1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Merge pull request #2199 from msabramo/create_Index_class_and_PyPI_instance

Reduce duplication of "pypi.python.org"
This commit is contained in:
Paul Moore 2014-12-16 17:02:44 +00:00
commit 0f5b325aba
4 changed files with 23 additions and 5 deletions

View file

@ -11,6 +11,7 @@ from __future__ import absolute_import
import copy
from optparse import OptionGroup, SUPPRESS_HELP, Option
from pip.index import PyPI
from pip.locations import CA_BUNDLE_PATH, USER_CACHE_DIR, src_prefix
@ -192,7 +193,7 @@ index_url = OptionMaker(
'-i', '--index-url', '--pypi-url',
dest='index_url',
metavar='URL',
default='https://pypi.python.org/simple/',
default=PyPI.simple_url,
help='Base URL of Python Package Index (default %default).')
extra_index_url = OptionMaker(

View file

@ -6,6 +6,7 @@ import textwrap
from pip.basecommand import Command, SUCCESS
from pip.download import PipXmlrpcTransport
from pip.index import PyPI
from pip.utils import get_terminal_size
from pip.utils.logging import indent_log
from pip.exceptions import CommandError
@ -30,7 +31,7 @@ class SearchCommand(Command):
'--index',
dest='index',
metavar='URL',
default='https://pypi.python.org/pypi',
default=PyPI.pypi_url,
help='Base URL of Python Package Index (default %default)')
self.parser.insert_option_group(0, self.cmd_opts)

View file

@ -47,6 +47,21 @@ SECURE_ORIGINS = [
logger = logging.getLogger(__name__)
class Index(object):
def __init__(self, url):
self.url = url
self.netloc = urllib_parse.urlsplit(url).netloc
self.simple_url = self.url_to_path('simple')
self.pypi_url = self.url_to_path('pypi')
self.pip_json_url = self.url_to_path('pypi/pip/json')
def url_to_path(self, path):
return urllib_parse.urljoin(self.url, path)
PyPI = Index('https://pypi.python.org/')
class PackageFinder(object):
"""This finds packages.
@ -302,7 +317,7 @@ class PackageFinder(object):
)
page = self._get_page(main_index_url, req)
if page is None and 'pypi.python.org' not in str(main_index_url):
if page is None and PyPI.netloc not in str(main_index_url):
warnings.warn(
"Failed to find %r at %s. It is suggested to upgrade "
"your index to support normalized names as the name in "
@ -703,7 +718,7 @@ class PackageFinder(object):
and comes_from is not None
and urllib_parse.urlparse(
comes_from.url
).netloc.endswith("pypi.python.org")):
).netloc.endswith(PyPI.netloc)):
if not wheel.supported(tags=supported_tags_noarch):
logger.debug(
"Skipping %s because it is a pypi-hosted binary "

View file

@ -10,6 +10,7 @@ from pip._vendor import lockfile
from pip._vendor import pkg_resources
from pip.compat import total_seconds
from pip.index import PyPI
from pip.locations import USER_CACHE_DIR, running_under_virtualenv
@ -104,7 +105,7 @@ def pip_version_check(session):
# Refresh the version if we need to or just see if we need to warn
if pypi_version is None:
resp = session.get(
"https://pypi.python.org/pypi/pip/json",
PyPI.pip_json_url,
headers={"Accept": "application/json"},
)
resp.raise_for_status()