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

Warn if [python-repos] is set during lockfile generation #12800

Merged
merged 3 commits into from
Sep 9, 2021
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
22 changes: 22 additions & 0 deletions src/python/pants/backend/python/goals/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from pants.engine.rules import Get, MultiGet, collect_rules, goal_rule, rule
from pants.engine.target import TransitiveTargets, TransitiveTargetsRequest, UnexpandedTargets
from pants.engine.unions import UnionMembership, union
from pants.python.python_repos import PythonRepos
from pants.python.python_setup import PythonSetup
from pants.util.logging import LogLevel
from pants.util.ordered_set import FrozenOrderedSet
Expand Down Expand Up @@ -327,7 +328,28 @@ async def generate_lockfiles_goal(
union_membership: UnionMembership,
generate_lockfiles_subsystem: GenerateLockfilesSubsystem,
python_setup: PythonSetup,
python_repos: PythonRepos,
) -> GenerateLockfilesGoal:
failure_instructions = (
"If lockfile generation fails, you can either disable lockfiles by setting "
"`[tool].lockfile = '<none>'`, e.g. setting `[black].lockfile`, or you can manually "
"generate lockfiles, e.g. by using pip-compile or `pip freeze`. If manually generating "
"lockfiles, you should set `[python-setup].invalid_lockfile_behavior = 'ignore'."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chrisjrn and I discussed that it could be possible to manually maintain a lockfile and set the Pants lockfile metadata yourself. But he intuited that is confusing / error-prone, and he suggested we simply don't use that mechanism if you're manually generating lockfiles. I now agree with him.

)
if python_repos.repos:
logger.warning(
"The option `[python-repos].repos` is configured, but it does not currently work with "
"lockfile generation because Pants is currently using Poetry for lockfile generation "
"and Poetry does not support `--find-links`. Lockfile generation may fail.\n\n"
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
f"{failure_instructions}"
)
if python_repos.indexes != [python_repos.pypi_index]:
logger.warning(
"The option `[python-repos].indexes` is configured, but is not currently wired up to "
"lockfile generation. Lockfile generation may fail.\n\n"
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
f"{failure_instructions}"
)

specified_user_resolves, specified_tool_sentinels = determine_resolves_to_generate(
python_setup.resolves_to_lockfiles.keys(),
union_membership[PythonToolLockfileSentinel],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ def register_options(cls, register):
"To use a custom lockfile, set this option to a file path relative to the "
f"build root, then run `./pants generate-lockfiles "
f"--resolve={cls.options_scope}`.\n\n"
""
"Lockfile generation currently does not wire up the `[python-repos]` options. "
"If lockfile generation fails, you can set this option to a manually "
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved
"generated lockfile path, such as using pip-compile or `pip freeze` to "
"generate the lockfile. When manually maintaining lockfiles, set "
"`[python-setup].invalid_lockfile_behavior = 'ignore'`."
),
)

Expand Down
4 changes: 3 additions & 1 deletion src/python/pants/python/python_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class PythonRepos(Subsystem):
"custom cheeseshops when resolving requirements."
)

pypi_index = "https://pypi.org/simple/"

@classmethod
def register_options(cls, register):
super().register_options(register)
Expand All @@ -30,7 +32,7 @@ def register_options(cls, register):
"--indexes",
advanced=True,
type=list,
default=["https://pypi.org/simple/"],
default=[cls.pypi_index],
help=(
"URLs of code repository indexes to look for requirements. If set to an empty "
"list, then Pex will use no indices (meaning it will not use PyPI). The values "
Expand Down