-
-
Notifications
You must be signed in to change notification settings - Fork 643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lockfiles: determine if Poetry meets our requirements #12568
Comments
@jsirois scoped out what it'd take to do this in Pex. Copied from Slack:
Thanks @jsirois, that's a really exciting find.
Agreed, sounds reasonable given the tradeoffs.
Hm, how would that work with my first question of handling multiple Python versions? |
Correct.
Correct. Lockfile generation is simple when generating the only lock you know works. Its only when you generate a platform independent lock where you don't know it actually works / is safe, etc that things get hard using Pip and you need to patch it. So that patching will be toggleable via a switch.
Who knows. I have not given that any thought. As mentioned elsewhere - the format has ~0 to do with anything here. Pex could generate the lockfile in any random format or support multiple. |
Closing for now as answered: we have a hypothesis that Pex's lockfile implementation will do what we need and @jsirois has been moving forward on an implementation. Thanks! |
#12470 determined we cannot use
pip-compile
. This is to determine if we can use Poetry vs. need to teach Pex how to generate lockfiles.(Credit to @jsirois for doing most of this initial investigation. Thank you!)
Problems solved by Poetry
Handling env markers
Poetry generates a lockfile intended to work for all requested environments, meaning: all requested Python interpreters and Linux, Windows, and macOS. This works consistently regardless of which machine you run Poetry from.
Solves #12200.
Solved issues
Poetry issues we can work around.
Poetry includes unused / unvetted dists
See #12458. This is a supply chain risk.
Our solution is to post-process
poetry.lock
to remove unused dists. It is still unresolved, though, how we will know what environments will be used and what will not.Support for
--platforms
See #12557. We want to only generate a lockfile if it is valid for the requested platforms, and not include entries/dists for unused platforms.
We can do this via post-processing
poetry.lock
.There is one known edge case where we will "cry wolf" when we didn't need to: #12557 (comment), although there is a decent workaround.
Handling of
setuptools
andwheel
Poetry 1.1 and earlier does not include these in lockfiles, which we need. Poetry 1.2 fixes it, but that's an alpha release and several months from becoming stable.
We worked around this by monkey matching to mark these dependencies as "safe".
Unsolved issues
Handling of "bifurcated requirements"
Poetry does not properly handle dependencies like:
pants/src/python/pants/backend/python/lint/flake8/subsystem.py
Lines 50 to 53 in 6d7d46b
Resulting in:
pants/3rdparty/python/lockfiles/flake8.txt
Lines 30 to 34 in df73917
See python-poetry/poetry#4381 for an issue John opened. We'll see if they're open to fixing it..
No support for
--find-links
Poetry supports indexes (
[python-repos].indexes
), but not--find-links
([python-repos].repos
). The issue has been open since 2019 with little traction: https://github.com/python-poetry/poetry/issues/1391, and no maintainer resposne despite being highly upvoted.This is a blocker, fwict. There are no documented workarounds, so we would likely need to contribute a patch and backport it to 1.1.
Leveraging Poetry's cache
At a minimum, we need to hook up Poetry to
named_caches
. Even better is teaching Pex how to consume Poetry's cache for downloading artifacts. A sample entry:Poetry's support is broken for changing the cache dir, though, and they have not fixed it in over a year: python-poetry/poetry#2445. On Linux, we can hack around it by setting
XDG_CACHE_HOME
, but there is no workaround on macOS. For this to work, we need to land a patch to Poetry itself, particularly Poetry 1.1 because 1.2 is alpha.I do not know how hard it would be to hook this up to Pex.
pip
options on individual requirements (TODO)Users have been asking for us to add support for pip options on individual requirements, rather than global options: #12090.
TODO: which of these pip options could be mapped to Poetry's pyproject.toml, if any?
Certs / auth (TODO)
Poetry does have support for credentials: https://python-poetry.org/docs/repositories/. TODO to confirm we can wire this all up properly.
Unsolvable issues
These are unlikely to be solved if we go with Poetry, e.g. they are unlikely to accept a patch or it's a fundamental problem. If we go with Poetry, we know we are making this tradeoff.
Using a new resolver
Switching from pip's new resolver (
resolvelib
) to Poetry's will risk breaking some users. Something that pip can resolve might not resolve for Poetry, and vice versa. Or they may resolve differently.To assess this risk, we would want to write an experiment that resolves using Poetry vs. using pip over N dependencies and check for discrepancies.
How to force transitive deps to a certain value
Pip's constraints files were originally intended to pin certain transitive deps, which you need to do if you don't like how the resolver did things.
There is no way to emulate this in Poetry, to force its resolver to use a particular version. See python-poetry/poetry#3225 for an issue proposing it. Someone tried implementing it in python-poetry/poetry#4005, but the maintainer was "not really enthused about this". After two months of no review, the author gave up and closed the issue.
There is a workaround: our users can hand edit the lockfiles we generate. They can also ignore Pants's generation and provide their own hand-generated lockfile. Of course, that is a subpar UX and harder for the user to get things right.
The text was updated successfully, but these errors were encountered: