|
1 | 1 | #!/usr/bin/env python
|
2 | 2 | # -*- coding: utf-8 -*-
|
3 | 3 |
|
| 4 | +import setuptools |
| 5 | +import sys |
| 6 | + |
4 | 7 | from codecs import open
|
| 8 | +from distutils.version import LooseVersion |
5 | 9 | from os import path
|
6 | 10 | from setuptools import setup, find_packages
|
7 |
| -import sys |
8 | 11 |
|
9 | 12 | local_path = path.abspath(path.dirname(__file__))
|
10 | 13 |
|
| 14 | +# find_packages()'s 'include' parameter has been introduced in setuptools 3.3. |
| 15 | +# |
| 16 | +# Ubuntu 14:04 comes with 3.3 for the system wide installation, |
| 17 | +# but when using virtualenv the setuptools version is 2.2. |
| 18 | +# The solution is to upgrade setuptools in the virtualenv. |
| 19 | +if LooseVersion(setuptools.__version__) < LooseVersion('3.3'): |
| 20 | + print("setuptools version:", str(LooseVersion(setuptools.__version__))) |
| 21 | + print("to upgrade with pip, type: pip install -U setuptools") |
| 22 | + raise AssertionError("compdb requires setuptools 3.3 higher") |
| 23 | + |
11 | 24 | with open(path.join(local_path, 'README.rst'), encoding='utf-8') as f:
|
12 | 25 | long_desc = f.read()
|
13 | 26 |
|
14 | 27 | about = {}
|
15 | 28 | with open(path.join(local_path, "compdb", "__about__.py")) as f:
|
16 | 29 | exec(f.read(), about)
|
17 | 30 |
|
18 |
| -dependencies = [] |
| 31 | +install_requires = [] |
| 32 | +extras_require = {} |
19 | 33 |
|
20 |
| -if sys.version_info[0] < 3: |
21 |
| - # Would be nicer in 'extra_require' with an environment marker (PEP 496), |
22 |
| - # but this requires a more recent version of setuptools |
23 |
| - # than provided by Ubuntu 14.04. |
24 |
| - dependencies.append('configparser') |
| 34 | +# Depending on the setuptools version, |
| 35 | +# fill in install_requires or extras_require. |
| 36 | +# |
| 37 | +# The ideas comes from the following article: |
| 38 | +# - https://hynek.me/articles/conditional-python-dependencies/ |
| 39 | +# |
| 40 | +# This handles Ubuntu 14.04, which comes with setuptools 3.3. |
| 41 | +# But not everything is handled, a more recent version of setuptools |
| 42 | +# is still required to support bdist_wheel. |
| 43 | +if LooseVersion(setuptools.__version__) < LooseVersion('18'): |
| 44 | + if "bdist_wheel" in sys.argv: |
| 45 | + print("setuptools version:", str(LooseVersion(setuptools.__version__))) |
| 46 | + print("to upgrade with pip, type: pip install -U setuptools") |
| 47 | + raise AssertionError("setuptools >= 18 required for wheels") |
| 48 | + if sys.version_info[0] < 3: |
| 49 | + install_requires.append('configparser') |
| 50 | +else: # setuptools >= 18 |
| 51 | + extras_require[":python_version<'3.0'"] = ['configparser'] |
25 | 52 |
|
26 | 53 | setup(
|
27 | 54 | name=about['__prog__'],
|
|
55 | 82 | ],
|
56 | 83 | },
|
57 | 84 | python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*',
|
58 |
| - install_requires=dependencies) |
| 85 | + install_requires=install_requires, |
| 86 | + extras_require=extras_require) |
0 commit comments