Skip to content

Introduce a LockfileFormat enum.#23233

Merged
benjyw merged 5 commits intopantsbuild:mainfrom
benjyw:lockfile_format
Apr 9, 2026
Merged

Introduce a LockfileFormat enum.#23233
benjyw merged 5 commits intopantsbuild:mainfrom
benjyw:lockfile_format

Conversation

@benjyw
Copy link
Copy Markdown
Contributor

@benjyw benjyw commented Apr 8, 2026

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.

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.
@benjyw benjyw added the release-notes:not-required [CI] PR doesn't require mention in release notes label Apr 8, 2026
@benjyw benjyw requested review from cburroughs and tdyas April 8, 2026 15:56
@benjyw
Copy link
Copy Markdown
Contributor Author

benjyw commented Apr 8, 2026

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.

@benjyw benjyw requested a review from sureshjoshi April 8, 2026 16:05
@cburroughs
Copy link
Copy Markdown
Contributor

it got it right on the first try.

Jinxed!

logger = logging.getLogger(__name__)


class LockfileFormat(Enum):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this not to be a StrEnum if they are all strings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason, can change it.


class LockfileFormat(Enum):
Pex = "pex"
# The very old, deprecated constraints-based "lockfile" that should
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to start the deprecation process?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But also, I don't intend to support lockfile front matter for any new lockfile formats, so it's moot for line 272.

@benjyw benjyw merged commit fb9b33c into pantsbuild:main Apr 9, 2026
25 checks passed
@benjyw benjyw deleted the lockfile_format branch April 9, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes:not-required [CI] PR doesn't require mention in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants