Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
GhazanfarShahbaz committed Jun 22, 2024
1 parent 36ee168 commit a45a16f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 265 deletions.
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ cmake_minimum_required(VERSION 3.23)
project(TokenGranterWrapperBindings)
set(CMAKE_CXX_STANDARD 17)

set(CURL_LIBRARY "-lcurl")
find_package(CURL REQUIRED)

add_subdirectory(./lib/include/pybind11)
add_subdirectory(./lib/src)

set(SOURCE_DIR "src/token_granter_wrapper")
set(SOURCES "${SOURCE_DIR}/token_granter_bindings.cpp")

pybind11_add_module(token_granter_bindings ${SOURCES})
target_link_libraries(token_granter_bindings PRIVATE token_granter ${CURL_LIBRARIES})
target_include_directories(token_granter_bindings PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(token_granter_bindings PRIVATE token_granter
225 changes: 0 additions & 225 deletions Makefile

This file was deleted.

77 changes: 42 additions & 35 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,85 @@
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext

'''
"""
Modified from https://www.benjack.io/2017/06/12/python-cpp-tests.html
'''
"""


class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)


class CMakeBuild(build_ext):
def run(self):
try:
out = subprocess.check_output(['cmake', '--version'])
out = subprocess.check_output(["cmake", "--version"])
except OSError:
raise RuntimeError(
"CMake must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))
"CMake must be installed to build the following extensions: "
+ ", ".join(e.name for e in self.extensions)
)

if platform.system() == "Windows":
cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)',
out.decode()).group(1))
if cmake_version < '3.1.0':
cmake_version = LooseVersion(
re.search(r"version\s*([\d.]+)", out.decode()).group(1)
)
if cmake_version < "3.1.0":
raise RuntimeError("CMake >= 3.1.0 is required on Windows")

for ext in self.extensions:
self.build_extension(ext)

def build_extension(self, ext):
extdir = os.path.abspath(
os.path.dirname(self.get_ext_fullpath(ext.name)))
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))

cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable]
cmake_args = [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
"-DPYTHON_EXECUTABLE=" + sys.executable,
]

cfg = 'Debug' if self.debug else 'Release'
build_args = ['--config', cfg]
cfg = "Debug" if self.debug else "Release"
build_args = ["--config", cfg]

if platform.system() == "Windows":
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(
cfg.upper(),
extdir)]
cmake_args += [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)
]
if sys.maxsize > 2**32:
cmake_args += ['-A', 'x64']
build_args += ['--', '/m']
cmake_args += ["-A", "x64"]
build_args += ["--", "/m"]
else:
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
build_args += ['--', '-j2']
cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg]
build_args += ["--", "-j2"]

env = os.environ.copy()
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(
env.get('CXXFLAGS', ''),
self.distribution.get_version())
env["CXXFLAGS"] = '{} -DVERSION_INFO=\\"{}\\"'.format(
env.get("CXXFLAGS", ""), self.distribution.get_version()
)
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args,
cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.'] + build_args,
cwd=self.build_temp)
subprocess.check_call(
["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env
)
subprocess.check_call(
["cmake", "--build", "."] + build_args, cwd=self.build_temp
)


setup(
name="token-granter-wrapper",
version="0.2.0",
version="0.2.1",
packages=setuptools.find_packages("src"),
package_dir={"": "src"},
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: POSIX :: Linux"
"Operating System :: POSIX :: Linux",
],
ext_modules=[CMakeExtension('token_granter_wrapper/token_granter_bindings')],
python_requires='>=3.6',
ext_modules=[CMakeExtension("token_granter_wrapper/token_granter_bindings")],
python_requires=">=3.6",
cmdclass=dict(build_ext=CMakeBuild),
zip_safe=False,
install_requires=[]
)
install_requires=[],
)

0 comments on commit a45a16f

Please sign in to comment.