Commit 1f23f9a2 authored by Steve Kowalik's avatar Steve Kowalik

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.
parent 2388233e
...@@ -49,8 +49,9 @@ from setuptools.sandbox import run_setup ...@@ -49,8 +49,9 @@ from setuptools.sandbox import run_setup
from setuptools.py31compat import get_path, get_config_vars from setuptools.py31compat import get_path, get_config_vars
from setuptools.command import setopt from setuptools.command import setopt
from setuptools.archive_util import unpack_archive from setuptools.archive_util import unpack_archive
from setuptools.package_index import PackageIndex from setuptools.package_index import (
from setuptools.package_index import URL_SCHEME PackageIndex, parse_requirement_arg, URL_SCHEME,
)
from setuptools.command import bdist_egg, egg_info from setuptools.command import bdist_egg, egg_info
from pkg_resources import ( from pkg_resources import (
yield_lines, normalize_path, resource_string, ensure_directory, yield_lines, normalize_path, resource_string, ensure_directory,
...@@ -1522,15 +1523,6 @@ def get_exe_prefixes(exe_filename): ...@@ -1522,15 +1523,6 @@ def get_exe_prefixes(exe_filename):
return prefixes return prefixes
def parse_requirement_arg(spec):
try:
return Requirement.parse(spec)
except ValueError:
raise DistutilsError(
"Not a URL, existing file, or requirement spec: %r" % (spec,)
)
class PthDistributions(Environment): class PthDistributions(Environment):
"""A .pth file with Distribution paths in it""" """A .pth file with Distribution paths in it"""
......
...@@ -52,6 +52,15 @@ _tmpl = "setuptools/{setuptools.__version__} Python-urllib/{py_major}" ...@@ -52,6 +52,15 @@ _tmpl = "setuptools/{setuptools.__version__} Python-urllib/{py_major}"
user_agent = _tmpl.format(py_major=sys.version[:3], **globals()) 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): def parse_bdist_wininst(name):
"""Return (base,pyversion) or (None,None) for possible .exe name""" """Return (base,pyversion) or (None,None) for possible .exe name"""
...@@ -561,13 +570,7 @@ class PackageIndex(Environment): ...@@ -561,13 +570,7 @@ class PackageIndex(Environment):
# Existing file or directory, just return it # Existing file or directory, just return it
return spec return spec
else: else:
try: spec = parse_requirement_arg(spec)
spec = Requirement.parse(spec)
except ValueError:
raise DistutilsError(
"Not a URL, existing file, or requirement spec: %r" %
(spec,)
)
return getattr(self.fetch_distribution(spec, tmpdir), 'location', None) return getattr(self.fetch_distribution(spec, tmpdir), 'location', None)
def fetch_distribution( def fetch_distribution(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment