From 5e46aca9a4745e06eb4a72f4902477dc30e860ec Mon Sep 17 00:00:00 2001 From: Claire's Monster Date: Wed, 20 Mar 2024 10:58:04 -0500 Subject: [PATCH] FEAT: from setup to pyproject (#161) * FEAT: from setup to pyproject * (ref) setuptools version should not be an issue * (ref) no longer need to extract version * (ref) package-data * (ref) python -m build for windows (temporary, since CMake builds native) * (fix) lint setuptools.__version__ * (fix) let's be fancy. python -m build FTW * (cos) clean comments * (cos) simpler command --- .github/scripts/build-windows-wheels.sh | 8 +-- pyproject.toml | 60 ++++++++++++++++++++++- setup.py | 65 +------------------------ 3 files changed, 64 insertions(+), 69 deletions(-) diff --git a/.github/scripts/build-windows-wheels.sh b/.github/scripts/build-windows-wheels.sh index 3cabf9234..32f9082a8 100755 --- a/.github/scripts/build-windows-wheels.sh +++ b/.github/scripts/build-windows-wheels.sh @@ -26,19 +26,19 @@ cp 64bit 32bit -R cd 64bit build_dll x86_64-w64-mingw32 -# Not sure why it ended-up being a -2.dll instead of -0.dll: Researching +# As the API changes, the -x.dll will change to -y.dll, so we use a wildcard mv .libs/libsecp256k1-?.dll ../clean/src/coincurve/libsecp256k1.dll cd ../clean -python setup.py bdist_wheel --plat-name=win_amd64 -vvv +python -m build --wheel -C="--build-option=--plat-name win_amd64" rm src/coincurve/libsecp256k1.dll rm -rf build/temp.* cd ../32bit build_dll i686-w64-mingw32 -# Not sure why it ended-up being a -2.dll instead of -0.dll: Researching +# As the API changes, the -x.dll will change to -y.dll, so we use a wildcard mv .libs/libsecp256k1-?.dll ../clean/src/coincurve/libsecp256k1.dll cd ../clean -python setup.py bdist_wheel --plat-name=win32 +python -m build --wheel -C="--build-option--plat-name win32" mv dist/* ../coincurve/dist cd ../coincurve diff --git a/pyproject.toml b/pyproject.toml index f343a3a8a..18fb92446 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,65 @@ [build-system] -requires = ["setuptools>=61", "cffi>=1.3.0", "requests"] +requires = ["setuptools>=61", "cffi>=1.3.0", "requests", "setuptools-scm", 'asn1crypto'] build-backend = "setuptools.build_meta" +[project] +name = "coincurve" +authors = [ + { name="Ofek Lev", email="oss@ofek.dev" }, +] +description = "Cross-platform Python CFFI bindings for libsecp256k1" +keywords = ["secp256k1", "crypto", "elliptic curves", "bitcoin", "ethereum", "cryptocurrency"] +requires-python = ">=3.8" +dependencies = [ + "asn1crypto", + "cffi>=1.3.0" +] +classifiers = [ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'License :: OSI Approved :: Apache Software License', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', + 'Topic :: Software Development :: Libraries', + 'Topic :: Security :: Cryptography', +] +dynamic = ['version', 'readme'] + +[project.optional-dependencies] +dev = [ + "coverage", + "pytest", + "pytest-benchmark" +] + +[project.urls] +Homepage = "https://github.com/ofek/coincurve" +Documentation = "https://ofek.dev/coincurve/" +Repository = "https://github.com/ofek/coincurve" +"Bug Tracker" = "https://github.com/ofek/coincurve/issues" + +# --- setuptools --- +[tool.setuptools] +packages = ['coincurve'] +package-dir = {'' = 'src'} +package-data = {'coincurve' = ['py.typed']} + +[tool.setuptools.dynamic] +version = {attr = "coincurve._version.__version__"} +readme = {content-type = "text/markdown", file = "README.md"} + +# --- hatch --- + [tool.pytest.ini_options] addopts = [ "--import-mode=importlib", diff --git a/setup.py b/setup.py index 05926ba0e..5bbe1338a 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from os.path import join from sys import path as PATH -from setuptools import Distribution as _Distribution, setup, __version__ as setuptools_version +from setuptools import Distribution as _Distribution, setup from setuptools.extension import Extension # Define the package root directory and add it to the system path @@ -29,20 +29,6 @@ LIB_TARBALL_URL = f'https://github.com/bitcoin-core/secp256k1/archive/{UPSTREAM_REF}.tar.gz' -globals_ = {} -with open(join(COINCURVE_ROOT_DIR, 'src', 'coincurve', '_version.py')) as fp: - exec(fp.read(), globals_) # noqa S102 - __version__ = globals_['__version__'] - -# We require setuptools >= 3.3 -if [int(i) for i in setuptools_version.split('.', 2)[:2]] < [3, 3]: - raise SystemExit( - f'Your setuptools version ({setuptools_version}) is too old to correctly install this package. Please upgrade ' - f'to a newer version (>= 3.3).' - ) - -package_data = {'coincurve': ['py.typed']} - def main(): from setup_tools.commands import BdistWheel, EggInfo, Sdist, Develop @@ -96,7 +82,6 @@ class Distribution(_Distribution): def is_pure(self): return False - package_data['coincurve'].append('libsecp256k1.dll') setup_kwargs = {} else: @@ -119,56 +104,8 @@ def has_c_libraries(self): ) setup( - name='coincurve', - version=__version__, - - description='Cross-platform Python CFFI bindings for libsecp256k1', - long_description=open('README.md', 'r').read(), - long_description_content_type='text/markdown', - author_email='Ofek Lev ', - license='MIT OR Apache-2.0', - - python_requires='>=3.8', - setup_requires=['cffi>=1.3.0'], - install_requires=['asn1crypto', 'cffi>=1.3.0'], - - packages=['coincurve'], - package_dir={'coincurve': 'src/coincurve'}, - distclass=Distribution, zip_safe=False, - - project_urls={ - 'Documentation': 'https://ofek.dev/coincurve/', - 'Issues': 'https://github.com/ofek/coincurve/issues', - 'Source': 'https://github.com/ofek/coincurve', - }, - keywords=[ - 'secp256k1', - 'crypto', - 'elliptic curves', - 'bitcoin', - 'ethereum', - 'cryptocurrency', - ], - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'License :: OSI Approved :: Apache Software License', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - 'Topic :: Software Development :: Libraries', - 'Topic :: Security :: Cryptography', - ], **setup_kwargs )