diff --git a/.github/workflows/tests-and-linters.yml b/.github/workflows/tests-and-linters.yml index ce0345dd..184889a7 100644 --- a/.github/workflows/tests-and-linters.yml +++ b/.github/workflows/tests-and-linters.yml @@ -50,7 +50,6 @@ jobs: with: python-version: 3.12 - run: pip install tox 'cython>=3,<4' - - run: make cythonize - run: tox -vv env: TOXENV: coveralls diff --git a/Makefile b/Makefile index 8466381a..7bbfb06b 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,5 @@ VERSION := $(shell python setup.py --version) -CYTHON_SRC := $(shell find src/dependency_injector -name '*.pyx') - -CYTHON_DIRECTIVES = -Xlanguage_level=3 - -ifdef DEPENDENCY_INJECTOR_DEBUG_MODE - CYTHON_DIRECTIVES += -Xprofile=True - CYTHON_DIRECTIVES += -Xlinetrace=True -endif - clean: # Clean sources @@ -25,21 +16,17 @@ clean: find examples -name '*.py[co]' -delete find examples -name '__pycache__' -delete -cythonize: - # Compile Cython to C - cython -a $(CYTHON_DIRECTIVES) $(CYTHON_SRC) +build: clean + # Compile C extensions + python setup.py build_ext --inplace # Move all Cython html reports mkdir -p reports/cython/ find src -name '*.html' -exec mv {} reports/cython/ \; -build: clean cythonize - # Compile C extensions - python setup.py build_ext --inplace - docs-live: sphinx-autobuild docs docs/_build/html -install: uninstall clean cythonize +install: uninstall clean build pip install -ve . uninstall: @@ -61,9 +48,9 @@ check: mypy tests/typing -test-publish: cythonize +test-publish: build # Create distributions - python setup.py sdist + python -m build --sdist # Upload distributions to PyPI twine upload --repository testpypi dist/dependency-injector-$(VERSION)* diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..1f46515f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,79 @@ +[build-system] +requires = ["setuptools", "Cython"] +build-backend = "setuptools.build_meta" + +[project] +name = "dependency-injector" +authors = [ + {name = "Roman Mogylatov", email = "rmogilatov@gmail.com"}, +] +maintainers = [ + {name = "Roman Mogylatov", email = "rmogilatov@gmail.com"}, +] +description = "Dependency injection framework for Python" +readme = {file = "README.rst", content-type = "text/x-rst"} +license = {file = "LICENSE.rst", content-type = "text/x-rst"} +requires-python = ">=3.7" +keywords = [ + "Dependency injection", + "DI", + "Inversion of Control", + "IoC", + "Factory", + "Singleton", + "Design patterns", + "Flask", +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "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 :: 3.13", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Framework :: AsyncIO", + "Framework :: Bottle", + "Framework :: Django", + "Framework :: Flask", + "Framework :: Pylons", + "Framework :: Pyramid", + "Framework :: Pytest", + "Framework :: TurboGears", + "Topic :: Software Development", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", +] +dynamic = ["version"] +dependencies = ["six"] + +[project.optional-dependencies] +yaml = ["pyyaml"] +pydantic = ["pydantic"] +flask = ["flask"] +aiohttp = ["aiohttp"] + +[project.urls] +Homepage = "https://github.com/ets-labs/python-dependency-injector" +Documentation = "https://python-dependency-injector.ets-labs.org/" +Download = "https://pypi.python.org/pypi/dependency_injector" + +[tool.setuptools] +package-dir = {"" = "src"} + +[tool.setuptools.packages.find] +where = ["src"] + +[tool.setuptools.package-data] +dependency_injector = ["*.pxd", "*.pyi", "py.typed"] + +[tool.setuptools.dynamic] +version = {attr = "dependency_injector.__version__"} diff --git a/setup.py b/setup.py index 9047ff5c..429e672c 100644 --- a/setup.py +++ b/setup.py @@ -1,128 +1,42 @@ """`Dependency injector` setup script.""" import os -import re -import sys -from setuptools import setup, Extension +from Cython.Build import cythonize +from Cython.Compiler import Options +from setuptools import Extension, setup - -def _open(filename): - if sys.version_info[0] == 2: - return open(filename) - return open(filename, encoding="utf-8") - - -# Defining setup variables: -defined_macros = dict() -defined_macros["CYTHON_CLINE_IN_TRACEBACK"] = 0 - -# Getting description: -with _open("README.rst") as readme_file: - description = readme_file.read() - -# Getting requirements: -with _open("requirements.txt") as requirements_file: - requirements = requirements_file.readlines() - -# Getting version: -with _open("src/dependency_injector/__init__.py") as init_file: - version = re.search("__version__ = \"(.*?)\"", init_file.read()).group(1) +debug = os.environ.get("DEPENDENCY_INJECTOR_DEBUG_MODE") == "1" +defined_macros = [] +compiler_directives = { + "language_level": 3, + "profile": debug, + "linetrace": debug, +} +Options.annotate = debug # Adding debug options: -if os.environ.get("DEPENDENCY_INJECTOR_DEBUG_MODE") == "1": - defined_macros["CYTHON_TRACE"] = 1 - defined_macros["CYTHON_TRACE_NOGIL"] = 1 - defined_macros["CYTHON_CLINE_IN_TRACEBACK"] = 1 +if debug: + defined_macros.extend( + [ + ("CYTHON_TRACE", "1"), + ("CYTHON_TRACE_NOGIL", "1"), + ("CYTHON_CLINE_IN_TRACEBACK", "1"), + ] + ) -setup(name="dependency-injector", - version=version, - description="Dependency injection framework for Python", - long_description=description, - author="Roman Mogylatov", - author_email="rmogilatov@gmail.com", - maintainer="Roman Mogylatov", - maintainer_email="rmogilatov@gmail.com", - url="https://github.com/ets-labs/python-dependency-injector", - download_url="https://pypi.python.org/pypi/dependency_injector", - packages=[ - "dependency_injector", - "dependency_injector.ext", - ], - package_dir={ - "": "src", - }, - package_data={ - "dependency_injector": ["*.pxd", "*.pyi", "py.typed"], - }, - ext_modules=[ - Extension("dependency_injector.containers", - ["src/dependency_injector/containers.c"], - define_macros=list(defined_macros.items()), - extra_compile_args=["-O2"]), - Extension("dependency_injector.providers", - ["src/dependency_injector/providers.c"], - define_macros=list(defined_macros.items()), - extra_compile_args=["-O2"]), - Extension("dependency_injector._cwiring", - ["src/dependency_injector/_cwiring.c"], - define_macros=list(defined_macros.items()), - extra_compile_args=["-O2"]), - ], - install_requires=requirements, - extras_require={ - "yaml": [ - "pyyaml", - ], - "pydantic": [ - "pydantic", - ], - "flask": [ - "flask", - ], - "aiohttp": [ - "aiohttp", - ], - }, - zip_safe=True, - license="BSD New", - platforms=["any"], - keywords=[ - "Dependency injection", - "DI", - "Inversion of Control", - "IoC", - "Factory", - "Singleton", - "Design patterns", - "Flask", - ], - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: BSD License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "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 :: 3.13", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Framework :: AsyncIO", - "Framework :: Bottle", - "Framework :: Django", - "Framework :: Flask", - "Framework :: Pylons", - "Framework :: Pyramid", - "Framework :: Pytest", - "Framework :: TurboGears", - "Topic :: Software Development", - "Topic :: Software Development :: Libraries", - "Topic :: Software Development :: Libraries :: Python Modules", - ]) +setup( + ext_modules=cythonize( + [ + Extension( + "*", + ["src/**/*.pyx"], + define_macros=defined_macros, + ), + ], + annotate=debug, + show_all_warnings=True, + compiler_directives=compiler_directives, + ), +) diff --git a/tox.ini b/tox.ini index 65aa26f0..75a5020a 100644 --- a/tox.ini +++ b/tox.ini @@ -24,6 +24,9 @@ extras= commands = pytest -c tests/.configs/pytest.ini python_files = test_*_py3*.py +[testenv:.pkg] +passenv = DEPENDENCY_INJECTOR_* + [testenv:coveralls] passenv = GITHUB_*, COVERALLS_*, DEPENDENCY_INJECTOR_* basepython=python3.12 # TODO: Upgrade to version 3.13 is blocked by coveralls 4.0.1 not supporting Python 3.13