|
1 | 1 | """The setup script."""
|
2 |
| -from pathlib import Path |
3 |
| -from typing import List, Optional |
4 |
| - |
5 | 2 | from setuptools import setup
|
6 | 3 |
|
7 |
| - |
8 |
| -def parse_reqs_in(filepath: Path, visited: Optional[set] = None) -> List[str]: # noqa: C901 |
9 |
| - """ |
10 |
| - Parse a file path containing a pip-tools requirements.in and return a list of requirements. |
11 |
| -
|
12 |
| - Will properly follow ``-r`` and ``-c`` links like ``pip-tools``. This |
13 |
| - means layered requirements will be returned as one list. |
14 |
| -
|
15 |
| - Other ``pip-tools`` and ``pip``-specific lines are excluded. |
16 |
| -
|
17 |
| - Args: |
18 |
| - filepath (Path): The path to the requirements file |
19 |
| - visited (set, optional): A set of paths that have already been visited. |
20 |
| -
|
21 |
| - Returns: |
22 |
| - All the requirements as a list. |
23 |
| - """ |
24 |
| - if visited is None: |
25 |
| - visited = set() |
26 |
| - reqstr: str = filepath.read_text() |
27 |
| - reqs: List[str] = [] |
28 |
| - for line in reqstr.splitlines(keepends=False): |
29 |
| - line = line.strip() # noqa: PLW2901 |
30 |
| - if not line: |
31 |
| - continue |
32 |
| - elif not line or line.startswith("#"): |
33 |
| - # comments are lines that start with # only |
34 |
| - continue |
35 |
| - elif line.startswith("-c"): |
36 |
| - _, new_filename = line.split() |
37 |
| - new_file_path = filepath.parent / new_filename.replace(".txt", ".in") |
38 |
| - if new_file_path not in visited: |
39 |
| - visited.add(new_file_path) |
40 |
| - reqs.extend(parse_reqs_in(new_file_path, visited)) |
41 |
| - elif line.startswith(("-r", "--requirement")): |
42 |
| - _, new_filename = line.split() |
43 |
| - new_file_path = filepath.parent / new_filename |
44 |
| - if new_file_path not in visited: |
45 |
| - visited.add(new_file_path) |
46 |
| - reqs.extend(parse_reqs_in(new_file_path, visited)) |
47 |
| - elif line.startswith("-f") or line.startswith("-i") or line.startswith("--"): |
48 |
| - continue |
49 |
| - elif line.startswith("-Z") or line.startswith("--always-unzip"): |
50 |
| - continue |
51 |
| - else: |
52 |
| - reqs.append(line) |
53 |
| - return reqs |
54 |
| - |
55 |
| - |
56 |
| -here: Path = Path(__file__).parent.absolute() |
57 |
| -requirements = parse_reqs_in(here / "requirements/prod.in") |
58 |
| -dev_requirements = parse_reqs_in(here / "requirements/dev.in") |
59 |
| -test_requirements = parse_reqs_in(here / "requirements/test.in") |
60 |
| - |
61 |
| -setup( |
62 |
| - install_requires=requirements, |
63 |
| - tests_require=test_requirements, |
64 |
| - extras_require={"dev": dev_requirements, "test": test_requirements}, |
65 |
| -) |
| 4 | +setup() |
0 commit comments