Skip to content

Commit 6045853

Browse files
committed
add cython as a build dependency
1 parent 5a852cd commit 6045853

File tree

3 files changed

+9
-64
lines changed

3 files changed

+9
-64
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ jobs:
4747
run: |
4848
python -m pip install -U pip setuptools wheel
4949
python -m pip install .[test]
50-
python -m unittest -v tests.suite
50+
cd tests
51+
python -m unittest -v

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
22
build-backend = "setuptools.build_meta"
3-
requires = ["setuptools"]
3+
requires = ["setuptools", "cython"]
44

55
[project]
66
name = "httptools"
7-
dynamic = ["version"]
7+
dynamic = ["version", "optional-dependencies"]
88
classifiers = [
99
"Intended Audience :: Developers",
1010
"Programming Language :: Python :: 3",

setup.py

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sys
22

3+
from Cython.Build import cythonize
4+
35
vi = sys.version_info
46
if vi < (3, 8):
57
raise RuntimeError('httptools require Python 3.8 or greater')
@@ -15,26 +17,18 @@
1517

1618
ROOT = pathlib.Path(__file__).parent
1719

18-
CYTHON_DEPENDENCY = 'Cython>=0.29.24'
20+
CYTHON_DEPENDENCY = 'Cython>=3.1.0'
1921

2022

2123
class httptools_build_ext(build_ext):
2224
user_options = build_ext.user_options + [
23-
('cython-always', None,
24-
'run cythonize() even if .c files are present'),
25-
('cython-annotate', None,
26-
'Produce a colorized HTML version of the Cython source.'),
27-
('cython-directives=', None,
28-
'Cythion compiler directives'),
2925
('use-system-llhttp', None,
3026
'Use the system provided llhttp, instead of the bundled one'),
3127
('use-system-http-parser', None,
3228
'Use the system provided http-parser, instead of the bundled one'),
3329
]
3430

3531
boolean_options = build_ext.boolean_options + [
36-
'cython-always',
37-
'cython-annotate',
3832
'use-system-llhttp',
3933
'use-system-http-parser',
4034
]
@@ -49,9 +43,6 @@ def initialize_options(self):
4943
super().initialize_options()
5044
self.use_system_llhttp = False
5145
self.use_system_http_parser = False
52-
self.cython_always = False
53-
self.cython_annotate = None
54-
self.cython_directives = None
5546

5647
def finalize_options(self):
5748
# finalize_options() may be called multiple times on the
@@ -60,53 +51,6 @@ def finalize_options(self):
6051
if getattr(self, '_initialized', False):
6152
return
6253

63-
need_cythonize = self.cython_always
64-
cfiles = {}
65-
66-
for extension in self.distribution.ext_modules:
67-
for i, sfile in enumerate(extension.sources):
68-
if sfile.endswith('.pyx'):
69-
prefix, ext = os.path.splitext(sfile)
70-
cfile = prefix + '.c'
71-
72-
if os.path.exists(cfile) and not self.cython_always:
73-
extension.sources[i] = cfile
74-
else:
75-
if os.path.exists(cfile):
76-
cfiles[cfile] = os.path.getmtime(cfile)
77-
else:
78-
cfiles[cfile] = 0
79-
need_cythonize = True
80-
81-
if need_cythonize:
82-
try:
83-
import Cython
84-
except ImportError:
85-
raise RuntimeError(
86-
'please install Cython to compile httptools from source')
87-
88-
if Cython.__version__ < '0.29':
89-
raise RuntimeError(
90-
'httptools requires Cython version 0.29 or greater')
91-
92-
from Cython.Build import cythonize
93-
94-
directives = {}
95-
if self.cython_directives:
96-
for directive in self.cython_directives.split(','):
97-
k, _, v = directive.partition('=')
98-
if v.lower() == 'false':
99-
v = False
100-
if v.lower() == 'true':
101-
v = True
102-
103-
directives[k] = v
104-
105-
self.distribution.ext_modules[:] = cythonize(
106-
self.distribution.ext_modules,
107-
compiler_directives=directives,
108-
annotate=self.cython_annotate)
109-
11054
super().finalize_options()
11155

11256
self._initialized = True
@@ -172,7 +116,7 @@ def build_extensions(self):
172116
cmdclass={
173117
'build_ext': httptools_build_ext,
174118
},
175-
ext_modules=[
119+
ext_modules=cythonize([
176120
Extension(
177121
"httptools.parser.parser",
178122
sources=[
@@ -187,7 +131,7 @@ def build_extensions(self):
187131
],
188132
extra_compile_args=CFLAGS,
189133
),
190-
],
134+
]),
191135
include_package_data=True,
192136
exclude_package_data={"": ["*.c", "*.h"]},
193137
test_suite='tests.suite',

0 commit comments

Comments
 (0)