Skip to content

Commit

Permalink
packaging: improve requirements loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Dec 7, 2023
1 parent 0502ea5 commit ee7ce2a
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ##################################

# standard library
import pathlib
from pathlib import Path

# 3rd party
from setuptools import find_packages, setup
Expand All @@ -17,30 +17,40 @@
# ########## Globals #############
# ################################

HERE = pathlib.Path(__file__).parent
HERE = Path(__file__).parent
README = (HERE / "README.md").read_text()

with open(HERE / "requirements/base.txt") as f:
requirements = [
line
for line in f.read().splitlines()
if not line.startswith(("#", "-")) and len(line)
]
# ############################################################################
# ########### Functions ############
# ##################################


def load_requirements(requirements_files: Path | list[Path]) -> list:
"""Helper to load requirements list from a path or a list of paths.
Args:
requirements_files (Path | list[Path]): path or list to paths of requirements
file(s)
Returns:
list: list of requirements loaded from file(s)
"""
out_requirements = []

with open(HERE / "requirements/development.txt") as f:
requirements_dev = [
line
for line in f.read().splitlines()
if not line.startswith(("#", "-")) and len(line)
]
if isinstance(requirements_files, Path):
requirements_files = [
requirements_files,
]

for requirements_file in requirements_files:
with requirements_file.open(encoding="UTF-8") as f:
out_requirements += [
line
for line in f.read().splitlines()
if not line.startswith(("#", "-")) and len(line)
]

with open(HERE / "requirements/documentation.txt") as f:
requirements_docs = [
line
for line in f.read().splitlines()
if not line.startswith(("#", "-")) and len(line)
]
return out_requirements


# ############################################################################
Expand Down Expand Up @@ -70,10 +80,12 @@
# dependencies
python_requires=">=3.8, <4",
extras_require={
"dev": requirements_dev,
"doc": requirements_docs,
# tooling
"dev": load_requirements(HERE / "requirements/development.txt"),
"doc": load_requirements(HERE / "requirements/documentation.txt"),
"test": load_requirements(HERE / "requirements/testing.txt"),
},
install_requires=requirements,
install_requires=load_requirements(HERE / "requirements/base.txt"),
# metadata
keywords="mkdocs rss git plugin",
classifiers=[
Expand Down

0 comments on commit ee7ce2a

Please sign in to comment.