Hi. I’m wondering if pants works with pdm? I did a...
# general
b
Hi. I’m wondering if pants works with pdm? I did a search in the slack for it and it seem like it at least kind of does but the documentation doesn’t mention poetry or pdm. However, there’s also this blog post which says that it works with poetry. So what’s up with all this?
h
Hi! I don't know of anyone working to integrate with pdm, although that would be neat Re the Poetry integration, the integration looks like Pants knowing how to read your pyproject.toml and convert it into python_requirement targets. That then gets used for Pants's normal way of handling third-party dependencies via Pex, which uses Pip. We're not using Poetry to actually install things A PDM integration for core Pants would look similar, that we still use pip/pep, but know how to consume your PDM config to make the integration easier on you (If it was critical you still use PDM as the installer, then you'd want to consider redoing the Python backend as a plugin. The builtin one is heavily linked to Pex, in part due to good performance characteristics for Pants's execution model)
b
PDM is more critical than pants right now (since we aren’t using pants). So if I write a bit of code to just read the pyproject.toml and pull out a list of the dependencies (and optional dependencies and dev dependencies) and passed that to pants in the right format what does that buy me? Can I do linting? Do I have that fancy magic where Pants knows what tests were affected by a change and only runs the affected tests? What can’t I do with that (relatively) simple level of integration?
b
We have a hybrid poetry and pants repo (for several reasons, including https://github.com/pantsbuild/pants/issues/15704 and the fact it doesn't read
poetry.lock
). Thus, we load dependencies into pants by first exporting
poetry export
to a (checked in)
requirements.txt
, and then use
python_requirements
on that. (We have tests that check that
requirements.txt
matches poetry, and that the Pants lockfile matches
requirements.txt
) All the pants fanciness (formatting, linting, tests, ...) works fine under this scheme.
b
Okay. Thanks!
h
The question would be what you’d like Pants to do for you in this scenario? For example, Pants could do that “fancy magic”, yes. I don’t know much about PDM, but if it uses poetry-style pyproject.toml to specify requirements then Pants can read those already: https://www.pantsbuild.org/docs/python-third-party-dependencies#poetry so you shouldn’t need to write any code to pull out dependencies
But to figure out what kind of integration makes sense, the first thing to know would be what operations you’d want Pants to help with, vs what you’d want to keep in PDM.
b
PDM uses a slightly different format than poetry so it’s not immediately compatible. I want to keep all dependency management in PDM, testing, linting, and everything else goes to pants.
h
Got it. We’d need a
pdm_requirements
macro, similar to
poetry_requirements
, that reads and passes the requirements on to Pants. I think that should be pretty straightforward to implement, if you want to take a whack at it. poetry_requirements is implemented here
🙌 1
👍 1
And there may be code that can be shared between the two? I don’t know what the differences would be