Skip to content

Commit

Permalink
Issue #2563: Read cached wheels from ~/.cache/pip/wheels
Browse files Browse the repository at this point in the history
This won't put wheels into that directory, but will read them if they
are there. --no-cache-dir will disable reading such wheels.
  • Loading branch information
rbtcollins committed Mar 30, 2015
1 parent 77df270 commit d73c84f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/reference/pip_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ Windows
:file:`<CSIDL_LOCAL_APPDATA>\pip\Cache`


Wheel cache
***********

Pip will read from the subdirectory ``wheels`` within the pip cache dir and use
any packages found there. This is disabled via the same ``no-cache-dir`` option
that disables the HTTP cache.


Hash Verification
+++++++++++++++++

Expand Down
1 change: 1 addition & 0 deletions pip/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def _build_package_finder(self, options, index_urls, session):
allow_all_prereleases=options.pre,
process_dependency_links=options.process_dependency_links,
session=session,
wheel_cache=options.cache_dir,
)

def run(self, options, args):
Expand Down
1 change: 1 addition & 0 deletions pip/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def _build_package_finder(self, options, index_urls, session):
trusted_hosts=options.trusted_hosts,
process_dependency_links=options.process_dependency_links,
session=session,
wheel_cache=options.cache_dir,
)

def run(self, options, args):
Expand Down
1 change: 1 addition & 0 deletions pip/commands/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def run(self, options, args):
trusted_hosts=options.trusted_hosts,
process_dependency_links=options.process_dependency_links,
session=session,
wheel_cache=options.cache_dir,
)

build_delete = (not (options.no_clean or options.build_dir))
Expand Down
15 changes: 13 additions & 2 deletions pip/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Routines related to PyPI, indexes"""
from __future__ import absolute_import

from itertools import chain
import logging
import cgi
import sys
Expand All @@ -24,6 +25,7 @@
)
from pip.download import url_to_path, path_to_url
from pip.models import PyPI
from pip.locations import WHEEL_CACHE_URL
from pip.wheel import Wheel, wheel_ext
from pip.pep425tags import supported_tags, supported_tags_noarch, get_platform
from pip.req.req_requirement import InstallationCandidate
Expand Down Expand Up @@ -60,7 +62,12 @@ def __init__(self, find_links, index_urls,
use_wheel=True, allow_external=(), allow_unverified=(),
allow_all_external=False, allow_all_prereleases=False,
trusted_hosts=None, process_dependency_links=False,
session=None):
session=None, wheel_cache=True):
"""Create a PackageFinder.
:param wheel_cache: If True (the default) the path for pip wheel
caching is added to the find_links setting.
"""
if session is None:
raise TypeError(
"PackageFinder() missing 1 required keyword argument: "
Expand All @@ -73,7 +80,11 @@ def __init__(self, find_links, index_urls,
# This is deliberately conservative - it might be fine just to
# blindly normalize anything starting with a ~...
self.find_links = []
for link in find_links:
if wheel_cache:
links = chain(find_links, [WHEEL_CACHE_URL()])
else:
links = find_links
for link in links:
if link.startswith('~'):
new_link = normalize_path(link)
if os.path.exists(new_link):
Expand Down
4 changes: 4 additions & 0 deletions pip/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@

# Application Directories
USER_CACHE_DIR = appdirs.user_cache_dir("pip")
# Not a constant because HOME is mangled during tests.
WHEEL_CACHE_DIR = \
lambda: os.path.join(appdirs.user_cache_dir("pip"), 'wheels')
WHEEL_CACHE_URL = lambda: 'file://' + WHEEL_CACHE_DIR()


DELETE_MARKER_MESSAGE = '''\
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pkg_resources import parse_version, Distribution
from pip.req import InstallRequirement
from pip.index import PackageFinder, Link
from pip.locations import WHEEL_CACHE_URL
from pip.exceptions import (
BestVersionAlreadyInstalled, DistributionNotFound, InstallationError,
)
Expand Down Expand Up @@ -771,3 +772,15 @@ def test_find_all_versions_find_links_and_index(data):
InstallRequirement.from_line('simple'))
# first the find-links versions then the page versions
assert [str(v.version) for v in versions] == ['3.0', '2.0', '1.0', '1.0']


def test_find_links_defaults_include_wheel_cache(data):
finder = PackageFinder(
[data.find_links], [], session=PipSession())
assert WHEEL_CACHE_URL() == finder.find_links[-1]


def test_find_links_suppress_wheel_cache(data):
finder = PackageFinder(
[data.find_links], [], session=PipSession(), wheel_cache=False)
assert [data.find_links] == finder.find_links

0 comments on commit d73c84f

Please sign in to comment.