Skip to content

Commit

Permalink
provide a more friendly pointer on unconfigured constraint file (#20781)
Browse files Browse the repository at this point in the history
Or more formally, a mismatch between the lockfile metadata saying there
should be constraints when none is configured. Previously this showed up
as a bare:

```
Engine traceback:
  in `package` goal

AssertionError:
```
  • Loading branch information
cburroughs authored Apr 17, 2024
1 parent 76bcd4e commit d2a9a46
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/python/pants/backend/python/util_rules/pex_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,22 @@ def _common_failure_reasons(
failure_reasons: set[InvalidPythonLockfileReason], maybe_constraints_file_path: str | None
) -> Iterator[str]:
if InvalidPythonLockfileReason.CONSTRAINTS_FILE_MISMATCH in failure_reasons:
assert maybe_constraints_file_path is not None
yield softwrap(
f"""
- The constraints file at {maybe_constraints_file_path} has changed from when the
lockfile was generated. (Constraints files are set via the option
`[python].resolves_to_constraints_file`)
"""
)
if maybe_constraints_file_path is None:
yield softwrap(
"""
- Constraint file expected from lockfile metadata but no
constraints file configured. See the option
`[python].resolves_to_constraints_file`.
"""
)
else:
yield softwrap(
f"""
- The constraints file at {maybe_constraints_file_path} has changed from when the
lockfile was generated. (Constraints files are set via the option
`[python].resolves_to_constraints_file`)
"""
)
if InvalidPythonLockfileReason.ONLY_BINARY_MISMATCH in failure_reasons:
yield softwrap(
"""
Expand Down Expand Up @@ -652,7 +660,10 @@ def _invalid_lockfile_error(
yield f"\n\nSee {doc_url('docs/python/overview/interpreter-compatibility')} for details."

yield "\n\n"
yield from _common_failure_reasons(validation.failure_reasons, maybe_constraints_file_path)
yield from (
f"{fail}\n"
for fail in _common_failure_reasons(validation.failure_reasons, maybe_constraints_file_path)
)
yield "To regenerate your lockfile, "
yield f"run `{bin_name()} generate-lockfiles --resolve={resolve}`."
yield f"\n\nSee {doc_url('docs/python/overview/third-party-dependencies')} for details.\n\n"
Expand Down

0 comments on commit d2a9a46

Please sign in to comment.