Skip to content

packages_distributions doesn’t work for some dist-info packages built outside Setuptools #330

Closed

Description

@flying-sheep

I assume that for those packages, something similar to the following will work to retrieve the top level packages/modules contained in a distribution

{
    f.parts[0] if len(f.parts) > 1 else f.with_suffix('').name
    for f in pkg.files if f.suffix == ".py"
}

Of course there’s a lot of edgecases

Activity

  1. FFY00 commented on Jul 12, 2021

    @FFY00
    Member

    Yeah, because we are looking for top_level.txt, which AFAIK is a setuptools-specific thing. As you point out, the logic you suggest is fragile, so we need a better mechanism. top_level.txt is not defined in any PEP I could find, it's only defined in eggs. I think we may want to propose this to be added as an optional part of the project metadata.

  2. FFY00 commented on Jul 12, 2021

    @FFY00
    Member

    FYI, the original discussion is in #131.

  3. jaraco commented on Aug 14, 2021

    @jaraco
    Member

    It works for me:

    ~ $ pip-run importlib_metadata requests -- -c "import importlib_metadata as md; print(md.packages_distributions()['requests'])"
    Collecting importlib_metadata
      Using cached importlib_metadata-4.6.4-py3-none-any.whl (17 kB)
    Collecting requests
      Using cached requests-2.26.0-py2.py3-none-any.whl (62 kB)
    Collecting zipp>=0.5
      Using cached zipp-3.5.0-py3-none-any.whl (5.7 kB)
    Collecting charset-normalizer~=2.0.0
      Using cached charset_normalizer-2.0.4-py3-none-any.whl (36 kB)
    Collecting idna<4,>=2.5
      Using cached idna-3.2-py3-none-any.whl (59 kB)
    Collecting certifi>=2017.4.17
      Using cached certifi-2021.5.30-py2.py3-none-any.whl (145 kB)
    Collecting urllib3<1.27,>=1.21.1
      Using cached urllib3-1.26.6-py2.py3-none-any.whl (138 kB)
    Installing collected packages: zipp, urllib3, idna, charset-normalizer, certifi, requests, importlib-metadata
    Successfully installed certifi-2021.5.30 charset-normalizer-2.0.4 idna-3.2 importlib-metadata-4.6.4 requests-2.26.0 urllib3-1.26.6 zipp-3.5.0
    ['requests']
    

    The title says "some dist-info packages". Can you provide maybe one example that doesn't work?

  4. FFY00 commented on Aug 14, 2021

    @FFY00
    Member

    Non-setuptools ones, see my comment above.

    $ pip-run importlib_metadata hidabc -- -c "import importlib_metadata as md; print(md.packages_distributions()['hidabc'])"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    KeyError: 'hidabc'
    
  5. changed the title [-]packages_distributions doesn’t work for some dist-info packages installed from wheels[/-] [+]packages_distributions doesn’t work for some dist-info packages built outside Setuptools[/+] on Aug 14, 2021
  6. jaraco commented on Aug 14, 2021

    @jaraco
    Member

    In #340, I've drafted a change that implements the proposed approach above as a fallback when top-level isn't available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions