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 duplicated package metadata when using importlib.metadata #342

Merged
merged 6 commits into from
Apr 4, 2024

Conversation

kemzeb
Copy link
Collaborator

@kemzeb kemzeb commented Apr 4, 2024

Fixes #341.

Using an environment similar to the one shown in the issue:

$ PYTHONPATH=/workspaces/pipdeptree/temp-site-pkgs/ pipdeptree -a -d 0
Warning!!! Duplicate package metadata found:
"/home/vscode/.local/lib/python3.9/site-packages"
  pluggy                           1.4.0            (using 1.4.0, "/workspaces/pipdeptree/temp-site-pkgs")
  packaging                        24.0             (using 24.0, "/workspaces/pipdeptree/temp-site-pkgs")
  tomli                            2.0.1            (using 2.0.1, "/workspaces/pipdeptree/temp-site-pkgs")
  pytest                           8.1.1            (using 8.1.1, "/workspaces/pipdeptree/temp-site-pkgs")
  exceptiongroup                   1.2.0            (using 1.2.0, "/workspaces/pipdeptree/temp-site-pkgs")
  iniconfig                        2.0.0            (using 2.0.0, "/workspaces/pipdeptree/temp-site-pkgs")
"/usr/local/lib/python3.9/site-packages"
  pip                              23.0.1           (using 24.0, "/home/vscode/.local/lib/python3.9/site-packages")
------------------------------------------------------------------------
chardet==5.2.0
covdefaults==2.3.0
coverage==7.4.4
diff_cover==8.0.3
distlib==0.3.8
exceptiongroup==1.2.0
filelock==3.13.3
gitdb==4.0.11
GitPython==3.1.41
iniconfig==2.0.0
Jinja2==3.1.3
MarkupSafe==2.1.5
packaging==24.0
pip==24.0
pipdeptree==2.16.3.dev3+g91d21e3.d20240403
platformdirs==4.2.0
pluggy==1.4.0
Pygments==2.17.2
pytest==8.1.1
pytest-cov==5.0.0
pytest-mock==3.14.0
setuptools==69.0.3
smmap==5.0.1
tomli==2.0.1
virtualenv==20.25.1
wheel==0.42.0

@kemzeb
Copy link
Collaborator Author

kemzeb commented Apr 4, 2024

Make it a draft for now so that I can write a test or two and see if I can refactor the code at all 👍👍

src/pipdeptree/_discovery.py Outdated Show resolved Hide resolved
src/pipdeptree/_util.py Outdated Show resolved Hide resolved
tests/test_discovery.py Outdated Show resolved Hide resolved
@kemzeb kemzeb marked this pull request as ready for review April 4, 2024 16:37
tests/test_discovery.py Outdated Show resolved Hide resolved
@kemzeb
Copy link
Collaborator Author

kemzeb commented Apr 4, 2024

One other thing I should mention, I think users who have an older pip installed on their system may get the duplicate metadata warning message as when they install pipdeptree they will also most likely install the latest pip version (and since the former pip is installed on the system it most likely won't be removed). Here's an example:

$ pipdeptree
Warning!!! Duplicate package metadata found:
"/usr/local/lib/python3.8/site-packages"
  pip                              23.0.1           (using 24.0, "/home/vscode/.local/lib/python3.8/site-packages")
------------------------------------------------------------------------
covdefaults==2.3.0
└── coverage [required: >=6.0.2, installed: 7.4.4]
diff_cover==8.0.3
├── chardet [required: >=3.0.0, installed: 5.2.0]
├── Jinja2 [required: >=2.7.1, installed: 3.1.3]
. . .

Should we accept this, or should we handle this special case in some way?

Edit: Now that I think about it, this will only happen if they are using a version of pip<23.1.2 (where pip install will just use the system-provided pip if it is >=23.1.2) so I don't think we need to handle this.

@kemzeb
Copy link
Collaborator Author

kemzeb commented Apr 4, 2024

Gonna merge this and cut a 2.17.0 release!

@kemzeb kemzeb enabled auto-merge (squash) April 4, 2024 17:35
@gaborbernat gaborbernat merged commit ff31dc4 into tox-dev:main Apr 4, 2024
10 checks passed
@kemzeb
Copy link
Collaborator Author

kemzeb commented Apr 4, 2024

Thanks re-running the workflow (not sure why coverage for _discovery.py was failing when it passed previously). Seeing that there are no further issues I'll cut a new release 👍

@kemzeb kemzeb deleted the handle-duplicated-metadata branch April 4, 2024 17:48
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.

duplicate packages when using importlib.metadata
3 participants