Introduce a LockfileFormat enum.#23233
Conversation
Previously we had an `is_pex_native` boolean, where the alternative was using constraints files. This change makes way for new lockfile formats, specifically uv.lock.
|
AI disclosure: Claude did this, and it was simple enough that it got it right on the first try. Not sure it saved me much time, but whatever. |
Jinxed! |
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class LockfileFormat(Enum): |
There was a problem hiding this comment.
Any reason for this not to be a StrEnum if they are all strings?
There was a problem hiding this comment.
No reason, can change it.
|
|
||
| class LockfileFormat(Enum): | ||
| Pex = "pex" | ||
| # The very old, deprecated constraints-based "lockfile" that should |
There was a problem hiding this comment.
Any reason not to start the deprecation process?
There was a problem hiding this comment.
No reason. The current deprecation is for 3.0.0, which is silly. We can and should get rid of this.
| lockfile_contents = await get_digest_contents(lockfile_digest) | ||
| lock_bytes = lockfile_contents[0].content | ||
| is_pex_native = is_probably_pex_json_lockfile(lock_bytes) | ||
| lockfile_format = ( |
There was a problem hiding this comment.
Does Python have a match expression or some other way to check easily when new enums have been added? 2-item enums end up being the bane of my existence as I always forget to look for places where I did if/else while an enum was 2-items, then updated to 3 and bugs introduced.
Maybe there is a mypy or ruff lint?
There was a problem hiding this comment.
There is match/case, but it is a statement, not an expression, so you can't use it on the RHS of an assignment. But that's ok on line 272 below, since it already has that structure (I assume you didn't mean to use such an expression here on line 236, since this is where we decide which enum value is in play, so the match doesn't figure into it)
There was a problem hiding this comment.
But also, I don't intend to support lockfile front matter for any new lockfile formats, so it's moot for line 272.
Previously we had an
is_pex_nativeboolean,where the alternative was using constraints files.
This change makes way for new lockfile formats,
specifically uv.lock.