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

responding to comments

This commit is contained in:
Omry Yadan 2019-08-02 23:14:41 -07:00
parent e67f066169
commit 8e87980d17
2 changed files with 31 additions and 40 deletions

View file

@ -938,10 +938,10 @@ def unpack_file_url(
if is_dir_url(link): if is_dir_url(link):
def ignore(d, names): def ignore(d, names):
# Pulling in those directories can potentially # Pulling in those directories can potentially be very slow,
# be very slow. # exclude the following directories if they appear in the top
# see discussion at: # level dir (and only it).
# https://github.com/pypa/pip/pull/6770 # See discussion at https://github.com/pypa/pip/pull/6770
return ['.tox', '.nox'] if d == link_path else [] return ['.tox', '.nox'] if d == link_path else []
if os.path.isdir(location): if os.path.isdir(location):

View file

@ -18,8 +18,8 @@ from pip._internal.download import (
from pip._internal.exceptions import HashMismatch from pip._internal.exceptions import HashMismatch
from pip._internal.models.link import Link from pip._internal.models.link import Link
from pip._internal.utils.hashes import Hashes from pip._internal.utils.hashes import Hashes
from pip._internal.utils.misc import ensure_dir, path_to_url from pip._internal.utils.misc import path_to_url
from tests.lib import create_file from tests.lib import Path, create_file
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
@ -417,44 +417,35 @@ class Test_unpack_file_url(object):
'.nox', '.nox',
'.tox' '.tox'
]) ])
def test_unpack_file_url_with_excluded_dirs(exclude_dir): def test_unpack_file_url_excludes_expected_dirs(tmpdir, exclude_dir):
src_dir = tmpdir / 'src'
def touch(path): dst_dir = tmpdir / 'dst'
with open(path, 'a'): src_included_file = Path.joinpath(src_dir, 'file.txt')
os.utime(path, None) src_excluded_dir = Path.joinpath(src_dir, exclude_dir)
src_excluded_file = Path.joinpath(src_dir, exclude_dir, 'file.txt')
src_dir = mkdtemp() src_included_dir = Path.joinpath(src_dir, 'subdir', exclude_dir)
src_included_file = os.path.join(src_dir, 'file.txt')
src_excluded_dir = os.path.join(src_dir, exclude_dir)
src_excluded_file = os.path.join(src_dir, exclude_dir, 'file.txt')
src_included_dir = os.path.join(src_dir, 'subdir', exclude_dir)
# set up source directory # set up source directory
ensure_dir(src_excluded_dir) src_excluded_dir.mkdir(parents=True)
ensure_dir(src_included_dir) src_included_dir.mkdir(parents=True)
touch(src_included_file) Path.touch(src_included_file)
touch(src_excluded_file) Path.touch(src_excluded_file)
dst_dir = mkdtemp() dst_included_file = Path.joinpath(dst_dir, 'file.txt')
dst_included_file = os.path.join(dst_dir, 'file.txt') dst_excluded_dir = Path.joinpath(dst_dir, exclude_dir)
dst_excluded_dir = os.path.join(dst_dir, exclude_dir) dst_excluded_file = Path.joinpath(dst_dir, exclude_dir, 'file.txt')
dst_excluded_file = os.path.join(dst_dir, exclude_dir, 'file.txt') dst_included_dir = Path.joinpath(dst_dir, 'subdir', exclude_dir)
dst_included_dir = os.path.join(dst_dir, 'subdir', exclude_dir)
try: src_link = Link(path_to_url(src_dir))
src_link = Link(path_to_url(src_dir)) unpack_file_url(
unpack_file_url( src_link,
src_link, dst_dir,
dst_dir, download_dir=None
download_dir=None )
) assert not os.path.isdir(dst_excluded_dir)
assert not os.path.isdir(dst_excluded_dir) assert not os.path.isfile(dst_excluded_file)
assert not os.path.isfile(dst_excluded_file) assert os.path.isfile(dst_included_file)
assert os.path.isfile(dst_included_file) assert os.path.isdir(dst_included_dir)
assert os.path.isdir(dst_included_dir)
finally:
rmtree(src_dir)
rmtree(dst_dir)
class TestSafeFileCache: class TestSafeFileCache: