Skip to content

Commit 65a1c85

Browse files
rickeylevaignas
andauthored
docs: tell how to emulate dependency groups with pip-compile (bazel-contrib#3089)
While pyproject.toml is supported by piptools, dependency groups aren't. They can be emulated by using multiple files. Explain how to do that in the docs and link to the upstream feature request (jazzband/pip-tools#2062) Along the way, link to our own feature request for pylock.toml support in pip.parse. --------- Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
1 parent a97b98c commit 65a1c85

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

docs/pypi/lock.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
:::{note}
77
Currently `rules_python` only supports `requirements.txt` format.
8+
9+
#{gh-issue}`2787` tracks `pylock.toml` support.
810
:::
911

1012
## requirements.txt
@@ -37,11 +39,33 @@ This rule generates two targets:
3739
Once you generate this fully specified list of requirements, you can install the requirements ([bzlmod](./download)/[WORKSPACE](./download-workspace)).
3840

3941
:::{warning}
40-
If you're specifying dependencies in `pyproject.toml`, make sure to include the `[build-system]` configuration, with pinned dependencies. `compile_pip_requirements` will use the build system specified to read your project's metadata, and you might see non-hermetic behavior if you don't pin the build system.
42+
If you're specifying dependencies in `pyproject.toml`, make sure to include the
43+
`[build-system]` configuration, with pinned dependencies.
44+
`compile_pip_requirements` will use the build system specified to read your
45+
project's metadata, and you might see non-hermetic behavior if you don't pin the
46+
build system.
4147

42-
Not specifying `[build-system]` at all will result in using a default `[build-system]` configuration, which uses unpinned versions ([ref](https://peps.python.org/pep-0518/#build-system-table)).
48+
Not specifying `[build-system]` at all will result in using a default
49+
`[build-system]` configuration, which uses unpinned versions
50+
([ref](https://peps.python.org/pep-0518/#build-system-table)).
4351
:::
4452

53+
54+
#### pip compile Dependency groups
55+
56+
pip-compile doesn't yet support pyproject.toml dependency groups. Follow
57+
[pip-tools #2062](https://github.com/jazzband/pip-tools/issues/2062)
58+
to see the status of their support.
59+
60+
In the meantime, support can be emulated by passing multiple files to `srcs`:
61+
62+
```starlark
63+
compile_pip_requirements(
64+
srcs = ["pyproject.toml", "requirements-dev.in"]
65+
...
66+
)
67+
```
68+
4569
### uv pip compile (bzlmod only)
4670

4771
We also have experimental setup for the `uv pip compile` way of generating lock files.

python/private/pypi/pip_compile.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def pip_compile(
4040
tags = None,
4141
constraints = [],
4242
**kwargs):
43-
"""Generates targets for managing pip dependencies with pip-compile.
43+
"""Generates targets for managing pip dependencies with pip-compile (piptools).
4444
4545
By default this rules generates a filegroup named "[name]" which can be included in the data
4646
of some other compile_pip_requirements rule that references these requirements
@@ -65,7 +65,10 @@ def pip_compile(
6565
* a requirements text file, usually named `requirements.in`
6666
* A `.toml` file, where the `project.dependencies` list is used as per
6767
[PEP621](https://peps.python.org/pep-0621/).
68-
extra_args: passed to pip-compile.
68+
extra_args: passed to pip-compile (aka `piptools`). See the
69+
[pip-compile docs](https://pip-tools.readthedocs.io/en/latest/cli/pip-compile)
70+
for args and meaning (passing `-h` and/or `--version` can help
71+
inform what args are available)
6972
extra_deps: extra dependencies passed to pip-compile.
7073
generate_hashes: whether to put hashes in the requirements_txt file.
7174
py_binary: the py_binary rule to be used.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy