Skip to content

Commit

Permalink
Don't crash on invalid wheel names
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jun 3, 2018
1 parent 3db2fe9 commit 3648288
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions dumb_pypi/main.py
Expand Up @@ -11,10 +11,10 @@
import tempfile
from datetime import datetime

import distlib.wheel
import jinja2
import packaging.utils
import packaging.version
from distlib.wheel import Wheel


jinja_env = jinja2.Environment(
Expand All @@ -32,8 +32,12 @@ def remove_extension(name):

def guess_name_version_from_filename(filename):
if filename.endswith('.whl'):
wheel = Wheel(filename)
return wheel.name, wheel.version
try:
wheel = distlib.wheel.Wheel(filename)
except distlib.DistlibException:
raise ValueError(f'Invalid package name: {filename}')
else:
return wheel.name, wheel.version
else:
# These don't have a well-defined format like wheels do, so they are
# sort of "best effort", with lots of tests to back them up.
Expand Down
1 change: 1 addition & 0 deletions tests/main_test.py
Expand Up @@ -58,6 +58,7 @@ def test_guess_name_version_from_filename_only_name(filename, name, version):
'lol',
'lol-sup',
'-20160920.193125.zip',
'playlyfe-0.1.1-2.7.6-none-any.whl', # 2.7.6 is not a valid python tag
))
def test_guess_name_version_from_filename_invalid(filename):
with pytest.raises(ValueError):
Expand Down

0 comments on commit 3648288

Please sign in to comment.