From 57ec808456ed42f7335e806f04d4f9c24041a18b Mon Sep 17 00:00:00 2001 From: ChandanChainani Date: Thu, 20 Oct 2022 16:45:47 +0530 Subject: [PATCH] Migrate setup.py to pyproject.toml (#8) --- _custom_build.py | 20 ++++++++++++ pyproject.toml | 33 ++++++++++++++++++++ pytest.ini | 5 +++ setup.cfg | 3 ++ setup.py | 80 ------------------------------------------------ 5 files changed, 61 insertions(+), 80 deletions(-) create mode 100644 _custom_build.py create mode 100644 pyproject.toml create mode 100644 pytest.ini create mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/_custom_build.py b/_custom_build.py new file mode 100644 index 0000000..f6ac922 --- /dev/null +++ b/_custom_build.py @@ -0,0 +1,20 @@ +from setuptools import Extension +from setuptools.command.build_py import build_py as _build_py + +class build_py(_build_py): + def run(self): + self.run_command("build_ext") + return super().run() + + def initialize_options(self): + super().initialize_options() + if self.distribution.ext_modules == None: + self.distribution.ext_modules = [] + + self.distribution.ext_modules.append( + Extension( + "termial_random.random", + sources=["termial_random/random.c"], + extra_compile_args=["-std=c17", "-lm"], + ) + ) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8d3c123 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,33 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "termial-random" +description = "Extensions to standard Python's heapq for performance applications" +authors = [ + { name="Fridolin Pokorny", email="fridolin@redhat.com" }, +] +license = {text = "GPLv3+"} +readme = "README.rst" +dynamic = ["version"] + +[tool.setuptools.dynamic] +version = {attr = "termial_random.__version__"} + +[tool.setuptools] +py-modules = ["_custom_build"] +packages = ["termial_random"] + +[tool.setuptools.cmdclass] +build_py = "_custom_build.build_py" + +[tool.setuptools.exclude-package-data] +termial_random = ["*.c"] + +[tool.pytest.ini_options] +minversion = "6.0" +addopts = "-l -s -vvv" +testpaths = [ + "tests", +] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..6a525b6 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +minversion = 6.0 +addopts = -l -s -vvv +testpaths = + tests diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..125d6a0 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[metadata] +url = "https://github.com/thoth-station/termial-random" +download_url = "https://pypi.org/project/termial-random" diff --git a/setup.py b/setup.py deleted file mode 100644 index 105f103..0000000 --- a/setup.py +++ /dev/null @@ -1,80 +0,0 @@ -import os -import sys -from setuptools.command.test import test as TestCommand -from setuptools import Extension -from setuptools import setup - - -class Test(TestCommand): - """Introduce test command to run test suite using pytest.""" - - _IMPLICIT_PYTEST_ARGS = [ - "--verbose", - "-l", - "-s", - "-vv", - "tests/", - ] - - user_options = [("pytest-args=", "a", "Arguments to pass into py.test")] - - def initialize_options(self): - super().initialize_options() - self.pytest_args = None - - def finalize_options(self): - super().finalize_options() - self.test_args = [] - self.test_suite = True - - def run_tests(self): - import pytest - - passed_args = list(self._IMPLICIT_PYTEST_ARGS) - - if self.pytest_args: - self.pytest_args = [arg for arg in self.pytest_args.split() if arg] - passed_args.extend(self.pytest_args) - - sys.exit(pytest.main(passed_args)) - - -def get_version(): - with open(os.path.join("termial_random", "__init__.py")) as f: - content = f.readlines() - - for line in content: - if line.startswith("__version__ ="): - # dirty, remove trailing and leading chars - return line.split(" = ")[1][1:-2] - raise ValueError("No version identifier found") - - -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() - - -VERSION = get_version() -setup( - name="termial-random", - version=VERSION, - description="Extensions to standard Python's heapq for performance applications", - long_description=read("README.rst"), - author="Fridolin Pokorny", - author_email="fridolin@redhat.com", - url="https://github.com/thoth-station/termial-random", - download_url="https://pypi.org/project/termial-random", - license="GPLv3+", - packages=["termial_random"], - package_data={ - "termial_random": ["py.typed", "__init__.pyi"], - }, - ext_modules=[ - Extension( - "termial_random.random", - sources=["termial_random/random.c"], - extra_compile_args=["-std=c17", "-lm"], - ), - ], - cmdclass={"test": Test}, -)