Skip to content
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

[12610] add versions to lockfiles #12788

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/python/pants/backend/python/util_rules/lockfile_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LockfileMetadata:

@classmethod
def from_lockfile(
cls, lockfile: bytes, lockfile_scope_name: str | None = None
cls, lockfile: bytes, lockfile_path: str | None = None, resolve_name: str | None = None
) -> LockfileMetadata:
"""Parse all relevant metadata from the lockfile's header."""
in_metadata_block = False
Expand All @@ -43,21 +43,22 @@ def from_lockfile(
metadata_lines.append(line[2:])

error_suffix = "To resolve this error, you will need to regenerate the lockfile by running `./pants generate-lockfiles"
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting nit, this is over 100 lines and Black won't attempt to fix. You'd need to use implicit string concatenation.


if lockfile_scope_name:
if resolve_name:
error_suffix += "--resolve={tool_name}"

error_suffix += "`."

lockfile_description: str = ""
if lockfile_scope_name:
lockfile_description = f"the lockfile for `{lockfile_scope_name}`"
if lockfile_path is not None and resolve_name is not None:
lockfile_description = f"the lockfile `{lockfile_path}` for `{resolve_name}`"
elif lockfile_path is not None:
lockfile_description = f"the lockfile `{lockfile_path}`"
elif resolve_name is not None:
lockfile_description = f"the lockfile for `{resolve_name}`"
else:
"""this lockfile."""
lockfile_description = "this lockfile"

if not metadata_lines:
raise InvalidLockfileError(
f"Could not find a pants metadata block in this {lockfile_scope_name}. {error_suffix}"
f"Could not find a pants metadata block in {lockfile_description}. {error_suffix}"
)

try:
Expand Down
19 changes: 12 additions & 7 deletions src/python/pants/backend/python/util_rules/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,11 @@ async def build_pex_component(
constraint_file_digest = EMPTY_DIGEST
requirements_file_digest = EMPTY_DIGEST

lockfile_scope_name: str | None
if isinstance(request.requirements, (ToolDefaultLockfile, ToolCustomLockfile)):
lockfile_scope_name = request.requirements.options_scope_name
else:
lockfile_scope_name = None
lockfile_scope_name = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Bump on calling this resolve_name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed that change;fixing now

request.requirements.options_scope_name
if isinstance(request.requirements, (ToolDefaultLockfile, ToolCustomLockfile))
else None
)

if isinstance(request.requirements, Lockfile):
argv.extend(["--requirement", request.requirements.file_path])
Expand All @@ -500,8 +500,11 @@ async def build_pex_component(
)

requirements_file_digest_contents = await Get(DigestContents, PathGlobs, globs)

metadata = LockfileMetadata.from_lockfile(
requirements_file_digest_contents[0].content, lockfile_scope_name
requirements_file_digest_contents[0].content,
request.requirements.file_path,
lockfile_scope_name,
)
_validate_metadata(metadata, request, request.requirements, python_setup)

Expand All @@ -512,7 +515,9 @@ async def build_pex_component(
argv.extend(["--requirement", file_content.path])
argv.append("--no-transitive")

metadata = LockfileMetadata.from_lockfile(file_content.content, lockfile_scope_name)
metadata = LockfileMetadata.from_lockfile(
file_content.content, resolve_name=lockfile_scope_name
)
_validate_metadata(metadata, request, request.requirements, python_setup)

requirements_file_digest = await Get(Digest, CreateDigest([file_content]))
Expand Down