aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/package_index.py
diff options
context:
space:
mode:
authorSteve Kowalik <steven@wedontsleep.org>2016-09-13 10:54:45 +1200
committerSteve Kowalik <steven@wedontsleep.org>2016-09-13 10:54:45 +1200
commit1f23f9a25e6c91554954185e84497056062093be (patch)
tree9660c20ee817c2cd4e4872492194591282517d12 /setuptools/package_index.py
parent2388233e4106937064bf1cdb087e7e1cfc5c7ea7 (diff)
downloadexternal_python_setuptools-1f23f9a25e6c91554954185e84497056062093be.tar.gz
external_python_setuptools-1f23f9a25e6c91554954185e84497056062093be.tar.bz2
external_python_setuptools-1f23f9a25e6c91554954185e84497056062093be.zip
Don't duplicate error case in package_index
easy_install has code to handle parsing a requirement, catching the ValueError and then raising a DistUtilsError. This code was entirely duplicated in package_index, so I've slightly refactored to remove the duplication.
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-xsetuptools/package_index.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py
index 82cd608f..3fb39269 100755
--- a/setuptools/package_index.py
+++ b/setuptools/package_index.py
@@ -52,6 +52,15 @@ _tmpl = "setuptools/{setuptools.__version__} Python-urllib/{py_major}"
user_agent = _tmpl.format(py_major=sys.version[:3], **globals())
+def parse_requirement_arg(spec):
+ try:
+ return Requirement.parse(spec)
+ except ValueError:
+ raise DistutilsError(
+ "Not a URL, existing file, or requirement spec: %r" % (spec,)
+ )
+
+
def parse_bdist_wininst(name):
"""Return (base,pyversion) or (None,None) for possible .exe name"""
@@ -561,13 +570,7 @@ class PackageIndex(Environment):
# Existing file or directory, just return it
return spec
else:
- try:
- spec = Requirement.parse(spec)
- except ValueError:
- raise DistutilsError(
- "Not a URL, existing file, or requirement spec: %r" %
- (spec,)
- )
+ spec = parse_requirement_arg(spec)
return getattr(self.fetch_distribution(spec, tmpdir), 'location', None)
def fetch_distribution(