|
5 | 5 | # ################################## |
6 | 6 |
|
7 | 7 | # standard library |
8 | | -import pathlib |
| 8 | +from pathlib import Path |
| 9 | +from typing import List, Union |
9 | 10 |
|
10 | 11 | # 3rd party |
11 | 12 | from setuptools import find_packages, setup |
|
17 | 18 | # ########## Globals ############# |
18 | 19 | # ################################ |
19 | 20 |
|
20 | | -HERE = pathlib.Path(__file__).parent |
| 21 | +HERE = Path(__file__).parent |
21 | 22 | README = (HERE / "README.md").read_text() |
22 | 23 |
|
23 | | -with open(HERE / "requirements/base.txt") as f: |
24 | | - requirements = [ |
25 | | - line |
26 | | - for line in f.read().splitlines() |
27 | | - if not line.startswith(("#", "-")) and len(line) |
28 | | - ] |
| 24 | +# ############################################################################ |
| 25 | +# ########### Functions ############ |
| 26 | +# ################################## |
| 27 | + |
| 28 | + |
| 29 | +def load_requirements(requirements_files: Union[Path, List[Path]]) -> list: |
| 30 | + """Helper to load requirements list from a path or a list of paths. |
| 31 | +
|
| 32 | + Args: |
| 33 | + requirements_files (Path | list[Path]): path or list to paths of requirements |
| 34 | + file(s) |
| 35 | +
|
| 36 | + Returns: |
| 37 | + list: list of requirements loaded from file(s) |
| 38 | + """ |
| 39 | + out_requirements = [] |
29 | 40 |
|
30 | | -with open(HERE / "requirements/development.txt") as f: |
31 | | - requirements_dev = [ |
32 | | - line |
33 | | - for line in f.read().splitlines() |
34 | | - if not line.startswith(("#", "-")) and len(line) |
35 | | - ] |
| 41 | + if isinstance(requirements_files, Path): |
| 42 | + requirements_files = [ |
| 43 | + requirements_files, |
| 44 | + ] |
36 | 45 |
|
| 46 | + for requirements_file in requirements_files: |
| 47 | + with requirements_file.open(encoding="UTF-8") as f: |
| 48 | + out_requirements += [ |
| 49 | + line |
| 50 | + for line in f.read().splitlines() |
| 51 | + if not line.startswith(("#", "-")) and len(line) |
| 52 | + ] |
37 | 53 |
|
38 | | -with open(HERE / "requirements/documentation.txt") as f: |
39 | | - requirements_docs = [ |
40 | | - line |
41 | | - for line in f.read().splitlines() |
42 | | - if not line.startswith(("#", "-")) and len(line) |
43 | | - ] |
| 54 | + return out_requirements |
44 | 55 |
|
45 | 56 |
|
46 | 57 | # ############################################################################ |
|
70 | 81 | # dependencies |
71 | 82 | python_requires=">=3.8, <4", |
72 | 83 | extras_require={ |
73 | | - "dev": requirements_dev, |
74 | | - "doc": requirements_docs, |
| 84 | + # tooling |
| 85 | + "dev": load_requirements(HERE / "requirements/development.txt"), |
| 86 | + "doc": load_requirements(HERE / "requirements/documentation.txt"), |
| 87 | + "test": load_requirements(HERE / "requirements/testing.txt"), |
75 | 88 | }, |
76 | | - install_requires=requirements, |
| 89 | + install_requires=load_requirements(HERE / "requirements/base.txt"), |
77 | 90 | # metadata |
78 | 91 | keywords="mkdocs rss git plugin", |
79 | 92 | classifiers=[ |
|
0 commit comments