Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ repos:

- repo: local
hooks:
- id: pyproject.toml
name: pyproject.toml
- id: generate_requirements.py
name: generate_requirements.py
language: system
entry: python tools/generate_requirements.py
files: "pyproject.toml|requirements/.*\\.txt|tools/.*generate.*"
files: "pyproject.toml|requirements/.*\\.txt|tools/generate_requirements.py"
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Homepage = 'https://numpydoc.readthedocs.io'
Source = 'https://github.com/numpy/numpydoc/'

[project.optional-dependencies]
developer = [
'pre-commit>=3.3',
"tomli; python_version < '3.11'",
]
doc = [
'numpy>=1.22',
'matplotlib>=3.5',
Expand Down
6 changes: 6 additions & 0 deletions requirements/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
sphinx>=5
Jinja2>=2.10
tabulate>=0.8.10
tomli>=1.1.0;python_version<'3.11'
2 changes: 2 additions & 0 deletions requirements/developer.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
pre-commit>=3.3
tomli; python_version < '3.11'
3 changes: 2 additions & 1 deletion requirements/doc.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated from pyproject.toml
# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
numpy>=1.22
matplotlib>=3.5
pydata-sphinx-theme>=0.13
Expand Down
3 changes: 2 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated from pyproject.toml
# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
pytest
pytest-cov
matplotlib
33 changes: 25 additions & 8 deletions tools/generate_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,28 @@
except ImportError:
sys.exit("Please install `tomli` first: `pip install tomli`")

repo_dir = (Path(__file__).parent / "..").resolve()
req_dir = repo_dir / "requirements"
pyproject = toml.loads((repo_dir / "pyproject.toml").read_text())

for key, opt_list in pyproject["project"]["optional-dependencies"].items():
lines = ["# Generated from pyproject.toml"] + opt_list
req_fname = req_dir / f"{key}.txt"
req_fname.write_text("\n".join(lines) + "\n")
script_pth = Path(__file__)
repo_dir = script_pth.parent.parent
script_relpth = script_pth.relative_to(repo_dir)
header = [
f"# Generated via {script_relpth.as_posix()} and pre-commit hook.",
"# Do not edit this file; modify pyproject.toml instead.",
]


def generate_requirement_file(name: str, req_list: list[str]) -> None:
req_fname = repo_dir / "requirements" / f"{name}.txt"
req_fname.write_text("\n".join(header + req_list) + "\n")


def main() -> None:
pyproject = toml.loads((repo_dir / "pyproject.toml").read_text())

generate_requirement_file("default", pyproject["project"]["dependencies"])

for key, opt_list in pyproject["project"]["optional-dependencies"].items():
generate_requirement_file(key, opt_list)


if __name__ == "__main__":
main()