Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize cache_dir path to be compatible with pip v20 #1062

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions piptools/_compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
is_dir_url,
is_file_url,
is_vcs_url,
normalize_path,
parse_requirements,
path_to_url,
stdlib_pkgs,
Expand Down
1 change: 1 addition & 0 deletions piptools/_compat/pip_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def do_import(module_path, subimport=None, old_path=None):
Session = do_import("_vendor.requests.sessions", "Session")
Resolver = do_import("legacy_resolve", "Resolver", old_path="resolve")
WheelCache = do_import("cache", "WheelCache", old_path="wheel")
normalize_path = do_import("utils.misc", "normalize_path", old_path="utils")

# pip 18.1 has refactored InstallRequirement constructors use by pip-tools.
if PIP_VERSION < (18, 1):
Expand Down
5 changes: 4 additions & 1 deletion piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
is_dir_url,
is_file_url,
is_vcs_url,
normalize_path,
path_to_url,
url_to_path,
)
Expand Down Expand Up @@ -62,6 +63,8 @@ def __init__(self, pip_args, cache_dir, build_isolation=False):
# and pre) are deferred to pip.
self.command = create_install_command()
self.options, _ = self.command.parse_args(pip_args)
if self.options.cache_dir:
kammala marked this conversation as resolved.
Show resolved Hide resolved
self.options.cache_dir = normalize_path(self.options.cache_dir)
kammala marked this conversation as resolved.
Show resolved Hide resolved

self.session = self.command._build_session(self.options)
self.finder = self.command._build_package_finder(
Expand All @@ -81,7 +84,7 @@ def __init__(self, pip_args, cache_dir, build_isolation=False):

# Setup file paths
self.freshen_build_caches()
self._cache_dir = cache_dir
self._cache_dir = normalize_path(cache_dir)
self._download_dir = fs_str(os.path.join(self._cache_dir, "pkgs"))
self._wheel_download_dir = fs_str(os.path.join(self._cache_dir, "wheels"))

Expand Down
29 changes: 29 additions & 0 deletions tests/test_repository_pypi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os

import mock
import pytest

from piptools._compat import PackageFinder
from piptools._compat.pip_compat import PIP_VERSION, Link, Session, path_to_url
from piptools.repositories import PyPIRepository
from piptools.repositories.pypi import open_local_or_remote_file


Expand Down Expand Up @@ -176,3 +179,29 @@ def test_wheel_cache_cleanup_called(
ireq = from_line("six==1.10.0")
pypi_repository.get_dependencies(ireq)
WheelCache.return_value.cleanup.assert_called_once_with()


def test_relative_path_cache_dir_is_normalized(from_line):
relative_cache_dir = "pypi-repo-cache"
pypi_repository = PyPIRepository([], cache_dir=relative_cache_dir)

assert os.path.isabs(pypi_repository._cache_dir)
assert pypi_repository._cache_dir.endswith(relative_cache_dir)


def test_relative_path_pip_cache_dir_is_normalized(from_line, tmpdir):
relative_cache_dir = "pip-cache"
pypi_repository = PyPIRepository(
["--cache-dir", relative_cache_dir], cache_dir=str(tmpdir / "pypi-repo-cache")
)

assert os.path.isabs(pypi_repository.options.cache_dir)
assert pypi_repository.options.cache_dir.endswith(relative_cache_dir)


def test_pip_cache_dir_is_empty(from_line, tmpdir):
pypi_repository = PyPIRepository(
["--no-cache-dir"], cache_dir=str(tmpdir / "pypi-repo-cache")
)

assert not pypi_repository.options.cache_dir