|
15 | 15 | import pathlib |
16 | 16 | import platform |
17 | 17 | import re |
| 18 | +import subprocess |
18 | 19 |
|
19 | 20 | # We use vanilla build_ext, to avoid importing Cython via |
20 | 21 | # the setuptools version. |
|
28 | 29 |
|
29 | 30 | CYTHON_DEPENDENCY = 'Cython==0.28.3' |
30 | 31 |
|
| 32 | +# Minimal dependencies required to test asyncpg. |
| 33 | +TEST_DEPENDENCIES = [ |
| 34 | + 'flake8~=3.5.0', |
| 35 | + 'uvloop>=0.8.0;platform_system!="Windows"', |
| 36 | +] |
| 37 | + |
| 38 | +# Dependencies required to build documentation. |
| 39 | +DOC_DEPENDENCIES = [ |
| 40 | + 'Sphinx~=1.7.3', |
| 41 | + 'sphinxcontrib-asyncio~=0.2.0', |
| 42 | + 'sphinx_rtd_theme~=0.2.4', |
| 43 | +] |
| 44 | + |
31 | 45 | EXTRA_DEPENDENCIES = { |
| 46 | + 'docs': DOC_DEPENDENCIES, |
| 47 | + 'test': TEST_DEPENDENCIES, |
32 | 48 | # Dependencies required to develop asyncpg. |
33 | 49 | 'dev': [ |
34 | 50 | CYTHON_DEPENDENCY, |
35 | | - 'flake8~=3.5.0', |
36 | | - 'pytest~=3.0.7', |
37 | | - 'uvloop>=0.8.0;platform_system!="Windows"', |
38 | | - # Docs |
39 | | - 'Sphinx~=1.7.3', |
40 | | - 'sphinxcontrib-asyncio~=0.2.0', |
41 | | - 'sphinx_rtd_theme~=0.2.4', |
42 | | - ] |
| 51 | + 'pytest>=3.6.0', |
| 52 | + ] + DOC_DEPENDENCIES + TEST_DEPENDENCIES |
43 | 53 | } |
44 | 54 |
|
45 | 55 |
|
|
50 | 60 | CFLAGS.extend(['-fsigned-char', '-Wall', '-Wsign-compare', '-Wconversion']) |
51 | 61 |
|
52 | 62 |
|
| 63 | +_ROOT = pathlib.Path(__file__).parent |
| 64 | + |
| 65 | + |
| 66 | +with open(str(_ROOT / 'README.rst')) as f: |
| 67 | + readme = f.read() |
| 68 | + |
| 69 | + |
| 70 | +with open(str(_ROOT / 'asyncpg' / '__init__.py')) as f: |
| 71 | + for line in f: |
| 72 | + if line.startswith('__version__ ='): |
| 73 | + _, _, version = line.partition('=') |
| 74 | + VERSION = version.strip(" \n'\"") |
| 75 | + break |
| 76 | + else: |
| 77 | + raise RuntimeError( |
| 78 | + 'unable to read the version from asyncpg/__init__.py') |
| 79 | + |
| 80 | + |
| 81 | +if (_ROOT / '.git').is_dir() and 'dev' in VERSION: |
| 82 | + # This is a git checkout, use git to |
| 83 | + # generate a precise version. |
| 84 | + def git_commitish(): |
| 85 | + env = {} |
| 86 | + v = os.environ.get('PATH') |
| 87 | + if v is not None: |
| 88 | + env['PATH'] = v |
| 89 | + |
| 90 | + git = subprocess.run(['git', 'rev-parse', 'HEAD'], env=env, cwd=_ROOT, |
| 91 | + stdout=subprocess.PIPE) |
| 92 | + if git.returncode == 0: |
| 93 | + commitish = git.stdout.strip().decode('ascii') |
| 94 | + else: |
| 95 | + commitish = 'unknown' |
| 96 | + |
| 97 | + return commitish |
| 98 | + |
| 99 | + VERSION += '+' + git_commitish()[:7] |
| 100 | + |
| 101 | + |
53 | 102 | class VersionMixin: |
54 | 103 |
|
55 | 104 | def _fix_version(self, filename): |
@@ -183,55 +232,10 @@ def finalize_options(self): |
183 | 232 | super(build_ext, self).finalize_options() |
184 | 233 |
|
185 | 234 |
|
186 | | -_ROOT = pathlib.Path(__file__).parent |
187 | | - |
188 | | - |
189 | | -with open(str(_ROOT / 'README.rst')) as f: |
190 | | - readme = f.read() |
191 | | - |
192 | | - |
193 | | -with open(str(_ROOT / 'asyncpg' / '__init__.py')) as f: |
194 | | - for line in f: |
195 | | - if line.startswith('__version__ ='): |
196 | | - _, _, version = line.partition('=') |
197 | | - VERSION = version.strip(" \n'\"") |
198 | | - break |
199 | | - else: |
200 | | - raise RuntimeError( |
201 | | - 'unable to read the version from asyncpg/__init__.py') |
202 | | - |
203 | | - |
204 | | -extra_setup_kwargs = {} |
205 | 235 | setup_requires = [] |
206 | 236 |
|
207 | | -if (_ROOT / '.git').is_dir(): |
208 | | - # This is a git checkout, use setuptools_scm to |
209 | | - # generage a precise version. |
210 | | - def version_scheme(v): |
211 | | - from setuptools_scm import version |
212 | | - |
213 | | - if v.exact: |
214 | | - fv = v.format_with("{tag}") |
215 | | - if fv != VERSION: |
216 | | - raise RuntimeError( |
217 | | - 'asyncpg.__version__ does not match the git tag') |
218 | | - else: |
219 | | - fv = v.format_next_version( |
220 | | - version.guess_next_simple_semver, |
221 | | - retain=version.SEMVER_MINOR) |
222 | | - |
223 | | - if not fv.startswith(VERSION[:-1]): |
224 | | - raise RuntimeError( |
225 | | - 'asyncpg.__version__ does not match the git tag') |
226 | | - |
227 | | - return fv |
228 | | - |
229 | | - setup_requires.append('setuptools_scm') |
230 | | - extra_setup_kwargs['use_scm_version'] = { |
231 | | - 'version_scheme': version_scheme |
232 | | - } |
233 | | - |
234 | | -if not (_ROOT / 'asyncpg' / 'protocol' / 'protocol.c').exists(): |
| 237 | +if (not (_ROOT / 'asyncpg' / 'protocol' / 'protocol.c').exists() or |
| 238 | + '--cython-always' in sys.argv): |
235 | 239 | # No Cython output, require Cython to build. |
236 | 240 | setup_requires.append(CYTHON_DEPENDENCY) |
237 | 241 |
|
@@ -273,5 +277,4 @@ def version_scheme(v): |
273 | 277 | test_suite='tests.suite', |
274 | 278 | extras_require=EXTRA_DEPENDENCIES, |
275 | 279 | setup_requires=setup_requires, |
276 | | - **extra_setup_kwargs |
277 | 280 | ) |
0 commit comments