Skip to content

Commit

Permalink
Merge pull request #1 from GhazTools/newVersion
Browse files Browse the repository at this point in the history
Finally working
  • Loading branch information
GhazanfarShahbaz authored Jun 20, 2024
2 parents 5ceba63 + 1c86fe3 commit 6dc2d34
Show file tree
Hide file tree
Showing 278 changed files with 97 additions and 79 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
timeout-minutes: 480
strategy:
matrix:
# os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest]
# os: [ubuntu-latest, windows-latest, macos-latest]
include:
Expand Down Expand Up @@ -49,7 +50,8 @@ jobs:
# run: cmake -E make_directory ${{runner.workspace}}/build

# - name: Configure CMake
# shell: bash
# shell: bash /opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: lib/src/libtoken_granter.a(token_granter.cpp.o): relocation R_X86_64_32 against undefined symbol `__pthread_key_create' can not be used when making a shared object; recompile with -fPIC

# run: cmake $GITHUB_WORKSPACE -B ${{runner.workspace}}/build

# - name: Build
Expand Down Expand Up @@ -107,12 +109,12 @@ jobs:
run: |
ls
echo "TK GRANTER STARTS HERE"
ls token_granter_wrapper
ls src/token_granter_wrapper
echo "WHEELHOUSE STARTS HERE"
ls wheelhouse
- name: Test pacakge
run: pip install wheelhouse/*.whl && pytest tests/
# - name: Test pacakge
# run: pip install wheelhouse/*.whl && pytest tests/

- name: Publish to PyPI
run: python -m twine upload --repository-url https://pypi.ghaz.dev:440 wheelhouse/*.whl --verbose
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
49 changes: 31 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
cmake_minimum_required(VERSION 3.23)
project(TokenGranterWrapper)
# cmake_minimum_required(VERSION 3.23)
# project(TokenGranterWrapperBindings)

set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_CXX_STANDARD 17)

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

# # add_executable(token_granter src/token_granter.cpp)
# # target_include_directories(token_granter PRIVATE ${CURL_INCLUDE_DIRS})
# # target_link_libraries(token_granter ${CURL_LIBRARIES})

set(CURL_LIBRARY "-lcurl")
find_package(CURL REQUIRED)
# # SHARED LIBRARY COMPILATION HERE
# 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})

# add_executable(token_granter src/token_granter.cpp)
# target_include_directories(token_granter PRIVATE ${CURL_INCLUDE_DIRS})
# target_link_libraries(token_granter ${CURL_LIBRARIES})

# SHARED LIBRARY COMPILATION HERE
add_library(token_granter_shared SHARED 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(./lib/include/pybind11)
# pybind11_add_module(token_granter ./token_granter_wrapper/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})

cmake_minimum_required(VERSION 3.23)
project(TokenGranterWrapperBindings)
set(CMAKE_CXX_STANDARD 17)

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

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

# PYBINDING SHARED LIBRARY COMPILATION HERE
add_subdirectory(./include/pybind11)
pybind11_add_module(token_granter ./src/token_granter_bindings.cpp ./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})
pybind11_add_module(token_granter_bindings ${SOURCES})
target_link_libraries(token_granter_bindings PRIVATE token_granter)
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.
14 changes: 14 additions & 0 deletions lib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.23)
project(TokenGranterWrapper)

set(CMAKE_CXX_STANDARD 17)

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

add_library(token_granter STATIC token_granter.cpp)

target_link_libraries(token_granter ${CURL_LIBRARIES})
target_include_directories(token_granter PRIVATE ${CURL_INCLUDE_DIRS})
set_target_properties(token_granter PROPERTIES POSITION_INDEPENDENT_CODE ON)

File renamed without changes.
86 changes: 37 additions & 49 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,90 +10,78 @@
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",
packages=setuptools.find_packages("token_granter_wrapper"),
package_dir={"src": "token_granter_wrapper"},
version="0.2.0",
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/")],
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=[]
)
1 change: 1 addition & 0 deletions src/token_granter_wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .token_granter_bindings import *
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "../include/token_granter.hpp"
#include "../../lib/include/token_granter.hpp"

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

namespace py = pybind11;

PYBIND11_MODULE(token_granter, m)
PYBIND11_MODULE(token_granter_bindings, m)
{
py::class_<TokenGranter>(m, "TokenGranter")
.def(py::init<const std::string &>())
Expand Down
Binary file modified tests/__pycache__/test_package.cpython-311-pytest-8.2.2.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from token_granter_wrapper import token_granter
from token_granter_wrapper import token_granter_bindings


def test_token_granter():
tk = token_granter.TokenGranter("here")
tk = token_granter_bindings.TokenGranter("here")
assert "" == tk.grant_access_token("TEST", "TEST", False)
Empty file removed token_granter_wrapper/__init__.py
Empty file.

0 comments on commit 6dc2d34

Please sign in to comment.