-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup_utils.py
55 lines (48 loc) · 2.01 KB
/
setup_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import re
REQUIREMENT_RE = re.compile(r'^(([^=]+)[=<>]+[^#]+)(#.*)?$')
def update_pins(setup_args):
# Use requirements and constraints to set version pins
packages = set()
constraint_files = []
install_dir = os.path.dirname(__file__)
with open(os.path.join(install_dir, 'requirements.txt')) as requirements:
for r in requirements:
if r.lower().strip() == 'dallinger':
continue
if r.startswith('-c '):
constraint_files.append(r.replace('-c ', '').strip())
if not r.startswith('-') or r.startswith('#'):
package = r.strip().lower()
packages.add(package)
requirements = []
for fname in constraint_files:
with open(os.path.join(install_dir, fname)) as constraints:
for c in constraints:
matches = REQUIREMENT_RE.match(c.strip())
if not matches:
continue
match = matches.group(2).lower().strip()
req = matches.group(1).strip()
if match in packages:
requirements.append(req)
# pin extra requirements
for extra in setup_args['extras_require']:
extra_packages = setup_args['extras_require'][extra]
for i, package in enumerate(extra_packages[:]):
package = package.strip().lower()
matches = REQUIREMENT_RE.match(package)
if matches:
package = matches.group(2)
if package == match:
extra_packages[i] = req
if requirements:
setup_args['install_requires'] = requirements
# If not on Heroku, install setuptools-markdown.
try:
os.environ["DYNO"]
except KeyError:
setup_args.update({
"setup_requires": ['setuptools-markdown==0.4.1'],
"long_description_markdown_filename": 'README.md',
})