-
-
Notifications
You must be signed in to change notification settings - Fork 692
Introduce a LockfileFormat enum. #23233
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import logging | ||
| from collections.abc import Iterable, Iterator | ||
| from dataclasses import dataclass, field | ||
| from enum import StrEnum, auto | ||
| from typing import TYPE_CHECKING | ||
| from urllib.parse import urlparse | ||
|
|
||
|
|
@@ -50,6 +51,13 @@ | |
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class LockfileFormat(StrEnum): | ||
| Pex = auto() | ||
| # The very old, deprecated constraints-based "lockfile" that should | ||
| # be removed entirely. | ||
| ConstraintsDeprecated = auto() | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class Resolve: | ||
| # A named resolve for a "user lockfile". | ||
|
|
@@ -101,10 +109,10 @@ class LoadedLockfile: | |
| # An estimate of the number of requirements in this lockfile, to be used as a heuristic for | ||
| # available parallelism. | ||
| requirement_estimate: int | ||
| # True if the loaded lockfile is in PEX's native format. | ||
| is_pex_native: bool | ||
| # If !is_pex_native, the lockfile parsed as constraints strings, for use when the lockfile | ||
| # needs to be subsetted (see #15031, ##12222). | ||
| # The format of the loaded lockfile. | ||
| lockfile_format: LockfileFormat | ||
| # If lockfile_format is ConstraintsDeprecated, the lockfile parsed as constraints strings, | ||
| # for use when the lockfile needs to be subsetted (see #15031, ##12222). | ||
| as_constraints_strings: FrozenOrderedSet[str] | None | ||
| # The original file or file content (which may not have identical content to the output | ||
| # `lockfile_digest`). | ||
|
|
@@ -225,7 +233,11 @@ async def load_lockfile( | |
|
|
||
| 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 = ( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does Python have a Maybe there is a mypy or ruff lint?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| LockfileFormat.Pex | ||
| if is_probably_pex_json_lockfile(lock_bytes) | ||
| else LockfileFormat.ConstraintsDeprecated | ||
| ) | ||
| constraints_strings = None | ||
|
|
||
| metadata_url = PythonLockfileMetadata.metadata_location_for_lockfile(lockfile.url) | ||
|
|
@@ -256,7 +268,7 @@ async def load_lockfile( | |
| pass | ||
|
|
||
| if not metadata: | ||
| if is_pex_native: | ||
| if lockfile_format == LockfileFormat.Pex: | ||
| header_delimiter = "//" | ||
| stripped_lock_bytes = strip_comments_from_pex_json_lockfile(lock_bytes) | ||
| lockfile_digest = await create_digest( | ||
|
|
@@ -286,7 +298,7 @@ async def load_lockfile( | |
| lockfile_path, | ||
| metadata, | ||
| requirement_estimate, | ||
| is_pex_native, | ||
| lockfile_format, | ||
| constraints_strings, | ||
| original_lockfile=lockfile, | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.