Skip to content

Commit dd3c045

Browse files
committed
Testing via Github Actions
1 parent 4ca0734 commit dd3c045

File tree

7 files changed

+210
-13
lines changed

7 files changed

+210
-13
lines changed

.github/workflows/tests-reqs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cython==0.29.13

.github/workflows/tests.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: PR Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- ci
8+
pull_request:
9+
branches:
10+
- master
11+
12+
jobs:
13+
build:
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
max-parallel: 4
17+
matrix:
18+
python-version: [3.6, 3.7, 3.8]
19+
os: [windows-latest, ubuntu-18.04, macos-latest]
20+
21+
steps:
22+
- uses: actions/checkout@v1
23+
with:
24+
fetch-depth: 50
25+
submodules: true
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v1
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
- name: Install Deps
31+
run: |
32+
pip install -U setuptools
33+
pip install -r .github/workflows/tests-reqs.txt
34+
- name: Test
35+
# wdf needs to be killed or vcvarsall.bat will pick it up
36+
# thinking it's the latest version of the Windows 10 SDK.
37+
run: |
38+
python setup.py build_ext --inplace
39+
python setup.py test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.ymlc~
66
*.scssc
77
*.so
8+
*.pyd
89
*~
910
.#*
1011
.DS_Store

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
compile:
5-
cython httptools/parser/parser.pyx
65
python3 setup.py build_ext --inplace
76

87

@@ -11,10 +10,10 @@ release: compile test
1110

1211

1312
test:
14-
python3 -m unittest discover -s tests -v
13+
python3 setup.py test
1514

1615

1716
distclean:
1817
git --git-dir="./vendor/http-parser/.git" clean -dfx
19-
find ./httptools/parser -name '*.c' | xargs rm
20-
find ./httptools/parser -name '*.html' | xargs rm
18+
find ./httptools/parser -name '*.c' | xargs rm -f
19+
find ./httptools/parser -name '*.html' | xargs rm -f

httptools/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from .parser import *
1+
from .parser import parser
2+
from .parser import * # NOQA
23

34

4-
__all__ = parser.__all__
5+
__all__ = parser.__all__ # NOQA
6+
__version__ = '0.0.13'

setup.py

Lines changed: 145 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,142 @@
1+
import os.path
2+
import sys
3+
14
from setuptools import setup, Extension
5+
from setuptools.command.build_ext import build_ext as build_ext
6+
7+
8+
vi = sys.version_info
9+
if vi < (3, 5):
10+
raise RuntimeError('httptools require Python 3.5 or greater')
11+
12+
CFLAGS = ['-O2']
13+
ROOT = os.path.dirname(__file__)
14+
15+
16+
class httptools_build_ext(build_ext):
17+
user_options = build_ext.user_options + [
18+
('cython-always', None,
19+
'run cythonize() even if .c files are present'),
20+
('cython-annotate', None,
21+
'Produce a colorized HTML version of the Cython source.'),
22+
('cython-directives=', None,
23+
'Cythion compiler directives'),
24+
('use-system-http-parser', None,
25+
'Use the system provided http-parser, instead of the bundled one'),
26+
]
27+
28+
boolean_options = build_ext.boolean_options + [
29+
'cython-always',
30+
'cython-annotate',
31+
'use-system-http-parser',
32+
]
33+
34+
def initialize_options(self):
35+
# initialize_options() may be called multiple times on the
36+
# same command object, so make sure not to override previously
37+
# set options.
38+
if getattr(self, '_initialized', False):
39+
return
40+
41+
super().initialize_options()
42+
self.use_system_http_parser = False
43+
self.cython_always = False
44+
self.cython_annotate = None
45+
self.cython_directives = None
46+
47+
def finalize_options(self):
48+
# finalize_options() may be called multiple times on the
49+
# same command object, so make sure not to override previously
50+
# set options.
51+
if getattr(self, '_initialized', False):
52+
return
53+
54+
need_cythonize = self.cython_always
55+
cfiles = {}
56+
57+
for extension in self.distribution.ext_modules:
58+
for i, sfile in enumerate(extension.sources):
59+
if sfile.endswith('.pyx'):
60+
prefix, ext = os.path.splitext(sfile)
61+
cfile = prefix + '.c'
62+
63+
if os.path.exists(cfile) and not self.cython_always:
64+
extension.sources[i] = cfile
65+
else:
66+
if os.path.exists(cfile):
67+
cfiles[cfile] = os.path.getmtime(cfile)
68+
else:
69+
cfiles[cfile] = 0
70+
need_cythonize = True
71+
72+
if need_cythonize:
73+
try:
74+
import Cython
75+
except ImportError:
76+
raise RuntimeError(
77+
'please install Cython to compile httptools from source')
278

