forked from callowayproject/cookie-composer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
58 lines (47 loc) · 1.82 KB
/
setup.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
56
57
58
"""The setup script."""
from pathlib import Path
from setuptools import setup
def parse_reqs_in(filepath: str) -> list:
"""
Parse a file path containing a pip-tools requirements.in and return a list of requirements.
Will properly follow ``-r`` and ``-c`` links like ``pip-tools``. This
means layered requirements will be returned as one list.
Other ``pip-tools`` and ``pip``-specific lines are excluded.
Args:
filepath: The path to the requirements file
Returns:
All the requirements as a list.
"""
path = Path(filepath)
reqstr = path.read_text()
reqs = []
for line in reqstr.splitlines():
line = line.strip()
if line == "":
continue
elif not line or line.startswith("#"):
# comments are lines that start with # only
continue
elif line.startswith("-c"):
_, new_filename = line.split()
new_file_path = path.parent / new_filename.replace(".txt", ".in")
reqs.extend(parse_reqs_in(new_file_path))
elif line.startswith(("-r", "--requirement")):
_, new_filename = line.split()
new_file_path = path.parent / new_filename
reqs.extend(parse_reqs_in(new_file_path))
elif line.startswith("-f") or line.startswith("-i") or line.startswith("--"):
continue
elif line.startswith("-Z") or line.startswith("--always-unzip"):
continue
else:
reqs.append(line)
return reqs
requirements = parse_reqs_in("requirements/prod.in")
dev_requirements = parse_reqs_in("requirements/dev.in")
test_requirements = parse_reqs_in("requirements/test.in")
setup(
install_requires=requirements,
tests_require=test_requirements,
extras_require={"dev": dev_requirements, "test": test_requirements},
)