Skip to content

Commit 4f1f428

Browse files
committed
Convert to PEP-517 project
1 parent abf2a25 commit 4f1f428

File tree

5 files changed

+123
-141
lines changed

5 files changed

+123
-141
lines changed

.github/workflows/tests-and-linters.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ jobs:
5050
with:
5151
python-version: 3.12
5252
- run: pip install tox 'cython>=3,<4'
53-
- run: make cythonize
5453
- run: tox -vv
5554
env:
5655
TOXENV: coveralls

Makefile

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
VERSION := $(shell python setup.py --version)
22

3-
CYTHON_SRC := $(shell find src/dependency_injector -name '*.pyx')
4-
5-
CYTHON_DIRECTIVES = -Xlanguage_level=3
6-
7-
ifdef DEPENDENCY_INJECTOR_DEBUG_MODE
8-
CYTHON_DIRECTIVES += -Xprofile=True
9-
CYTHON_DIRECTIVES += -Xlinetrace=True
10-
endif
11-
123

134
clean:
145
# Clean sources
@@ -25,21 +16,17 @@ clean:
2516
find examples -name '*.py[co]' -delete
2617
find examples -name '__pycache__' -delete
2718

28-
cythonize:
29-
# Compile Cython to C
30-
cython -a $(CYTHON_DIRECTIVES) $(CYTHON_SRC)
19+
build: clean
20+
# Compile C extensions
21+
python setup.py build_ext --inplace
3122
# Move all Cython html reports
3223
mkdir -p reports/cython/
3324
find src -name '*.html' -exec mv {} reports/cython/ \;
3425

35-
build: clean cythonize
36-
# Compile C extensions
37-
python setup.py build_ext --inplace
38-
3926
docs-live:
4027
sphinx-autobuild docs docs/_build/html
4128

42-
install: uninstall clean cythonize
29+
install: uninstall clean build
4330
pip install -ve .
4431

4532
uninstall:
@@ -61,9 +48,9 @@ check:
6148

6249
mypy tests/typing
6350

64-
test-publish: cythonize
51+
test-publish: build
6552
# Create distributions
66-
python setup.py sdist
53+
python -m build --sdist
6754
# Upload distributions to PyPI
6855
twine upload --repository testpypi dist/dependency-injector-$(VERSION)*
6956

