-
-
Notifications
You must be signed in to change notification settings - Fork 636
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
Add specific and actionable instructions to stale lockfile errors #12699
Add specific and actionable instructions to stale lockfile errors #12699
Conversation
# 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]
…r messages # 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]
[ci skip-rust] [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]
[ci skip-rust] [ci skip-build-wheels]
OK, the tests don't pass due to timing out. Those will need a rewrite; one moment |
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.
Thank you Chris
else: | ||
yield ( | ||
"To regenerate your lockfile based on your current configuration, run " | ||
"`./pants generate-lockfiles`. " |
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.
"`./pants generate-lockfiles`. " | |
"`./pants generate-lockfiles --resolve={tool_name}`. " |
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.
Bump
# 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]
# 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]
I think I've caught everything here. Let me know if you've got any questions. |
elif isinstance(requirements, ToolCustomLockfile): | ||
yield f"the lockfile at {requirements.file_path} " | ||
else: | ||
raise Exception("Check the type hinting on `requirements`") |
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.
type hints on requirements
say that this line should never be hit, but I'm not sure mypy agrees.
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.
Better is raise AssertionError
. And yeah this is good to keep. Although note that it will fail much earlier on line 619 due to AttributeError
if it isn't a _ToolLockfileMixin
.
Maybe you can assert that it's an instance of _ToolLockfileMixin
? It is totally valid to not support invalidation for non-tool lockfiles in Pants 2.7.
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.
Yeah, it will definitely fail earlier.
I didn't really want to expose _ToolLockfileMixin
, it's mostly there to ensure consistency of field names through DRY more than an implementation detail, we can change that if you think it helps.
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.
I think it's fine to keep it private w/ the underscore, but still import it here. I strongly suspect this code will change in Pants 2.8 when we add support for multiple user lockfiles - so it makes sense for the type to be an implementation detail.
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.
For what it's worth, my expectation is that we'll need a separate error message function to take care of user lockfiles
extra_requirements: Iterable[str] = (), | ||
uses_source_plugins: bool = False, |
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.
You can simplify things by chaing extra_requirements
to be requirements_from_source_plugins: Iterable[str] | None = None
. If requirements_from_source_plugins is None
, assume source plugins are not used.
Note that both MyPy and Pylint will pass an empty FrozenOrderedSet
, rather than None
, if no plugins are used:
pants/src/python/pants/backend/python/typecheck/mypy/subsystem.py
Lines 219 to 221 in cd24eba
@dataclass(frozen=True) | |
class MyPyFirstPartyPlugins: | |
requirement_strings: FrozenOrderedSet[str] |
pants/src/python/pants/backend/python/typecheck/mypy/subsystem.py
Lines 288 to 291 in cd24eba
return PythonLockfileRequest.from_tool( | |
mypy, constraints, extra_requirements=first_party_plugins.requirement_strings | |
) | |
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.
Firstly, that line is stale, and I'll be deleting it shortly. I'm not sure that relying on this parameter being set to determine overall tool behaviour is a good idea, because the impact to 3rd-party plugin developers of whether they use None
or a falsey iterator is pretty obscure at the moment. I've added a field at the class level, which is what we're actually using to implement the behaviour, which keeps things explicit.
@dataclass(frozen=True) | ||
class ToolProgrammaticLockfile(LockfileContent, _ToolLockfileMixin): | ||
pass |
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.
I don't think this makes sense to have without having call sites using this.
Instead, I think we simply don't support anything other than ToolCustomLockfile
and ToolDefaultLockfile
for now, as mentioned below.
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.
Fair
elif isinstance(requirements, ToolCustomLockfile): | ||
yield f"the lockfile at {requirements.file_path} " | ||
else: | ||
raise Exception("Check the type hinting on `requirements`") |
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.
Better is raise AssertionError
. And yeah this is good to keep. Although note that it will fail much earlier on line 619 due to AttributeError
if it isn't a _ToolLockfileMixin
.
Maybe you can assert that it's an instance of _ToolLockfileMixin
? It is totally valid to not support invalidation for non-tool lockfiles in Pants 2.7.
else: | ||
yield ( | ||
"To regenerate your lockfile based on your current configuration, run " | ||
"`./pants generate-lockfiles`. " |
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.
Bump
# 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]
elif isinstance(requirements, ToolCustomLockfile): | ||
yield f"the lockfile at {requirements.file_path} " | ||
else: | ||
raise Exception("Check the type hinting on `requirements`") | ||
assert isinstance(requirements, (ToolCustomLockfile, ToolDefaultLockfile)) |
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.
This needs to be moved higher up in the function. Once you do that, you can simply do if isinstance(requirements, ToolDefaultLockfile)
then else
(meaning ToolCustomLockfile
). MyPy should have "tightened" the types for you appropriately.
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.
Now that I've added an assertion, mypy
is complaining that it's unreachable. Much better!
deletes
else: | ||
message = "TODO: add support for user lockfiles" |
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.
This can be removed. The funciton only supports tool lockfiles, meaning that you can't hook up the invalidation check for anything else in Pants 2.7.
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.
I've replaced with a comment and a false assertion
# 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]
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.
Thanks Chris! Looks great
if (ir or ic) | ||
], | ||
) | ||
def test_validate_metadata( |
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.
You're right - this does make a already big file even bigger and more complex. And this will only get worse when we add multiple user lockfiles.
What do you think about this home being in lockfile_metadata.py
? Maybe it'd even make sense to rename to lockfile_invalidation.py
?
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.
Sounds like a good fix for the next round of changes :)
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.
Sgtm!
…ntsbuild#12699) This changes the lockfile staleness messages to include information on how to reconfigure pants to resolve the error. Language is largely similar to that proposed in pantsbuild#12654, with minor changes: * Language changes to explain the need for action on the user's part (_you can fix this by_ rather than _please change_ ) Closes pantsbuild#12654 # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust]
…errypick of #12699). (#12717) This changes the lockfile staleness messages to include information on how to reconfigure pants to resolve the error. Language is largely similar to that proposed in #12654, with minor changes: * Language changes to explain the need for action on the user's part (_you can fix this by_ rather than _please change_ ) Closes #12654 Cherry-picks `1cfe8dd`. [ci skip-rust]
This changes the lockfile staleness messages to include information on how to reconfigure pants to resolve the error. Language is largely similar to that proposed in #12654, with minor changes:
Closes #12654