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

Handle invalid requirement strings when using importlib.metadata #345

Merged
merged 3 commits into from
Apr 6, 2024

Conversation

kemzeb
Copy link
Collaborator

@kemzeb kemzeb commented Apr 5, 2024

Resolves #344.

This change also:

  • Makes Distribution.requires() into a generator for performance (i.e. avoid building list[Requirement] and then iterating list[Requirement and instead do both at the same time) and so that we can handle invalid requirement exceptions in PackageDAG.from_pkgs() for each individual requirement string
  • Modified conftest to avoid adding a extra comma at the end and removed some older code

Comment on lines +18 to +28
def render_invalid_reqs_text_if_necessary(dist_name_to_invalid_reqs_dict: dict[str, list[str]]) -> None:
if not dist_name_to_invalid_reqs_dict:
return

print("Warning!!! Invalid requirement strings found for the following distributions:", file=sys.stderr) # noqa: T201
for dist_name, invalid_reqs in dist_name_to_invalid_reqs_dict.items():
print(dist_name, file=sys.stderr) # noqa: T201

for invalid_req in invalid_reqs:
print(f' Skipping "{invalid_req}"', file=sys.stderr) # noqa: T201
print("-" * 72, file=sys.stderr) # noqa: T201
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel like we have been duplicating the print warning logic across quite a few areas of the codebase. I think we should ponder a better way of handling this in the future

src/pipdeptree/_models/dag.py Outdated Show resolved Hide resolved
@kemzeb
Copy link
Collaborator Author

kemzeb commented Apr 5, 2024

Here's an example of what it looks like:

$ pipdeptree
Warning!!! Invalid requirement strings found for the following distributions:
catalyst
  Skipping "scikit-image (<0.19.0>=0.16.1) ; extra == 'all'"
------------------------------------------------------------------------
catalyst==22.4
├── accelerate [required: >=0.5.1, installed: 0.29.1]
│   ├── huggingface-hub [required: Any, installed: 0.22.2]
│   │   ├── filelock [required: Any, installed: 3.13.3]
. . .

@gaborbernat gaborbernat merged commit 7a6e0ff into tox-dev:main Apr 6, 2024
10 checks passed
@kemzeb kemzeb deleted the handle-invalid-requirements branch April 8, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error with a certain version constraint format
2 participants