Skip to content

Commit

Permalink
feat: --quiet optiona and package warning (#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored Oct 9, 2023
1 parent ab37c5b commit 03329f1
Show file tree
Hide file tree
Showing 24 changed files with 253 additions and 66 deletions.
25 changes: 25 additions & 0 deletions docs/docs/usage/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,28 @@ lock = ["--no-cross-platform"]

These options will be added right after the command name. For instance, based on the configuration above,
`pdm add requests` is equivalent to `pdm add --no-isolation --no-self requests`.


## Ignore package warnings

_New in version 2.10.0_

You may see some warnings when resolving dependencies like this:

```
PackageWarning: Skipping [email protected] because it requires Python
<3.12,>=3.8 but the project claims to work with Python>=3.9.
Narrow down the `requires-python` range to include this version. For example, ">=3.9,<3.12" should work.
warnings.warn(record.message, PackageWarning, stacklevel=1)
Use `-q/--quiet` to suppress these warnings, or ignore them per-package with `ignore_package_warnings` config in [tool.pdm] table.
```

This is because the supported range of Python versions of the package doesn't cover the `requires-python` value specified in the `pyproject.toml`.
You can ignore these warnings in a per-package basis by adding the following config:

```toml
[tool.pdm]
ignore_package_warnings = ["scipy", "tensorflow-*"]
```

Where each item is a case-insensitive glob pattern to match the package name.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions news/2304.feature.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `-q/--quiet` option to suppress some warnings printed to the console. This option is mutually exclusive with `-v/--verbose`.
1 change: 1 addition & 0 deletions news/2304.feature.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show warnings when a package is rejected by the resolve because of uncovered `requires-python` range. And provide a way to ignore them per-package.
24 changes: 14 additions & 10 deletions src/pdm/cli/commands/show.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

import argparse
from typing import TYPE_CHECKING

from packaging.version import Version

Expand All @@ -11,10 +14,13 @@
from pdm.project import Project
from pdm.utils import normalize_name

if TYPE_CHECKING:
from unearth import Package


def filter_stable(candidate: Candidate) -> bool:
assert candidate.version
return not Version(candidate.version).is_prerelease
def filter_stable(package: Package) -> bool:
assert package.version
return not Version(package.version).is_prerelease


class Command(BaseCommand):
Expand All @@ -36,19 +42,17 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
def handle(self, project: Project, options: argparse.Namespace) -> None:
package = options.package
if package:
req = parse_requirement(package)
repository = project.get_repository()
# reverse the result so that latest is at first.
matches = repository.find_candidates(req, True, True)
latest = next(iter(matches), None)
if not latest:
with project.environment.get_finder() as finder:
best_match = finder.find_best_match(package, allow_prereleases=True)
if not best_match.applicable:
project.core.ui.echo(
f"No match found for the package {package!r}",
err=True,
style="warning",
)
return
latest_stable = next(filter(filter_stable, matches), None)
latest = Candidate.from_installation_candidate(best_match.best, parse_requirement(package))
latest_stable = next(filter(filter_stable, best_match.applicable), None)
metadata = latest.prepare(project.environment).metadata
else:
if not project.name:
Expand Down
46 changes: 23 additions & 23 deletions src/pdm/cli/completions/pdm.bash
Original file line number Diff line number Diff line change
Expand Up @@ -24,100 +24,100 @@ _pdm_a919b69078acdf0a_complete()

# completing for an option
if [[ ${cur} == --* ]] ; then
opts="--config --help --ignore-python --pep582 --verbose --version"
opts="--config --help --ignore-python --pep582 --quiet --verbose --version"

case "$com" in

(add)
opts="--dev --dry-run --editable --fail-fast --global --group --help --lockfile --no-editable --no-isolation --no-lock --no-self --no-sync --prerelease --project --save-compatible --save-exact --save-minimum --save-wildcard --skip --unconstrained --update-all --update-eager --update-reuse --venv --verbose"
opts="--dev --dry-run --editable --fail-fast --global --group --help --lockfile --no-editable --no-isolation --no-lock --no-self --no-sync --prerelease --project --quiet --save-compatible --save-exact --save-minimum --save-wildcard --skip --unconstrained --update-all --update-eager --update-reuse --venv --verbose"
;;

(build)
opts="--config-setting --dest --help --no-clean --no-isolation --no-sdist --no-wheel --project --skip --verbose"
opts="--config-setting --dest --help --no-clean --no-isolation --no-sdist --no-wheel --project --quiet --skip --verbose"
;;

(cache)
opts="--help --verbose"
opts="--help --quiet --verbose"
;;

(completion)
opts="--help"
;;

(config)
opts="--delete --edit --global --help --local --project --verbose"
opts="--delete --edit --global --help --local --project --quiet --verbose"
;;

(export)
opts="--dev --expandvars --format --global --group --help --lockfile --no-default --output --production --project --pyproject --verbose --without-hashes"
opts="--dev --expandvars --format --global --group --help --lockfile --no-default --output --production --project --pyproject --quiet --verbose --without-hashes"
;;

(fix)
opts="--dry-run --global --help --project --verbose"
opts="--dry-run --global --help --project --quiet --verbose"
;;

(import)
opts="--dev --format --global --group --help --project --verbose"
opts="--dev --format --global --group --help --project --quiet --verbose"
;;

(info)
opts="--env --global --help --json --packages --project --python --venv --verbose --where"
opts="--env --global --help --json --packages --project --python --quiet --venv --verbose --where"
;;

(init)
opts="--backend --cookiecutter --copier --global --help --lib --non-interactive --overwrite --project --python --skip --verbose"
opts="--backend --cookiecutter --copier --global --help --lib --non-interactive --overwrite --project --python --quiet --skip --verbose"
;;

(install)
opts="--check --dev --dry-run --fail-fast --global --group --help --lockfile --no-default --no-editable --no-isolation --no-lock --no-self --plugins --production --project --skip --venv --verbose"
opts="--check --dev --dry-run --fail-fast --global --group --help --lockfile --no-default --no-editable --no-isolation --no-lock --no-self --plugins --production --project --quiet --skip --venv --verbose"
;;

(list)
opts="--csv --exclude --fields --freeze --global --graph --help --include --json --markdown --project --resolve --reverse --sort --venv --verbose"
opts="--csv --exclude --fields --freeze --global --graph --help --include --json --markdown --project --quiet --resolve --reverse --sort --venv --verbose"
;;

(lock)
opts="--check --dev --global --group --help --lockfile --no-cross-platform --no-default --no-isolation --no-static-urls --production --project --refresh --skip --static-urls --verbose"
opts="--check --dev --global --group --help --lockfile --no-cross-platform --no-default --no-isolation --no-static-urls --production --project --quiet --refresh --skip --static-urls --verbose"
;;

(plugin)
opts="--help --verbose"
opts="--help --quiet --verbose"
;;

(publish)
opts="--ca-certs --comment --help --identity --no-build --no-very-ssl --password --project --repository --sign --skip --username --verbose"
opts="--ca-certs --comment --help --identity --no-build --no-very-ssl --password --project --quiet --repository --sign --skip --username --verbose"
;;

(remove)
opts="--dev --dry-run --fail-fast --global --group --help --lockfile --no-editable --no-isolation --no-lock --no-self --no-sync --project --skip --venv --verbose"
opts="--dev --dry-run --fail-fast --global --group --help --lockfile --no-editable --no-isolation --no-lock --no-self --no-sync --project --quiet --skip --venv --verbose"
;;

(run)
opts="--global --help --json --list --project --site-packages --skip --venv --verbose"
opts="--global --help --json --list --project --quiet --site-packages --skip --venv --verbose"
;;

(search)
opts="--help --verbose"
opts="--help --quiet --verbose"
;;

(self)
opts="--help --verbose"
opts="--help --quiet --verbose"
;;

(show)
opts="--global --help --keywords --license --name --platform --project --summary --venv --verbose --version"
opts="--global --help --keywords --license --name --platform --project --quiet --summary --venv --verbose --version"
;;

(sync)
opts="--clean --dev --dry-run --fail-fast --global --group --help --lockfile --no-default --no-editable --no-isolation --no-self --only-keep --production --project --reinstall --skip --venv --verbose"
opts="--clean --dev --dry-run --fail-fast --global --group --help --lockfile --no-default --no-editable --no-isolation --no-self --only-keep --production --project --quiet --reinstall --skip --venv --verbose"
;;

(update)
opts="--dev --fail-fast --global --group --help --lockfile --no-default --no-editable --no-isolation --no-lock --no-self --no-sync --outdated --prerelease --production --project --save-compatible --save-exact --save-minimum --save-wildcard --skip --top --unconstrained --update-all --update-eager --update-reuse --venv --verbose"
opts="--dev --fail-fast --global --group --help --lockfile --no-default --no-editable --no-isolation --no-lock --no-self --no-sync --outdated --prerelease --production --project --quiet --save-compatible --save-exact --save-minimum --save-wildcard --skip --top --unconstrained --update-all --update-eager --update-reuse --venv --verbose"
;;

(use)
opts="--first --global --help --ignore-remembered --project --skip --venv --verbose"
opts="--first --global --help --ignore-remembered --project --quiet --skip --venv --verbose"
;;

(venv)
Expand Down
Loading

0 comments on commit 03329f1

Please sign in to comment.