summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2018-08-06 23:18:42 +0200
committerIlya Etingof <etingof@gmail.com>2018-08-06 23:37:07 +0200
commitd662c557a78194cdfa1992c77e6e98f8f0ed478c (patch)
tree29e35edae671ae591d8bbe860e2fa3a19d1833b4 /setup.py
parent861d28f2003f6340ee1a64d76020839c02018b62 (diff)
downloadpysnmp-git-d662c557a78194cdfa1992c77e6e98f8f0ed478c.tar.gz
Improve package build and dependency tracking
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py61
1 files changed, 52 insertions, 9 deletions
diff --git a/setup.py b/setup.py
index 30fc8d49..eb59205d 100644
--- a/setup.py
+++ b/setup.py
@@ -7,6 +7,7 @@
"""
import sys
import os
+import re
classifiers = """\
Development Status :: 5 - Production/Stable
@@ -56,13 +57,53 @@ if py_version < (2, 4):
print("ERROR: this package requires Python 2.4 or later!")
sys.exit(1)
-requires = ['pyasn1>=0.2.3', 'pysmi']
+requires = [ln.strip() for ln in open('requirements.txt').readlines()]
-if py_version < (2, 7):
- requires.append('ordereddict')
+resolved_requires = []
+
+for requirement in requires:
+ match = re.match(
+ r'(.*?)\s*;\s*python_version\s*([<>=!~]+)\s*\'(.*?)\'', requirement)
+
+ if not match:
+ resolved_requires.append(requirement)
+ continue
+
+ package, condition, expected_py = match.groups()
+
+ expected_py = tuple([int(x) for x in expected_py.split('.')])
+
+ if py_version == expected_py and condition in ('<=', '==', '>='):
+ resolved_requires.append(package)
+
+ elif py_version < expected_py and condition in ('<=', '<'):
+ resolved_requires.append(package)
+
+ elif py_version > expected_py and condition in ('>=', '>'):
+ resolved_requires.append(package)
try:
- from setuptools import setup
+ import setuptools
+
+ setup, Command = setuptools.setup, setuptools.Command
+
+ observed_version = [int(x) for x in setuptools.__version__.split('.')]
+ required_version = [36, 2, 0]
+
+ # NOTE(etingof): require fresh setuptools to build proper wheels
+ # See also: https://hynek.me/articles/conditional-python-dependencies/
+ if ('bdist_wheel' in sys.argv and
+ observed_version < required_version):
+ print("ERROR: your wheels won't come out round with setuptools %s! "
+ "Upgrade to %s and try again." % (
+ '.'.join([str(x) for x in observed_version]),
+ '.'.join([str(x) for x in required_version])))
+ sys.exit(1)
+
+ # NOTE(etingof): older setuptools fail at parsing python_version
+
+ if observed_version < required_version:
+ requires = resolved_requires
params = {
'install_requires': requires,
@@ -70,16 +111,18 @@ try:
}
except ImportError:
- for arg in sys.argv:
- if 'egg' in arg:
- howto_install_setuptools()
- sys.exit(1)
+ if 'bdist_wheel' in sys.argv or 'bdist_egg' in sys.argv:
+ howto_install_setuptools()
+ sys.exit(1)
from distutils.core import setup
params = {}
+
if py_version > (2, 4):
- params['requires'] = requires
+ params['requires'] = [
+ re.sub(r'(.*?)([<>=!~]+)(.*)', r'\g<1>\g<2>(\g<3>)', r) for r in resolved_requires
+ ]
doclines = [x.strip() for x in (__doc__ or '').split('\n') if x]