Skip to content

Commit

Permalink
Merge pull request #6053 from pradyunsg/misc/minor-cleanup
Browse files Browse the repository at this point in the history
Eliminate a cyclic import, Add some comments to wheel.py for future reference
  • Loading branch information
pradyunsg committed Nov 30, 2018
2 parents e5ab7f6 + fc62b5b commit 95f0b2a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/pip/_internal/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
from pip._internal.utils.deprecation import deprecated
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import (
ARCHIVE_EXTENSIONS, SUPPORTED_EXTENSIONS, normalize_path,
ARCHIVE_EXTENSIONS, SUPPORTED_EXTENSIONS, WHEEL_EXTENSION, normalize_path,
redact_password_from_url,
)
from pip._internal.utils.packaging import check_requires_python
from pip._internal.wheel import Wheel, wheel_ext
from pip._internal.wheel import Wheel

__all__ = ['FormatControl', 'PackageFinder']

Expand Down Expand Up @@ -781,15 +781,15 @@ def _link_package_versions(self, link, search):
link, 'unsupported archive format: %s' % ext,
)
return
if "binary" not in search.formats and ext == wheel_ext:
if "binary" not in search.formats and ext == WHEEL_EXTENSION:
self._log_skipped_link(
link, 'No binaries permitted for %s' % search.supplied,
)
return
if "macosx10" in link.path and ext == '.zip':
self._log_skipped_link(link, 'macosx10 one')
return
if ext == wheel_ext:
if ext == WHEEL_EXTENSION:
try:
wheel = Wheel(link.filename)
except InvalidWheelFilename:
Expand All @@ -808,7 +808,7 @@ def _link_package_versions(self, link, search):
version = wheel.version

# This should be up by the search.ok_binary check, but see issue 2700.
if "source" not in search.formats and ext != wheel_ext:
if "source" not in search.formats and ext != WHEEL_EXTENSION:
self._log_skipped_link(
link, 'No sources permitted for %s' % search.supplied,
)
Expand Down
7 changes: 4 additions & 3 deletions src/pip/_internal/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from pip._vendor.six.moves.urllib import parse as urllib_parse

from pip._internal.download import path_to_url
from pip._internal.utils.misc import redact_password_from_url, splitext
from pip._internal.utils.misc import (
WHEEL_EXTENSION, redact_password_from_url, splitext,
)
from pip._internal.utils.models import KeyBasedCompareMixin
from pip._internal.wheel import wheel_ext


class Link(KeyBasedCompareMixin):
Expand Down Expand Up @@ -126,7 +127,7 @@ def show_url(self):

@property
def is_wheel(self):
return self.ext == wheel_ext
return self.ext == WHEEL_EXTENSION

@property
def is_artifact(self):
Expand Down
6 changes: 4 additions & 2 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@
'renames', 'get_prog',
'unzip_file', 'untar_file', 'unpack_file', 'call_subprocess',
'captured_stdout', 'ensure_dir',
'ARCHIVE_EXTENSIONS', 'SUPPORTED_EXTENSIONS',
'ARCHIVE_EXTENSIONS', 'SUPPORTED_EXTENSIONS', 'WHEEL_EXTENSION',
'get_installed_version', 'remove_auth_from_url']


logger = std_logging.getLogger(__name__)

WHEEL_EXTENSION = '.whl'
BZ2_EXTENSIONS = ('.tar.bz2', '.tbz')
XZ_EXTENSIONS = ('.tar.xz', '.txz', '.tlz', '.tar.lz', '.tar.lzma')
ZIP_EXTENSIONS = ('.zip', '.whl')
ZIP_EXTENSIONS = ('.zip', WHEEL_EXTENSION)
TAR_EXTENSIONS = ('.tar.gz', '.tgz', '.tar')
ARCHIVE_EXTENSIONS = (
ZIP_EXTENSIONS + BZ2_EXTENSIONS + TAR_EXTENSIONS + XZ_EXTENSIONS)
SUPPORTED_EXTENSIONS = ZIP_EXTENSIONS + TAR_EXTENSIONS

try:
import bz2 # noqa
SUPPORTED_EXTENSIONS += BZ2_EXTENSIONS
Expand Down
14 changes: 9 additions & 5 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from pip._internal.locations import (
PIP_DELETE_MARKER_FILENAME, distutils_scheme,
)
from pip._internal.models.link import Link
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import (
call_subprocess, captured_stdout, ensure_dir, read_chunks,
Expand All @@ -42,8 +43,6 @@
if MYPY_CHECK_RUNNING:
from typing import Dict, List, Optional # noqa: F401

wheel_ext = '.whl'

VERSION_COMPATIBLE = (1, 0)


Expand Down Expand Up @@ -236,6 +235,9 @@ def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None,
pycompile=True, scheme=None, isolated=False, prefix=None,
warn_script_location=True):
"""Install a wheel"""
# TODO: Investigate and break this up.
# TODO: Look into moving this into a dedicated class for representing an
# installation.

if not scheme:
scheme = distutils_scheme(
Expand Down Expand Up @@ -596,7 +598,8 @@ def check_compatibility(version, name):
class Wheel(object):
"""A wheel file"""

# TODO: maybe move the install code into this class
# TODO: Maybe move the class into the models sub-package
# TODO: Maybe move the install code into this class

wheel_file_re = re.compile(
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>.*?))
Expand Down Expand Up @@ -777,8 +780,6 @@ def build(self, requirements, session, autobuilding=False):
newly built wheel, in preparation for installation.
:return: True if all the wheels built correctly.
"""
from pip._internal.models.link import Link

# TODO: This check fails if --no-cache-dir is set. And yet we
# might be able to build into the ephemeral cache, surely?
building_is_possible = self._wheel_dir or (
Expand Down Expand Up @@ -823,6 +824,9 @@ def build(self, requirements, session, autobuilding=False):
if not buildset:
return []

# TODO by @pradyunsg
# Should break up this method into 2 separate methods.

# Build the wheels.
logger.info(
'Building wheels for collected packages: %s',
Expand Down

0 comments on commit 95f0b2a

Please sign in to comment.