Skip to content

Commit cb56a0f

Browse files
aignasrickeylev
andauthored
feat: support pyproject.toml in compile_pip_requirements (#1519)
With this PR we can also use `pyproject.toml` in addition to `requirements.in` which helps in making the requirements in a more structured form. For example, we could parse the toml itself and create aliases in the hub repos only for the packages outlined in the `pyproject.toml` file. The same for `gazelle`, we could restrict `gazelle_python.yaml` contents to only the dependencies listed in `pyproject.toml`. Examples can be migrated once we agree on the interface. Summary: - feat: support pyproject.toml in compile_pip_requirements - chore: use pyproject.toml for sphinx doc requirements --------- Co-authored-by: Richard Levasseur <[email protected]>
1 parent 78fc4de commit cb56a0f

File tree

18 files changed

+63
-33
lines changed

18 files changed

+63
-33
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ A brief description of the categories of changes:
4848
default, which will cause `gazelle` to change third-party dependency labels
4949
from `@pip_foo//:pkg` to `@pip//foo` by default.
5050

51+
* The `compile_pip_requirements` now defaults to `pyproject.toml` if the `src`
52+
or `requirements_in` attributes are unspecified, matching the upstream
53+
`pip-compile` behaviour more closely.
54+
5155
Breaking changes:
5256

5357
* (pip) `pip_install` repository rule in this release has been disabled and
@@ -76,6 +80,9 @@ Breaking changes:
7680
* (bzlmod) Added `.whl` patching support via `patches` and `patch_strip`
7781
arguments to the new `pip.override` tag class.
7882

83+
* (pip) Support for using [PEP621](https://peps.python.org/pep-0621/) compliant
84+
`pyproject.toml` for creating a resolved `requirements.txt` file.
85+
7986
## [0.26.0] - 2023-10-06
8087

8188
### Changed

docs/sphinx/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ sphinx_build_binary(
102102
# Run bazel run //docs/sphinx:requirements.update
103103
compile_pip_requirements(
104104
name = "requirements",
105+
src = "pyproject.toml",
105106
requirements_darwin = "requirements_darwin.txt",
106-
requirements_in = "requirements.in",
107107
requirements_txt = "requirements_linux.txt",
108108
target_compatible_with = _TARGET_COMPATIBLE_WITH,
109109
)

docs/sphinx/pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "rules_python_docs"
3+
version = "0.0.0"
4+
5+
dependencies = [
6+
# NOTE: This is only used as input to create the resolved requirements.txt
7+
# file, which is what builds, both Bazel and Readthedocs, both use.
8+
"sphinx",
9+
"myst-parser",
10+
"sphinx_rtd_theme",
11+
"readthedocs-sphinx-ext",
12+
]

docs/sphinx/requirements.in

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

docs/sphinx/requirements_darwin.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ mdurl==0.1.2 \
184184
myst-parser==1.0.0 \
185185
--hash=sha256:502845659313099542bd38a2ae62f01360e7dd4b1310f025dd014dfc0439cdae \
186186
--hash=sha256:69fb40a586c6fa68995e6521ac0a525793935db7e724ca9bac1d33be51be9a4c
187-
# via -r docs/sphinx/requirements.in
187+
# via rules-python-docs (docs/sphinx/pyproject.toml)
188188
packaging==23.0 \
189189
--hash=sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2 \
190190
--hash=sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97
@@ -240,7 +240,7 @@ pyyaml==6.0 \
240240
readthedocs-sphinx-ext==2.2.3 \
241241
--hash=sha256:6583c26791a5853ee9e57ce9db864e2fb06808ba470f805d74d53fc50811e012 \
242242
--hash=sha256:e9d911792789b88ae12e2be94d88c619f89a4fa1fe9e42c1505c9930a07163d8
243-
# via -r docs/sphinx/requirements.in
243+
# via rules-python-docs (docs/sphinx/pyproject.toml)
244244
requests==2.31.0 \
245245
--hash=sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f \
246246
--hash=sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1
@@ -255,14 +255,14 @@ sphinx==6.1.3 \
255255
--hash=sha256:0dac3b698538ffef41716cf97ba26c1c7788dba73ce6f150c1ff5b4720786dd2 \
256256
--hash=sha256:807d1cb3d6be87eb78a381c3e70ebd8d346b9a25f3753e9947e866b2786865fc
257257
# via
258-
# -r docs/sphinx/requirements.in
259258
# myst-parser
259+
# rules-python-docs (docs/sphinx/pyproject.toml)
260260
# sphinx-rtd-theme
261261
# sphinxcontrib-jquery
262262
sphinx-rtd-theme==1.2.0 \
263263
--hash=sha256:a0d8bd1a2ed52e0b338cbe19c4b2eef3c5e7a048769753dac6a9f059c7b641b8 \
264264
--hash=sha256:f823f7e71890abe0ac6aaa6013361ea2696fc8d3e1fa798f463e82bdb77eeff2
265-
# via -r docs/sphinx/requirements.in
265+
# via rules-python-docs (docs/sphinx/pyproject.toml)
266266
sphinxcontrib-applehelp==1.0.4 \
267267
--hash=sha256:29d341f67fb0f6f586b23ad80e072c8e6ad0b48417db2bde114a4c9746feb228 \
268268
--hash=sha256:828f867945bbe39817c210a1abfd1bc4895c8b73fcaade56d45357a348a07d7e

docs/sphinx/requirements_linux.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ mdurl==0.1.2 \
184184
myst-parser==1.0.0 \
185185
--hash=sha256:502845659313099542bd38a2ae62f01360e7dd4b1310f025dd014dfc0439cdae \
186186
--hash=sha256:69fb40a586c6fa68995e6521ac0a525793935db7e724ca9bac1d33be51be9a4c
187-
# via -r docs/sphinx/requirements.in
187+
# via rules-python-docs (docs/sphinx/pyproject.toml)
188188
packaging==23.0 \
189189
--hash=sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2 \
190190
--hash=sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97
@@ -240,7 +240,7 @@ pyyaml==6.0 \
240240
readthedocs-sphinx-ext==2.2.3 \
241241
--hash=sha256:6583c26791a5853ee9e57ce9db864e2fb06808ba470f805d74d53fc50811e012 \
242242
--hash=sha256:e9d911792789b88ae12e2be94d88c619f89a4fa1fe9e42c1505c9930a07163d8
243-
# via -r docs/sphinx/requirements.in
243+
# via rules-python-docs (docs/sphinx/pyproject.toml)
244244
requests==2.31.0 \
245245
--hash=sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f \
246246
--hash=sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1
@@ -255,14 +255,14 @@ sphinx==6.1.3 \
255255
--hash=sha256:0dac3b698538ffef41716cf97ba26c1c7788dba73ce6f150c1ff5b4720786dd2 \
256256
--hash=sha256:807d1cb3d6be87eb78a381c3e70ebd8d346b9a25f3753e9947e866b2786865fc
257257
# via
258-
# -r docs/sphinx/requirements.in
259258
# myst-parser
259+
# rules-python-docs (docs/sphinx/pyproject.toml)
260260
# sphinx-rtd-theme
261261
# sphinxcontrib-jquery
262262
sphinx-rtd-theme==1.2.0 \
263263
--hash=sha256:a0d8bd1a2ed52e0b338cbe19c4b2eef3c5e7a048769753dac6a9f059c7b641b8 \
264264
--hash=sha256:f823f7e71890abe0ac6aaa6013361ea2696fc8d3e1fa798f463e82bdb77eeff2
265-
# via -r docs/sphinx/requirements.in
265+
# via rules-python-docs (docs/sphinx/pyproject.toml)
266266
sphinxcontrib-applehelp==1.0.4 \
267267
--hash=sha256:29d341f67fb0f6f586b23ad80e072c8e6ad0b48417db2bde114a4c9746feb228 \
268268
--hash=sha256:828f867945bbe39817c210a1abfd1bc4895c8b73fcaade56d45357a348a07d7e

examples/build_file_generation/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load("@rules_python_gazelle_plugin//modules_mapping:def.bzl", "modules_mapping")
1111

1212
compile_pip_requirements(
1313
name = "requirements",
14-
requirements_in = "requirements.in",
14+
src = "requirements.in",
1515
requirements_txt = "requirements_lock.txt",
1616
requirements_windows = "requirements_windows.txt",
1717
)

examples/bzlmod/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
1616
# with pip-compile.
1717
compile_pip_requirements_3_9(
1818
name = "requirements_3_9",
19-
requirements_in = "requirements.in",
19+
src = "requirements.in",
2020
requirements_txt = "requirements_lock_3_9.txt",
2121
requirements_windows = "requirements_windows_3_9.txt",
2222
)
@@ -25,7 +25,7 @@ compile_pip_requirements_3_9(
2525
# with pip-compile.
2626
compile_pip_requirements_3_10(
2727
name = "requirements_3_10",
28-
requirements_in = "requirements.in",
28+
src = "requirements.in",
2929
requirements_txt = "requirements_lock_3_10.txt",
3030
requirements_windows = "requirements_windows_3_10.txt",
3131
)

examples/bzlmod/other_module/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ load("@python_versions//3.11:defs.bzl", compile_pip_requirements_311 = "compile_
44
# override in the MODULE.bazel.
55
compile_pip_requirements_311(
66
name = "requirements",
7-
requirements_in = "requirements.in",
7+
src = "requirements.in",
88
requirements_txt = "requirements_lock_3_11.txt",
99
)

examples/bzlmod_build_file_generation/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ load("@rules_python_gazelle_plugin//modules_mapping:def.bzl", "modules_mapping")
1616
# with pip-compile.
1717
compile_pip_requirements(
1818
name = "requirements",
19-
requirements_in = "requirements.in",
19+
src = "requirements.in",
2020
requirements_txt = "requirements_lock.txt",
2121
requirements_windows = "requirements_windows.txt",
2222
)

0 commit comments

Comments
 (0)