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

Make url metadata parsing compatible with new PyPI URLs #17

Merged
merged 1 commit into from Apr 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions hashin.py
Expand Up @@ -173,8 +173,7 @@ def expand_python_version(version):
# This should match the naming convention laid out in PEP 0427
# url = 'https://pypi.python.org/packages/3.4/P/Pygments/Pygments-2.1-py3-none-any.whl'
CLASSIFY_WHEEL_RE = re.compile('''
^https://pypi.python.org/packages/[^/]+/[^/]/[^/]+/
(?P<package>.+)-
^(?P<package>.+)-
(?P<version>\d[^-]*)-
(?P<python_version>[^-]+)-
(?P<abi>[^-]+)-
Expand All @@ -185,8 +184,7 @@ def expand_python_version(version):
''', re.VERBOSE)

CLASSIFY_EGG_RE = re.compile('''
^https://pypi.python.org/packages/[^/]+/[^/]/[^/]+/
(?P<package>.+)-
^(?P<package>.+)-
(?P<version>\d[^-]*)-
(?P<python_version>[^-]+)
(-(?P<platform>[^\.]+))?
Expand All @@ -196,17 +194,15 @@ def expand_python_version(version):
''', re.VERBOSE)

CLASSIFY_ARCHIVE_RE = re.compile('''
^https://pypi.python.org/packages/[^/]+/[^/]/[^/]+/
(?P<package>.+)-
^(?P<package>.+)-
(?P<version>\d[^-]*)
.(?P<format>tar.(gz|bz2)|zip)
(\#md5=.*)?
$
''', re.VERBOSE)

CLASSIFY_EXE_RE = re.compile('''
^https://pypi.python.org/packages/[^/]+/[^/]/[^/]+/
(?P<package>.+)-
^(?P<package>.+)-
(?P<version>\d[^-]*)-
((?P<platform>[^-]*)-)?
(?P<python_version>[^-]+)
Expand All @@ -217,6 +213,7 @@ def expand_python_version(version):


def release_url_metadata(url):
filename = url.split('/')[-1]
defaults = {
'package': None,
'version': None,
Expand All @@ -227,12 +224,12 @@ def release_url_metadata(url):
}
simple_classifiers = [CLASSIFY_WHEEL_RE, CLASSIFY_EGG_RE, CLASSIFY_EXE_RE]
for classifier in simple_classifiers:
match = classifier.match(url)
match = classifier.match(filename)
if match:
defaults.update(match.groupdict())
return defaults

match = CLASSIFY_ARCHIVE_RE.match(url)
match = CLASSIFY_ARCHIVE_RE.match(filename)
if match:
defaults.update(match.groupdict())
defaults['python_version'] = 'source'
Expand Down
9 changes: 9 additions & 0 deletions tests.py
Expand Up @@ -414,6 +414,15 @@ def test_release_url_metadata_python(self):
'platform': 'amd64',
'format': 'exe',
})
url = 'https://pypi.python.org/packages/d5/0d/445186a82bbcc75166a507eff586df683c73641e7d6bb7424a44426dca71/Django-1.8.12-py2.py3-none-any.whl'
self.assertEqual(hashin.release_url_metadata(url), {
'package': 'Django',
'version': '1.8.12',
'python_version': 'py2.py3',
'abi': 'none',
'platform': 'any',
'format': 'whl',
})

def test_expand_python_version(self):
self.assertEqual(sorted(hashin.expand_python_version('2.7')),
Expand Down