Skip to content

Commit

Permalink
setup
Browse files Browse the repository at this point in the history
  • Loading branch information
GhazanfarShahbaz committed Jun 20, 2024
1 parent 5ceba63 commit 3ac57ce
Show file tree
Hide file tree
Showing 273 changed files with 47 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CMake Build

on:
push:
branches: [main]
branches: [newVersion]
pull_request:
branches: [main]
branches: [newVersion]

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include/**`",
"${workspaceFolder}/src/**`"
"${workspaceFolder}/lib/include/**`",
"${workspaceFolder}/lib/src/**`"
],
"defines": [],
"macFrameworkPath": [
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ find_package(CURL REQUIRED)
# target_link_libraries(token_granter ${CURL_LIBRARIES})

# SHARED LIBRARY COMPILATION HERE
add_library(token_granter_shared SHARED src/token_granter.cpp)
add_library(token_granter_shared SHARED lib/src/token_granter.cpp)
target_link_libraries(token_granter_shared ${CURL_LIBRARIES})
target_link_libraries(token_granter_shared ${CURL_LIBRARIES})


# PYBINDING SHARED LIBRARY COMPILATION HERE
add_subdirectory(./include/pybind11)
pybind11_add_module(token_granter ./src/token_granter_bindings.cpp ./src/token_granter.cpp)
add_subdirectory(./lib/include/pybind11)
pybind11_add_module(token_granter ./lib/src/token_granter_bindings.cpp ./lib/src/token_granter.cpp)
set_target_properties(token_granter PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/token_granter_wrapper)
target_link_libraries(token_granter PRIVATE pybind11::module)
target_link_libraries(token_granter PRIVATE ${CURL_LIBRARIES})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
83 changes: 37 additions & 46 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,90 +10,81 @@
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)


with open("README.md", "r") as f:
long_description = f.read()

setup(
name="token-granter-wrapper",
version="0.1.0",
description="A test",
long_description="A test",
description="Some testing stuff",
packages=setuptools.find_packages("token_granter_wrapper"),
package_dir={"src": "token_granter_wrapper"},
package_dir={"": "src"},
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: POSIX :: Linux",
"Operating System :: POSIX :: Linux"
],
ext_modules=[CMakeExtension("token_granter_wrapper/")],
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=[]
)

# https://python.plainenglish.io/building-hybrid-python-c-packages-8985fa1c5b1d
1 change: 1 addition & 0 deletions token_granter_wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .token_granter_bindings import *
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "../include/token_granter.hpp"

// EXTERNAL IMPORTS START HERE
#include "../include/pybind11/include/pybind11/pybind11.h"
#include "../include/pybind11/include/pybind11/stl.h"
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
// EXTERNAL IMPORTS END HERE

namespace py = pybind11;
Expand Down

0 comments on commit 3ac57ce

Please sign in to comment.