Locator.get_project appears to only return a single URL

Issue #55 resolved
Paul Moore
created an issue

For example, setuptools 5.8 provides .whl, .tar.gz and .zip downloads. However:

>>> p = pypi.get_project('setuptools')
>>> p['5.8']
<Distribution setuptools (5.8) [https://pypi.python.org/packages/source/s/setuptools/setuptools-5.8.zip]>
>>> p['5.8'].download_url
'https://pypi.python.org/packages/source/s/setuptools/setuptools-5.8.zip'
>>> p['5.8'].source_url
'https://pypi.python.org/packages/source/s/setuptools/setuptools-5.8.zip'

Comments (5)

  1. Vinay Sajip

    I have a proposed fix in fc42324 - there are no API changes, but:

    1. A locate() call returns a Distribution instance, which now has two additional properties:
    • download_urls - a set of download URLs for that distribution's version.
    • digests - a dict mapping URLs in download_urls to (algo, digest) tuples, where digests are available.
    1. The dict returned by get_project() has two additional keys:
    • urls - a dict mapping versions to sets of download URLs.
    • digests - a dict mapping URLs to (algo, digest) tuples, where digests are available.

    This relies on locators to do the necessary work to populate these data structures, so people who have written their own locators may need to update their code to do that. I have addressed the built-in locators. Example session:

    >>> from distlib.locators import SimpleScrapingLocator
    >>> pypi = SimpleScrapingLocator('https://pypi.python.org/simple/', scheme='legacy')
    >>> dist = pypi.locate('setuptools==5.8')
    >>> from pprint import pprint
    >>> pprint(dist.download_urls)
    set([u'https://pypi.python.org/packages/3.4/s/setuptools/setuptools-5.8-py2.py3-none-any.whl',
         u'https://pypi.python.org/packages/source/s/setuptools/setuptools-5.8.tar.gz',
         u'https://pypi.python.org/packages/source/s/setuptools/setuptools-5.8.zip'])
    >>> pprint(dist.digests)
    {u'https://pypi.python.org/packages/3.4/s/setuptools/setuptools-5.8-py2.py3-none-any.whl': ('md5',
                                                                                                u'c7a5c93159c447954008acf254b8555a'),
     u'https://pypi.python.org/packages/source/s/setuptools/setuptools-5.8.tar.gz': ('md5',
                                                                                     u'356480fdf03590cfdf4210cf8366bcaf'),
     u'https://pypi.python.org/packages/source/s/setuptools/setuptools-5.8.zip': ('md5',
                                                                                  u'df27b76355e337bdbe904db6f4dfc339')}
    
    >>> d = pypi.get_project('sarge')
    >>> pprint(d['urls'])
    {u'0.1': set([u'https://pypi.python.org/packages/source/s/sarge/sarge-0.1.tar.gz']),
     u'0.1.1': set([u'https://pypi.python.org/packages/source/s/sarge/sarge-0.1.1.tar.gz']),
     u'0.1.2': set([u'https://pypi.python.org/packages/source/s/sarge/sarge-0.1.2.tar.gz']),
     u'0.1.3': set([u'https://pypi.python.org/packages/source/s/sarge/sarge-0.1.3.tar.gz'])}
    >>> pprint(d['digests'])
    {u'https://pypi.python.org/packages/source/s/sarge/sarge-0.1.1.tar.gz': ('md5',
                                                                             u'2a9b9d46e4ef6ae51e2a5ff7de93d9dd'),
     u'https://pypi.python.org/packages/source/s/sarge/sarge-0.1.2.tar.gz': ('md5',
                                                                             u'28c0f3183f75f9efd205573883a79e24'),
     u'https://pypi.python.org/packages/source/s/sarge/sarge-0.1.3.tar.gz': ('md5',
                                                                             u'5fa790cc26a97c66be735629b0e6671c'),
     u'https://pypi.python.org/packages/source/s/sarge/sarge-0.1.tar.gz': ('md5',
                                                                           u'961ddd9bc085fdd8b248c6dd96ceb1c8')}
    
  2. Log in to comment