I’m moving my specified dependencies from a requir...
# general
h
I’m moving my specified dependencies from a requirements.txt to pyproject.toml to enable using
uv
lockfiles and converting the output into Pex lockfiles. Does Pants support the
[dependency-groups]
fields in pyproject.toml in any way? It would be useful to be able to generate separate resolves from these as I have in the past for dependencies related to: test, tools, docs etc.
n
@hundreds-carpet-28072 I'm afraid I can't provide any help, but I'm very curious about what you're doing. We'd love to move to
uv
for dependency resolution but, I gather, Pants doesn't support that yet. Can you explain a bit more about how you're making this work?
h
Hi Oliver, I’m using a modified version of Alex’s script he’s shared to convert from uv.lock files to pex.lock files here: https://pantsbuild.slack.com/archives/C046T6T9U/p1746426500178629?thread_ts=1746139022.265759&cid=C046T6T9U. The only caveat being this has required me to move our dependencies from requirements.txt-format files all into pyproject.toml, which means that defining multiple Pants/Pex resolves is now not possible. I tried pretty extensively to instead convert from the output of
uv pip compile
(including all exposed distribution parameters, see example command below), but I can say with 95% confidence that it’s not possible to convert from the outputted pylock.toml file to a pex.lock file in this way due to some missing fields that are exposed via
uv lock
but not
uv pip compile
. Most notably the
Requires-Dist
field of Python wheels/bdists that is queried in both commands but not exposed in the final output, which is used by the pex.lock file.
Copy code
uv pip compile ${requirements_file} --output-file ${uv_lockfile} \
    -q --universal --index-strategy unsafe-best-match \
    --generate-hashes --no-strip-markers --no-strip-extras
I also saw some difficulty due to the fact that we support multiple Python versions, unlike Alex’s system - but I got around that with a bit of hackery converting environment markers (
python_full_version
) to
Requires-Python
fields.
e
@hundreds-carpet-28072 Curious what you are seeing re: > move dependencies from requirements.txt-format into pyproject.toml, which means that defining multiple resolves is now not possible. poetry_requirements does support the
resolve
field, and as far as I understand
poetry_requirements
and
python_requirements
are both just macros that generate an individual
python_requirement
target for each entry. Even if dependency groups isn't used by pants, I'd expect something like:
Copy code
poetry_requirements(
    source="pyproject.shared.toml",
    resolve=parametrize("resolveA", "resolveB"),
)
poetry_requirements(
    source="pyproject.resolveA.toml"
    resolve="resolveA",
)
poetry_requirements(
    source="pyproject.resolveB.toml"
    resolve="resolveB",
)
to still work, mirroring how you might use multiple
requirements.txt
for multiple resolves.
h
The difference is I have a single
pyproject.toml
file, not separate ones. This includes dependency groups for test/tools/docs dependencies that make sense to have their own resolve but afaik there’s notway to programmatically declare or generate resolves per dependency group of pyproject.toml in BUILD files?