Skip to content

Commit 94ef7f0

Browse files
authored
Generate requirements files from pyproject.toml (#483)
1 parent 9656a05 commit 94ef7f0

File tree

8 files changed

+29
-136
lines changed

8 files changed

+29
-136
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ repos:
4444
- id: pyproject.toml
4545
name: pyproject.toml
4646
language: system
47-
entry: python tools/generate_pyproject.toml.py
48-
files: "pyproject.toml|requirements/.*\\.txt|tools/.*pyproject.*"
47+
entry: python tools/generate_requirements.py
48+
files: "pyproject.toml|requirements/.*\\.txt|tools/.*generate.*"

pyproject.toml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
################################################################################
2-
# DO NOT EDIT
3-
# AUTOGENERATED BY
4-
#
5-
# $ python tools/generate_pyproject.toml.py
6-
#
7-
# EDIT tools/pyproject.toml.in AND RUN THAT SCRIPT.
8-
#
9-
################################################################################
10-
111
[build-system]
122
build-backend = 'setuptools.build_meta'
133
requires = ['setuptools>=61.2']
@@ -67,6 +57,7 @@ test = [
6757

6858
[project.scripts]
6959
validate-docstrings = 'numpydoc.hooks.validate_docstrings:main'
60+
7061
[tool.setuptools]
7162
include-package-data = false
7263
packages = [
@@ -84,6 +75,7 @@ numpydoc = [
8475
'tests/tinybuild/*.py',
8576
'templates/*.rst',
8677
]
78+
8779
[tool.pytest.ini_options]
8880
addopts = '''
8981
--showlocals --doctest-modules -ra --cov-report= --cov=numpydoc

requirements/developer.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pre-commit>=3.3
2-
rtoml
2+
tomli; python_version < '3.11'

requirements/doc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Generated from pyproject.toml
12
numpy>=1.22
23
matplotlib>=3.5
34
pydata-sphinx-theme>=0.13

requirements/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Generated from pyproject.toml
12
pytest
23
pytest-cov
34
matplotlib

tools/generate_pyproject.toml.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

tools/generate_requirements.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Generate requirements/*.txt files from pyproject.toml."""
3+
4+
import sys
5+
from pathlib import Path
6+
7+
try: # standard module since Python 3.11
8+
import tomllib as toml
9+
except ImportError:
10+
try: # available for older Python via pip
11+
import tomli as toml
12+
except ImportError:
13+
sys.exit("Please install `tomli` first: `pip install tomli`")
14+
15+
repo_dir = (Path(__file__).parent / "..").resolve()
16+
req_dir = repo_dir / "requirements"
17+
pyproject = toml.loads((repo_dir / "pyproject.toml").read_text())
18+
19+
for key, opt_list in pyproject["project"]["optional-dependencies"].items():
20+
lines = ["# Generated from pyproject.toml"] + opt_list
21+
req_fname = req_dir / f"{key}.txt"
22+
req_fname.write_text("\n".join(lines) + "\n")

tools/pyproject.toml.in

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)