pipdeptree icon indicating copy to clipboard operation
pipdeptree copied to clipboard

[pip 22.1] 'PathDistribution' object has no attribute 'project_name'

Open imba-tjd opened this issue 2 years ago • 16 comments

> pipdeptree.exe
Ignoring invalid distribution ~iztracer (C:\Users\imbat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages)
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "c:\users\imbat\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\scripts\pipdeptree.exe\__main__.py", line 7, in <module>
  File "C:\Users\imbat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pipdeptree.py", line 878, in main
    tree = PackageDAG.from_pkgs(pkgs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\imbat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pipdeptree.py", line 290, in from_pkgs
    pkgs = [DistPackage(p) for p in pkgs]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\imbat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pipdeptree.py", line 290, in <listcomp>
    pkgs = [DistPackage(p) for p in pkgs]
            ^^^^^^^^^^^^^^
  File "C:\Users\imbat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pipdeptree.py", line 149, in __init__
    super(DistPackage, self).__init__(obj)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\imbat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pipdeptree.py", line 109, in __init__
    self.project_name = obj.project_name
                        ^^^^^^^^^^^^^^^^
AttributeError: 'PathDistribution' object has no attribute 'project_name'

imba-tjd avatar May 14 '22 07:05 imba-tjd

I have figured it out. It's a pip issue. The change was made in https://github.com/pypa/pip/pull/11044, between 22.1b and 22.1

For now. If anyone wants to use pipdeptree, set _PIP_USE_IMPORTLIB_METADATA=0

imba-tjd avatar Jun 03 '22 00:06 imba-tjd

Yep, same problem on 3.11. Sadly it does not seem to be well maintained.

ssbarnea avatar Jul 14 '22 15:07 ssbarnea

Thanks. Unfortunately I have been caught up with other things and don't have time to work on pipdeptree in the immediate future. I'll try to find time by the end of this month.

Good that _PIP_USE_IMPORTLIB_METADATA=0 can be used as a work around in the meanwhile.

naiquevin avatar Jul 18 '22 05:07 naiquevin

trying to patch uglily first two errors line 109 & 110 :

    def __init__(self, obj):
        self._obj = obj
        self.project_name = obj.name #  obj.project_name
        self.key = obj.name.replace('-', '_').lower() # obj.key

I fall on line 293, and can't find out this one

pipdeptree -r -p wheel
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\python-3.11.0b5.amd64\Scripts\pipdeptree.exe\__main__.py", line 7, in <module>
  File "D:\python-3.11.0b5.amd64\Lib\site-packages\pipdeptree.py", line 878, in main
    tree = PackageDAG.from_pkgs(pkgs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.0b5.amd64\Lib\site-packages\pipdeptree.py", line 292, in from_pkgs
    m = {p: [ReqPackage(r, idx.get(r.key))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python-3.11.0b5.amd64\Lib\site-packages\pipdeptree.py", line 293, in <dictcomp>
    for r in p.requires()]
             ^^^^^^^^^^^^
TypeError: 'NoneType' object is not callable

stonebig avatar Jul 31 '22 10:07 stonebig

@naiquevin it is perfectly ok to be busy, but if you really care about pipdeptree, just move it under an org and give others access to fix and maintain it.

ssbarnea avatar Aug 07 '22 19:08 ssbarnea

@ssbarnea I have opened an issue in the pip repo to check if they would be interested in adopting pipdeptree by moving the code inside pip itself. IMO that would be better in the long run rather than maintaining the project externally. - https://github.com/pypa/pip/issues/11360

However, I can see that there's a huge backlog of issues on pip, so expect this to take time. If they are not interested, I'll move it under an org as you suggested.

In the meanwhile I am assuming that any one can fork the project, merge open PRs on any of the public forks, and install pipdeptree into their env from their own fork on github or any other origin for that matter. I am curious about what stops people from doing this? Isn't that the whole point of git?

I don't mean any offense here, please don't get me wrong. As the owner of the pipdeptree on github and pypi.org, I know that it's my responsibility to care about it and ensure timely releases. But due to pipdeptree's dependence on pip's internals, a "stable" version can suddenly become unstable when a new version of pip is released. It's usually not possible for me to drop whatever I am doing and fix it. If there are any PRs I believe I have a greater responsibility to avoid any regression by doing end-to-end test myself before merging them. So it could take some time for PRs to get merged.

Again, no offense meant. But recently I've noticed comments on my projects that imply it's my responsibility to not just maintain the project, but also unblock them on high priority. Not saying you meant that too but I did feel a mild nudge given my recent experience on github in general (not just this project).

naiquevin avatar Aug 08 '22 05:08 naiquevin

pypa org will not accept projects without active maintainers, as they do not want to become a junkyard. You can still move it to pycontribs or if you want, keeping the ownership.

I am one of the maintainers or pip-tools and we are still not moved to pypa, but looking to in the future.

As pip recently got the inspect feature, i was wondering if it would not be better to reimplement pipdeptree inside pip-tools, especially as we already have two tools in it.

Yep, keeping up with packaging changes is a challenge.

ssbarnea avatar Aug 08 '22 07:08 ssbarnea

@ssbarnea maybe you can propose a patch ? pip may be more inclined to integrate pipdeptree if the current issue is fixed.

stonebig avatar Aug 08 '22 09:08 stonebig

I think that pip team is very careful to minimize the amount of baggage the tool adopts, so unlikely to implement it. We should at least ask, maybe I am wrong.

ssbarnea avatar Aug 08 '22 09:08 ssbarnea

When trying to build an updated set of packages, I'm truly lost without pipdeptree to navigate dependancies.

stonebig avatar Aug 08 '22 10:08 stonebig

the suggested solution "pip pinspect" per pipa team sounds like a good splitting of duties

stonebig avatar Aug 08 '22 12:08 stonebig

@ssbarnea Looks like the pip team is reluctant about the proposal, as you had predicted.

As pip recently got the inspect feature, i was wondering if it would not be better to reimplement pipdeptree inside pip-tools, especially as we already have two tools in it.

I was not aware of pip inspect. If the json interface is indeed stable, I don't see why it can't be used to build a tool like pipdeptree.

Please feel free to reimplement it in pip-tools. Let me know once your version reaches stable state, I would happily archive this project and link it to yours.

naiquevin avatar Aug 08 '22 12:08 naiquevin

@stonebig Thanks for your kind words and support 👍

naiquevin avatar Aug 08 '22 12:08 naiquevin

pipdeptree helped me a lot since the troubled times of figuring out why pip "solver" was doing this or that. I'm not expert in Json, but I feel it's on my reach to survive pipdeptree with 'pip inspect' ... ... but as it may be take time, I'll do "set _PIP_USE_IMPORTLIB_METADATA=0" for now https://github.com/winpython/winpython/issues/1100#issuecomment-1208219443

thanks for having done pipdeptree and maintained it till january 2021

stonebig avatar Aug 08 '22 14:08 stonebig

from 'pip inspect' it's a bit tiedous to replace ' and extra == 'test'' or ' extra == 'test'' per a qualified requirement_branch 'test'...

stonebig avatar Aug 10 '22 13:08 stonebig

ok,

I failed to patch pipdeptree ("def from_pkgs") , which would have been simpler, but is over my debugging capability.

but with 'pip inspect', and 200 lines of 'proof of concept' code, i can do an acceptable ersatz for my use.

I hope it will inspire pip team to do the extra-mile of implementing the 4 basic features I whish

  • pipdeptree -p pandas
  • pipdeptree -r datashader
  • and bonus:
    • pipdeptree -p pandas['test']
    • pipdeptree -r -p datashader['doc'] # could be considered controversial

Proof-of-Concept code in the Notebook there: https://github.com/winpython/winpython_afterdoc/blob/master/docs/pipdeptree_replacement.ipynb

image

stonebig avatar Aug 11 '22 14:08 stonebig

@naiquevin I'd be interested in taking over this proejct as maintainer, I've contributed via https://github.com/naiquevin/pipdeptree/pull/128 and as https://bernat.tech/about/ I'm PyPA member and fairly active.

gaborbernat avatar Aug 31 '22 23:08 gaborbernat

I can vet for @gaborbernat, in case others do not know he is also happens to be tox maintainer.

I will also try to give him a hand as I am using pipdeptree in order to document project dependencies (sphinx build).

My initial hopes were to get this feature reimplemented in pip-tools, but I do not care as long we can find a way to keep the functionality alive (in a maintained project).

ssbarnea avatar Sep 01 '22 07:09 ssbarnea

Thanks @gaborbernat and @ssbarnea. Let me create an org pipdeptree-dev, move this repo under it and grant you two permissions to push and merge PRs.

Please give me time until this weekend though to read up about what it means to "move" a repo on github (I have some questions such as - what happens to open PRs? Will the existing forks continue to work? etc.).

I'll can also add maintainers on pypi for publishing new versions.

naiquevin avatar Sep 01 '22 08:09 naiquevin

@naiquevin movements do retain all data and add redirects (even if done multiple times on same repo), only repository secrets are lost (security measure). Yep forks work, open prs, everything. GH team did a great job at this. Even GH api does continue to work with old URLs.

You also retain your full rights on repo move but other people with access are not transferred, so you need to add others after.

I do not have create rights on pypa and it was not clear if @gaborbernat wants it there but I do own https://github.com/pycontribs and I can give you rights there, so you would not need to create a new organization (i already have too many on my account). Later we can move it to pypa one.

ssbarnea avatar Sep 01 '22 09:09 ssbarnea

I personally would keep it under the tox-dev org I also have access to. A new org seems a bit too much 😅 for a single project.

gaborbernat avatar Sep 01 '22 14:09 gaborbernat

@gaborbernat Sure. Give him rights to create repo under tox-dev org and he should be able to make the transfer.

ssbarnea avatar Sep 01 '22 14:09 ssbarnea

I think it would be easier to make me the owner of this repository and then I can do the transfer and add both of you on there as admins 👌

gaborbernat avatar Sep 01 '22 14:09 gaborbernat

@gaborbernat he cannot do that with repos under personal accounts. But we could transfer it to you and allow you to do the move. It is known issue repos under personal repos.

ssbarnea avatar Sep 01 '22 14:09 ssbarnea

I don't mind transfering the repo to an existing org as long as the org is ok with it (based on the thread I had started on pip repo, pypa is not)

@gaborbernat I think you will need to temporarily grant me permission to create a new repo in the tox-dev org.

From here - https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository

To transfer a repository that you own to an organization, you must have permission to create a repository in the target organization.

naiquevin avatar Sep 03 '22 06:09 naiquevin

Sent you the invitation.

gaborbernat avatar Sep 03 '22 06:09 gaborbernat

Accepted. Let me see if I can transfer now.

naiquevin avatar Sep 03 '22 06:09 naiquevin

@gaborbernat @ssbarnea Done!

Let me know if there are any more steps I need to take.

naiquevin avatar Sep 03 '22 06:09 naiquevin

All good if you can give us pypi publish rights that would be great.

gaborbernat avatar Sep 03 '22 06:09 gaborbernat

Yeah, I'll do that.

naiquevin avatar Sep 03 '22 06:09 naiquevin