Skip to content

Commit

Permalink
Improve setup: add extras and factorize requirements loading (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Sep 26, 2023
2 parents e217bb3 + 4081ab3 commit 6bcdcb4
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,42 @@
# The directory containing this file
HERE = Path(__file__).parent

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

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

# The text of the README file
README = (HERE / "README.md").read_text()

# ############################################################################
# ########### 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 = []

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)
]

return out_requirements


# ############################################################################
# ########### Main #################
# ##################################
Expand Down Expand Up @@ -72,9 +91,12 @@
exclude=["contrib", "docs", "*.tests", "*.tests.*", "tests.*", "tests", ".venv"]
),
include_package_data=True,
install_requires=requirements,
install_requires=load_requirements(HERE / "requirements/base.txt"),
extras_require={
"dev": dev_requirements,
# tooling
"dev": load_requirements(HERE / "requirements/development.txt"),
"doc": load_requirements(HERE / "requirements/documentation.txt"),
"test": load_requirements(HERE / "requirements/testing.txt"),
},
entry_points={
"console_scripts": [
Expand Down

0 comments on commit 6bcdcb4

Please sign in to comment.