3-
with open('README.md') as f:
79+
if Cython.__version__ < '0.29':
80+
raise RuntimeError(
81+
'httptools requires Cython version 0.29 or greater')
82+
83+
from Cython.Build import cythonize
84+
85+
directives = {}
86+
if self.cython_directives:
87+
for directive in self.cython_directives.split(','):
88+
k, _, v = directive.partition('=')
89+
if v.lower() == 'false':
90+
v = False
91+
if v.lower() == 'true':
92+
v = True
93+
94+
directives[k] = v
95+
96+
self.distribution.ext_modules[:] = cythonize(
97+
self.distribution.ext_modules,
98+
compiler_directives=directives,
99+
annotate=self.cython_annotate)
100+
101+
super().finalize_options()
102+
103+
self._initialized = True
104+
105+
def build_extensions(self):
106+
if self.use_system_http_parser:
107+
self.compiler.add_library('http_parser')
108+
109+
if sys.platform == 'darwin' and \
110+
os.path.exists('/opt/local/include'):
111+
# Support macports on Mac OS X.
112+
self.compiler.add_include_dir('/opt/local/include')
113+
else:
114+
self.compiler.add_include_dir(
115+
os.path.join(ROOT, 'vendor/http-parser'))
116+
self.distribution.ext_modules[0].sources.append(
117+
'vendor/http-parser/http_parser.c')
118+
119+
super().build_extensions()
120+
121+
122+
with open(os.path.join(ROOT, 'README.md')) as f:
4123
long_description = f.read()
5124

125+
126+
with open(os.path.join(ROOT, 'httptools', '__init__.py')) as f:
127+
for line in f:
128+
if line.startswith('__version__ ='):
129+
_, _, version = line.partition('=')
130+
VERSION = version.strip(" \n'\"")
131+
break
132+
else:
133+
raise RuntimeError(
134+
'unable to read the version from httptools/__init__.py')
135+
136+
6137
setup(
7138
name='httptools',
8-
version='0.0.13',
139+
version=VERSION,
9140
description='A collection of framework independent HTTP protocol utils.',
10141
long_description=long_description,
11142
long_description_content_type='text/markdown',
@@ -24,12 +155,19 @@
24155
author_email='[email protected]',
25156
license='MIT',
26157
packages=['httptools', 'httptools.parser'],
158+
cmdclass={
159+
'build_ext': httptools_build_ext,
160+
},
27161
ext_modules=[
28-
Extension("httptools.parser.parser",
29-
["httptools/parser/parser.c",
30-
"vendor/http-parser/http_parser.c"],
31-
extra_compile_args=['-O2'])
162+
Extension(
163+
"httptools.parser.parser",
164+
sources=[
165+
"httptools/parser/parser.pyx",
166+
],
167+
extra_compile_args=CFLAGS,
168+
),
32169
],
33170
provides=['httptools'],
34-
include_package_data=True
171+
include_package_data=True,
172+
test_suite='tests.suite'
35173
)

tests/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os.path
2+
import sys
3+
import unittest
4+
import unittest.runner
5+
6+
7+
def suite():
8+
test_loader = unittest.TestLoader()
9+
test_suite = test_loader.discover(
10+
os.path.dirname(__file__), pattern='test_*.py')
11+
return test_suite
12+
13+
14+
if __name__ == '__main__':
15+
runner = unittest.runner.TextTestRunner()
16+
result = runner.run(suite())
17+
sys.exit(not result.wasSuccessful())

0 commit comments

Comments
 (0)