|
1 | 1 | """`Dependency injector` setup script.""" |
2 | 2 |
|
3 | 3 | import os |
4 | | -import re |
5 | | -import sys |
6 | 4 |
|
7 | | -from setuptools import setup, Extension |
8 | | - |
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) |
31 | | - |
32 | | -# 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 | | - |
45 | | - maintainer="Roman Mogylatov", |
46 | | - maintainer_email="[email protected]", |
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 | | - ]) |
| 5 | +from setuptools import setup |
| 6 | +from Cython.Build import cythonize |
| 7 | +from Cython.Build.Dependencies import default_create_extension |
| 8 | +from Cython.Compiler import Options |
| 9 | + |
| 10 | +debug = os.environ.get("DEPENDENCY_INJECTOR_DEBUG_MODE") == "1" |
| 11 | +defined_macros = [] |
| 12 | +compiler_directives = { |
| 13 | + "language_level": 3, |
| 14 | + "profile": debug, |
| 15 | + "linetrace": debug, |
| 16 | +} |
| 17 | +Options.annotate = debug |
| 18 | + |
| 19 | + |
| 20 | +def create_extension(template, kwds): |
| 21 | + if debug: |
| 22 | + kwds["define_macros"] = [ |
| 23 | + *kwds.get("define_macros", []), |
| 24 | + ("CYTHON_TRACE", "1"), |
| 25 | + ("CYTHON_TRACE_NOGIL", "1"), |
| 26 | + ("CYTHON_CLINE_IN_TRACEBACK", "1"), |
| 27 | + ] |
| 28 | + return default_create_extension(template, kwds) |
| 29 | + |
| 30 | + |
| 31 | +setup( |
| 32 | + ext_modules=cythonize( |
| 33 | + "src/**/*.pyx", |
| 34 | + annotate=debug, |
| 35 | + show_all_warnings=True, |
| 36 | + compiler_directives=compiler_directives, |
| 37 | + create_extension=create_extension, |
| 38 | + ), |
| 39 | +) |
0 commit comments