pyproject.toml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
[build-system]
2+
requires = ["setuptools", "Cython"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "dependency-injector"
7+
authors = [
8+
{name = "Roman Mogylatov", email = "rmogilatov@gmail.com"},
9+
]
10+
maintainers = [
11+
{name = "Roman Mogylatov", email = "rmogilatov@gmail.com"},
12+
]
13+
description = "Dependency injection framework for Python"
14+
readme = {file = "README.rst", content-type = "text/x-rst"}
15+
license = {file = "LICENSE.rst", content-type = "text/x-rst"}
16+
requires-python = ">=3.7"
17+
keywords = [
18+
"Dependency injection",
19+
"DI",
20+
"Inversion of Control",
21+
"IoC",
22+
"Factory",
23+
"Singleton",
24+
"Design patterns",
25+
"Flask",
26+
]
27+
classifiers = [
28+
"Development Status :: 5 - Production/Stable",
29+
"Intended Audience :: Developers",
30+
"License :: OSI Approved :: BSD License",
31+
"Operating System :: OS Independent",
32+
"Programming Language :: Python",
33+
"Programming Language :: Python :: 3",
34+
"Programming Language :: Python :: 3.7",
35+
"Programming Language :: Python :: 3.8",
36+
"Programming Language :: Python :: 3.9",
37+
"Programming Language :: Python :: 3.10",
38+
"Programming Language :: Python :: 3.11",
39+
"Programming Language :: Python :: 3.12",
40+
"Programming Language :: Python :: 3.13",
41+
"Programming Language :: Python :: Implementation :: CPython",
42+
"Programming Language :: Python :: Implementation :: PyPy",
43+
"Framework :: AsyncIO",
44+
"Framework :: Bottle",
45+
"Framework :: Django",
46+
"Framework :: Flask",
47+
"Framework :: Pylons",
48+
"Framework :: Pyramid",
49+
"Framework :: Pytest",
50+
"Framework :: TurboGears",
51+
"Topic :: Software Development",
52+
"Topic :: Software Development :: Libraries",
53+
"Topic :: Software Development :: Libraries :: Python Modules",
54+
]
55+
dynamic = ["version"]
56+
dependencies = ["six"]
57+
58+
[project.optional-dependencies]
59+
yaml = ["pyyaml"]
60+
pydantic = ["pydantic"]
61+
flask = ["flask"]
62+
aiohttp = ["aiohttp"]
63+
64+
[project.urls]
65+
Homepage = "https://github.com/ets-labs/python-dependency-injector"
66+
Documentation = "https://python-dependency-injector.ets-labs.org/"
67+
Download = "https://pypi.python.org/pypi/dependency_injector"
68+
69+
[tool.setuptools]
70+
package-dir = {"" = "src"}
71+
72+
[tool.setuptools.packages.find]
73+
where = ["src"]
74+
75+
[tool.setuptools.package-data]
76+
dependency_injector = ["*.pxd", "*.pyi", "py.typed"]
77+
78+
[tool.setuptools.dynamic]
79+
version = {attr = "dependency_injector.__version__"}

setup.py

Lines changed: 35 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,42 @@
11
"""`Dependency injector` setup script."""
22

33
import os
4-
import re
5-
import sys
64

7-
from setuptools import setup, Extension
5+
from Cython.Build import cythonize
6+
from Cython.Compiler import Options
7+
from setuptools import Extension, setup
88

9-
10-
def _open(filename):
11-
if sys.version_info[0] == 2:
12-
return open(filename)
13-
return open(filename, encoding="utf-8")
14-
15-
16-
# Defining setup variables:
17-
defined_macros = dict()
18-
defined_macros["CYTHON_CLINE_IN_TRACEBACK"] = 0
19-
20-
# Getting description:
21-
with _open("README.rst") as readme_file:
22-
description = readme_file.read()
23-
24-
# Getting requirements:
25-
with _open("requirements.txt") as requirements_file:
26-
requirements = requirements_file.readlines()
27-
28-
# Getting version:
29-
with _open("src/dependency_injector/__init__.py") as init_file:
30-
version = re.search("__version__ = \"(.*?)\"", init_file.read()).group(1)
9+
debug = os.environ.get("DEPENDENCY_INJECTOR_DEBUG_MODE") == "1"
10+
defined_macros = []
11+
compiler_directives = {
12+
"language_level": 3,
13+
"profile": debug,
14+
"linetrace": debug,
15+
}
16+
Options.annotate = debug
3117

3218
# Adding debug options:
33-
if os.environ.get("DEPENDENCY_INJECTOR_DEBUG_MODE") == "1":
34-
defined_macros["CYTHON_TRACE"] = 1
35-
defined_macros["CYTHON_TRACE_NOGIL"] = 1
36-
defined_macros["CYTHON_CLINE_IN_TRACEBACK"] = 1
37-
38-
39-
setup(name="dependency-injector",
40-
version=version,
41-
description="Dependency injection framework for Python",
42-
long_description=description,
43-
author="Roman Mogylatov",
44-
author_email="rmogilatov@gmail.com",
45-
maintainer="Roman Mogylatov",
46-
maintainer_email="rmogilatov@gmail.com",
47-
url="https://github.com/ets-labs/python-dependency-injector",
48-
download_url="https://pypi.python.org/pypi/dependency_injector",
49-
packages=[
50-
"dependency_injector",
51-
"dependency_injector.ext",
52-
],
53-
package_dir={
54-
"": "src",
55-
},
56-
package_data={
57-
"dependency_injector": ["*.pxd", "*.pyi", "py.typed"],
58-
},
59-
ext_modules=[
60-
Extension("dependency_injector.containers",
61-
["src/dependency_injector/containers.c"],
62-
define_macros=list(defined_macros.items()),
63-
extra_compile_args=["-O2"]),
64-
Extension("dependency_injector.providers",
65-
["src/dependency_injector/providers.c"],
66-
define_macros=list(defined_macros.items()),
67-
extra_compile_args=["-O2"]),
68-
Extension("dependency_injector._cwiring",
69-
["src/dependency_injector/_cwiring.c"],
70-
define_macros=list(defined_macros.items()),
71-
extra_compile_args=["-O2"]),
72-
],
73-
install_requires=requirements,
74-
extras_require={
75-
"yaml": [
76-
"pyyaml",
77-
],
78-
"pydantic": [
79-
"pydantic",
80-
],
81-
"flask": [
82-
"flask",
83-
],
84-
"aiohttp": [
85-
"aiohttp",
86-
],
87-
},
88-
zip_safe=True,
89-
license="BSD New",
90-
platforms=["any"],
91-
keywords=[
92-
"Dependency injection",
93-
"DI",
94-
"Inversion of Control",
95-
"IoC",
96-
"Factory",
97-
"Singleton",
98-
"Design patterns",
99-
"Flask",
100-
],
101-
classifiers=[
102-
"Development Status :: 5 - Production/Stable",
103-
"Intended Audience :: Developers",
104-
"License :: OSI Approved :: BSD License",
105-
"Operating System :: OS Independent",
106-
"Programming Language :: Python",
107-
"Programming Language :: Python :: 3",
108-
"Programming Language :: Python :: 3.7",
109-
"Programming Language :: Python :: 3.8",
110-
"Programming Language :: Python :: 3.9",
111-
"Programming Language :: Python :: 3.10",
112-
"Programming Language :: Python :: 3.11",
113-
"Programming Language :: Python :: 3.12",
114-
"Programming Language :: Python :: 3.13",
115-
"Programming Language :: Python :: Implementation :: CPython",
116-
"Programming Language :: Python :: Implementation :: PyPy",
117-
"Framework :: AsyncIO",
118-
"Framework :: Bottle",
119-
"Framework :: Django",
120-
"Framework :: Flask",
121-
"Framework :: Pylons",
122-
"Framework :: Pyramid",
123-
"Framework :: Pytest",
124-
"Framework :: TurboGears",
125-
"Topic :: Software Development",
126-
"Topic :: Software Development :: Libraries",
127-
"Topic :: Software Development :: Libraries :: Python Modules",
128-
])
19+
if debug:
20+
defined_macros.extend(
21+
[
22+
("CYTHON_TRACE", "1"),
23+
("CYTHON_TRACE_NOGIL", "1"),
24+
("CYTHON_CLINE_IN_TRACEBACK", "1"),
25+
]
26+
)
27+
28+
29+
setup(
30+
ext_modules=cythonize(
31+
[
32+
Extension(
33+
"*",
34+
["src/**/*.pyx"],
35+
define_macros=defined_macros,
36+
),
37+
],
38+
annotate=debug,
39+
show_all_warnings=True,
40+
compiler_directives=compiler_directives,
41+
),
42+
)

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ extras=
2424
commands = pytest -c tests/.configs/pytest.ini
2525
python_files = test_*_py3*.py
2626

27+
[testenv:.pkg]
28+
passenv = DEPENDENCY_INJECTOR_*
29+
2730
[testenv:coveralls]
2831
passenv = GITHUB_*, COVERALLS_*, DEPENDENCY_INJECTOR_*
2932
basepython=python3.12 # TODO: Upgrade to version 3.13 is blocked by coveralls 4.0.1 not supporting Python 3.13

0 commit comments

Comments
 (0)