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

Conversation

chrisjrn
Copy link
Contributor

@chrisjrn chrisjrn commented Sep 8, 2021

This adds a version field to lockfiles, starting at version 1, which will allow for simpler validation logic when we start updating the expected metadata in lockfile headers.

This also adds new error messages to LockfileMetadata.from_lockfile

Added per request by @Eric-Arellano in #12782.

Christopher Neugebauer added 3 commits September 8, 2021 12:57
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thank you for splitting this up!

@@ -38,40 +53,53 @@ def from_lockfile(cls, lockfile: bytes) -> LockfileMetadata:
elif in_metadata_block:
metadata_lines.append(line[2:])

error_suffix = "To resolve this error, you will need to regenerate the lockfile."
Copy link
Contributor

Choose a reason for hiding this comment

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

"by running ./pants generate-lockfiles"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I mention --resolve={tool_name}?

Copy link
Contributor

Choose a reason for hiding this comment

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

If possible, yes, that would be excellent! But I'm not sure how easy that will be to wire up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thankfully, as easy as it was to wire in the other request you requested.

if not metadata_lines:
# TODO(#12314): Add a good error.
raise InvalidLockfileError("")
raise InvalidLockfileError(
"Could not find a pants metadata block in this lockfile. " + error_suffix
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be really helpful to mention the problematic lockfile in all these error messages.

Could not find a Pants metadata block in the lockfile at

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be. Let me figure out what it would take to be able to plumb that value in.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@chrisjrn
Copy link
Contributor Author

chrisjrn commented Sep 8, 2021

@Eric-Arellano How does it look now?

@classmethod
def from_lockfile(cls, lockfile: bytes) -> LockfileMetadata:
def from_lockfile(
cls, lockfile: bytes, lockfile_scope_name: str | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

If my read is correct, you always have the lockfile_path available. Only for tool lockfiles do you have the resolve_name (what you call lockfile_scope_name). If you're up for it, the error message would be even better if you could say

Could not find a Pants metadata block in the lockfile {path} for the resolve {resolve_name}.

Or if resolve_name is None,

Could not find a Pants metadata block in the lockfile {path}.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also please call it resolve_name. This error applies to multiple user lockfiles too, and lockfile_scope_name is a misnomer there. The way to refer to this is 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.

Sure thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. Making that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like lockfile_path is only available for non-default lockfiles, so I've added lockfile_path but made it optional.

if lockfile_scope_name:
lockfile_description = f"the lockfile for `{lockfile_scope_name}`"
else:
"""this lockfile."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching the typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now a 4-level conditional, and it reads pretty poorly as a ternary expression, so I've kept it as an if statement for now. Let me know if this is a problem.

Comment on lines 486 to 490
lockfile_scope_name: str | None
if isinstance(request.requirements, (ToolDefaultLockfile, ToolCustomLockfile)):
lockfile_scope_name = request.requirements.options_scope_name
else:
lockfile_scope_name = None
Copy link
Contributor

Choose a reason for hiding this comment

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

As explained above, please call it resolve_name. Also generally prefer ternary expressions: https://www.pantsbuild.org/docs/style-guide#prefer-conditional-expressions-ternary-expressions

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

In the future, this will need to capture the resolve name for multiple user lockfiles. It's fine to punt on that, but can you please add something like:

# TODO(#12314): Capture the resolve name for multiple user lockfiles.

@@ -53,36 +42,46 @@ def from_lockfile(cls, lockfile: bytes) -> LockfileMetadata:
elif in_metadata_block:
metadata_lines.append(line[2:])

error_suffix = "To resolve this error, you will need to regenerate the lockfile."
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.

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
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

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Yay! Thanks :)

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Christopher Neugebauer added 2 commits September 8, 2021 15:56
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano merged commit 567ece2 into pantsbuild:main Sep 9, 2021
@Eric-Arellano
Copy link
Contributor

Thanks! Can you please cherry-pick to Pants 2.7?

@chrisjrn
Copy link
Contributor Author

chrisjrn commented Sep 9, 2021

@Eric-Arellano Sure thing; PR will be incoming shortly.

chrisjrn pushed a commit to chrisjrn/pants that referenced this pull request Sep 9, 2021
This adds a `version` field to lockfiles, starting at version 1, which will allow for simpler validation logic when we start updating the expected metadata in lockfile headers.

This also adds new error messages to `LockfileMetadata.from_lockfile`.
# Conflicts:
#	3rdparty/python/lockfiles/user_reqs.txt
#	src/python/pants/backend/python/lint/black/lockfile.txt
#	src/python/pants/backend/python/lint/isort/lockfile.txt
#	src/python/pants/backend/python/subsystems/lambdex_lockfile.txt

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
jsirois added a commit to jsirois/pants that referenced this pull request Sep 10, 2021
…uild#12778))

* Add python-docx to the module mapping dictionary ([pantsbuild#12775](pantsbuild#12775))

* Add python-pptx to the module mapping dictionary ([pantsbuild#12776](pantsbuild#12776))

* Add `opencv-python` to the default Python module mapping ([pantsbuild#12777](pantsbuild#12777))

* Add `PyMuPDF` to the default Python module mapping ([pantsbuild#12774](pantsbuild#12774))

* Deprecate `--list-provides` option. ([pantsbuild#12759](pantsbuild#12759))

* Upgrade default `isort` to latest `isort==5.9.3` ([pantsbuild#12756](pantsbuild#12756))

* `OutputPathField.value_or_default()` no longer has an `Address` argument ([pantsbuild#12837](pantsbuild#12837))

* Properly include file dependencies in docker build context ([pantsbuild#12758](pantsbuild#12758))

* DigestSubset should not short-circuit when there are ignores involved. ([pantsbuild#12648](pantsbuild#12648))

* Improve cache reuse for `./pants package` when using a constraints file or lockfile ([pantsbuild#12807](pantsbuild#12807))

* Upgrade to Pex 2.1.48 and leverage packed layout. ([pantsbuild#12808](pantsbuild#12808))

* Fix backports of std lib modules like `dataclasses` not working with dependency inference ([pantsbuild#12818](pantsbuild#12818))

* Warn if `[python-repos]` is set during lockfile generation ([pantsbuild#12800](pantsbuild#12800))

* Add `version` to lockfile metadata headers ([pantsbuild#12788](pantsbuild#12788))

* jvm: add missing space to avoid two words running together ([pantsbuild#12793](pantsbuild#12793))

* Fix a markdown issue in a help string. ([pantsbuild#12766](pantsbuild#12766))

[ci skip-rust]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants