From b68b17d60f475f51b2940ddbb06b71578126dc31 Mon Sep 17 00:00:00 2001 From: learnforpractice Date: Mon, 26 Jun 2023 19:27:59 +0800 Subject: [PATCH] Remove scikit-build --- .github/workflows/python-app.yml | 3 +- .gitignore | 2 ++ requirements-dev.txt | 1 - setup.py | 56 ++++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 9f8bad8..2230ae9 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -56,7 +56,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install -U flake8 pytest scikit-build cython auditwheel + python -m pip install --upgrade wheel + python -m pip install -U flake8 pytest cython auditwheel # - name: Lint with flake8 # run: | # # stop the build if there are Python syntax errors or undefined names diff --git a/.gitignore b/.gitignore index 8c70d6a..77d7da7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# generated file by cython +src/_mixin.cpp .testnet *.wallet testnet diff --git a/requirements-dev.txt b/requirements-dev.txt index a9bfb20..0f84cf9 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,6 @@ websocket-client>=0.54.0 websockets dataclasses-json -scikit-build cython pytest pytest-asyncio diff --git a/setup.py b/setup.py index 5cd04d6..4d92cec 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,13 @@ import os import sys import platform -from setuptools import find_packages -from skbuild import setup - + +from setuptools import find_packages, setup, Extension +from Cython.Build import cythonize + +os.environ["CC"] = "clang" +os.environ["CXX"] = "clang++" + # Require pytest-runner only when running tests pytest_runner = (['pytest-runner>=2.0,<3dev'] if any(arg in sys.argv for arg in ('pytest', 'test')) @@ -22,6 +26,48 @@ version = platform.python_version_tuple() version = '%s.%s' % (version[0], version[1]) +dir_name = os.path.dirname(os.path.realpath(__file__)) + +root_path = os.path.join(dir_name, 'src/mixin') +def check_modification(): + lib_name = os.path.join(root_path, 'libmixin.a') + if not os.path.exists(lib_name): + return True + modify_time = os.path.getmtime(lib_name) + for root, dirs, files in os.walk(root_path): + for f in files: + if f[-3:] == '.go': + f = os.path.join(root, f) + file_time = os.path.getmtime(f) + if modify_time < file_time: + return True + return False + +r = check_modification() +if r: + print('mixin lib need to rebuild.') + os.system(f'touch {root_path}/main.go') + +if platform.system() == 'Windows': + os.system('cd ./src/mixin &&go build -o mixin.dll -buildmode=c-shared && copy mixin.dll ../../pysrc/mixin.dll && gendef mixin.dll && lib /def:mixin.def /machine:x64 /out:mixin.lib') +else: + os.system('cd ./src/mixin;go build -o libmixin.a -buildmode=c-archive') + +ext_modules = [ + Extension( + 'pymixin._mixin', + sources=[ + 'src/_mixin.pyx', + ], + include_dirs=[ + 'src/mixin', + ], + language='c++', + extra_compile_args=['-std=c++17'], + extra_link_args=['-L./src/mixin', '-lmixin'], + ) +] + setup( name="mixin-python", version="0.2.10", @@ -34,6 +80,10 @@ package_data={'pymixin': data}, data_files = data_files, scripts=[], + ext_modules=cythonize( + ext_modules, + compiler_directives={'language_level': 3, }, + ), install_requires=[ "PyJWT>=2.4.0", "websockets>=9.1",