Skip to content

Commit

Permalink
doc: Minor UI fixes for the new lock strategy arguments (#2329)
Browse files Browse the repository at this point in the history
* fix: improve lock strategy group name and argument help text.

* fix: improve PdmUsageError message when supplying invalid strategy flag.

Before/after:

    $ pdm run pdm lock -S someflag
    [PdmUsageError]: Invalid strategy flag: someflag, supported: frozenset({'static_urls', 'cross_platform', 'direct_minimal_versions'})
    $ pdm run pdm lock -S someflag
    [PdmUsageError]: Invalid strategy flag: someflag, supported: static_urls, direct_minimal_versions, cross_platform
  • Loading branch information
whitequark authored Oct 24, 2023
1 parent 8799761 commit 2c104aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/pdm/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def no_isolation_option(project: Project, namespace: argparse.Namespace, values:

install_group.options.append(no_isolation_option)

groups_group = ArgumentGroup("Dependencies selection")
groups_group = ArgumentGroup("Dependencies Selection")
groups_group.add_argument(
"-G",
"--group",
Expand Down Expand Up @@ -365,15 +365,15 @@ def ignore_python_option(project: Project, namespace: argparse.Namespace, values
)


lock_strategy_group = ArgumentGroup("lock_strategy")
lock_strategy_group = ArgumentGroup("Lock Strategy")
lock_strategy_group.add_argument(
"--strategy",
"-S",
dest="strategy_change",
metavar="STRATEGY",
action=split_lists(","),
help="Specify lock strategy(cross_platform,static_urls,direct_minimal_versions). Add 'no_' prefix to disable."
" Support given multiple times or split by comma.",
help="Specify lock strategy (cross_platform, static_urls, direct_minimal_versions). Add 'no_' prefix to disable."
" Can be supplied multiple times or split by comma.",
)
lock_strategy_group.add_argument(
"--no-cross-platform",
Expand Down
4 changes: 2 additions & 2 deletions src/pdm/project/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def apply_strategy_change(self, changes: Iterable[str]) -> set[str]:
change = change.replace("-", "_").lower()
if change.startswith("no_"):
if change[3:] not in SUPPORTED_FLAGS:
raise PdmUsageError(f"Invalid strategy flag: {change[3:]}, supported: {SUPPORTED_FLAGS}")
raise PdmUsageError(f"Invalid strategy flag: {change[3:]}, supported: {', '.join(SUPPORTED_FLAGS)}")
original.discard(change[3:])
else:
if change not in SUPPORTED_FLAGS:
raise PdmUsageError(f"Invalid strategy flag: {change}, supported: {SUPPORTED_FLAGS}")
raise PdmUsageError(f"Invalid strategy flag: {change}, supported: {', '.join(SUPPORTED_FLAGS)}")
original.add(change)
return original

Expand Down

0 comments on commit 2c104aa

Please sign in to comment.