Skip to content

Commit 1298af8

Browse files
committed
Resolve quoted names in requirements #143
Move the resolution to the from_filename() method in subclasses Reference: #143 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 37b37c4 commit 1298af8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/python_inspector/utils_pypi.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,6 @@ def from_filename(cls, filename):
701701
Return a distribution built from the data found in a `filename` string.
702702
Raise an exception if this is not a valid filename
703703
"""
704-
filename = unquote(os.path.basename(filename.strip("/")))
705704
clazz = cls.get_dist_class(filename)
706705
return clazz.from_filename(filename)
707706

@@ -950,6 +949,15 @@ def get_sdist_name_ver_ext(filename):
950949
return name, version, extension
951950

952951

952+
def get_filename(filename):
953+
"""
954+
Return a filename from a ``filename`` path or name string. Unquote as needed.
955+
"""
956+
filename = filename.strip("/")
957+
filename = os.path.basename(filename)
958+
return unquote(filename)
959+
960+
953961
@attr.attributes
954962
class Sdist(Distribution):
955963
extension = attr.ib(
@@ -965,6 +973,7 @@ def from_filename(cls, filename):
965973
Return a Sdist object built from a filename.
966974
Raise an exception if this is not a valid sdist filename
967975
"""
976+
filename = get_filename(filename)
968977
name_ver_ext = get_sdist_name_ver_ext(filename)
969978
if not name_ver_ext:
970979
raise InvalidDistributionFilename(filename)
@@ -1069,6 +1078,7 @@ def from_filename(cls, filename):
10691078
Return a wheel object built from a filename.
10701079
Raise an exception if this is not a valid wheel filename
10711080
"""
1081+
filename = get_filename(filename)
10721082
wheel_info = cls.get_wheel_from_filename(filename)
10731083
if not wheel_info:
10741084
raise InvalidDistributionFilename(filename)

0 commit comments

Comments
 (0)