Skip to content

Commit 61602fe

Browse files
committed
remove _copy_source_tree and friends
1 parent fab7319 commit 61602fe

File tree

6 files changed

+2
-290
lines changed

6 files changed

+2
-290
lines changed

src/pip/_internal/operations/prepare.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
PreviousBuildDirError,
2525
VcsHashUnsupported,
2626
)
27-
from pip._internal.utils.filesystem import copy2_fixed
2827
from pip._internal.utils.hashes import MissingHashes
2928
from pip._internal.utils.logging import indent_log
30-
from pip._internal.utils.misc import display_path, hide_url, path_to_display
29+
from pip._internal.utils.misc import display_path, hide_url
3130
from pip._internal.utils.temp_dir import TempDirectory
3231
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
3332
from pip._internal.utils.unpacking import unpack_file
@@ -128,47 +127,6 @@ def get_http_url(
128127
return File(from_path, content_type)
129128

130129

131-
def _copy2_ignoring_special_files(src, dest):
132-
# type: (str, str) -> None
133-
"""Copying special files is not supported, but as a convenience to users
134-
we skip errors copying them. This supports tools that may create e.g.
135-
socket files in the project source directory.
136-
"""
137-
try:
138-
copy2_fixed(src, dest)
139-
except shutil.SpecialFileError as e:
140-
# SpecialFileError may be raised due to either the source or
141-
# destination. If the destination was the cause then we would actually
142-
# care, but since the destination directory is deleted prior to
143-
# copy we ignore all of them assuming it is caused by the source.
144-
logger.warning(
145-
"Ignoring special file error '%s' encountered copying %s to %s.",
146-
str(e),
147-
path_to_display(src),
148-
path_to_display(dest),
149-
)
150-
151-
152-
def _copy_source_tree(source, target):
153-
# type: (str, str) -> None
154-
def ignore(d, names):
155-
# type: (str, List[str]) -> List[str]
156-
# Pulling in those directories can potentially be very slow,
157-
# exclude the following directories if they appear in the top
158-
# level dir (and only it).
159-
# See discussion at https://github.com/pypa/pip/pull/6770
160-
return ['.tox', '.nox'] if d == source else []
161-
162-
kwargs = dict(ignore=ignore, symlinks=True) # type: CopytreeKwargs
163-
164-
if not PY2:
165-
# Python 2 does not support copy_function, so we only ignore
166-
# errors on special file copy in Python 3.
167-
kwargs['copy_function'] = _copy2_ignoring_special_files
168-
169-
shutil.copytree(source, target, **kwargs)
170-
171-
172130
def get_file_url(
173131
link, # type: Link
174132
download_dir=None, # type: Optional[str]

src/pip/_internal/utils/filesystem.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import os
33
import os.path
44
import random
5-
import shutil
6-
import stat
75
import sys
86
from contextlib import contextmanager
97
from tempfile import NamedTemporaryFile
@@ -54,36 +52,6 @@ def check_path_owner(path):
5452
return False # assume we don't own the path
5553

5654

57-
def copy2_fixed(src, dest):
58-
# type: (str, str) -> None
59-
"""Wrap shutil.copy2() but map errors copying socket files to
60-
SpecialFileError as expected.
61-
62-
See also https://bugs.python.org/issue37700.
63-
"""
64-
try:
65-
shutil.copy2(src, dest)
66-
except (OSError, IOError):
67-
for f in [src, dest]:
68-
try:
69-
is_socket_file = is_socket(f)
70-
except OSError:
71-
# An error has already occurred. Another error here is not
72-
# a problem and we can ignore it.
73-
pass
74-
else:
75-
if is_socket_file:
76-
raise shutil.SpecialFileError(
77-
"`{f}` is a socket".format(**locals()))
78-
79-
raise
80-
81-
82-
def is_socket(path):
83-
# type: (str) -> bool
84-
return stat.S_ISSOCK(os.lstat(path).st_mode)
85-
86-
8755
@contextmanager
8856
def adjacent_tmp_file(path):
8957
# type: (str) -> Iterator[NamedTemporaryFileResult]

tests/functional/test_install.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import glob
33
import os
44
import re
5-
import shutil
65
import ssl
76
import sys
87
import textwrap
@@ -29,7 +28,6 @@
2928
skip_if_python2,
3029
windows_workaround_7667,
3130
)
32-
from tests.lib.filesystem import make_socket_file
3331
from tests.lib.local_repos import local_checkout
3432
from tests.lib.path import Path
3533
from tests.lib.server import (
@@ -576,30 +574,6 @@ def test_install_from_local_directory_with_symlinks_to_directories(
576574
assert egg_info_folder in result.files_created, str(result)
577575

578576

579-
@pytest.mark.skipif("sys.platform == 'win32' or sys.version_info < (3,)")
580-
def test_install_from_local_directory_with_socket_file(script, data, tmpdir):
581-
"""
582-
Test installing from a local directory containing a socket file.
583-
"""
584-
egg_info_file = (
585-
script.site_packages /
586-
"FSPkg-0.1.dev0-py{pyversion}.egg-info".format(**globals())
587-
)
588-
package_folder = script.site_packages / "fspkg"
589-
to_copy = data.packages.joinpath("FSPkg")
590-
to_install = tmpdir.joinpath("src")
591-
592-
shutil.copytree(to_copy, to_install)
593-
# Socket file, should be ignored.
594-
socket_file_path = os.path.join(to_install, "example")
595-
make_socket_file(socket_file_path)
596-
597-
result = script.pip("install", "--verbose", to_install)
598-
assert package_folder in result.files_created, str(result.stdout)
599-
assert egg_info_file in result.files_created, str(result)
600-
assert str(socket_file_path) in result.stderr
601-
602-
603577
def test_install_from_local_directory_with_no_setup_py(script, data):
604578
"""
605579
Test installing from a local directory with no 'setup.py'.

tests/lib/filesystem.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/unit/test_operations_prepare.py

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,9 @@
1010
from pip._internal.models.link import Link
1111
from pip._internal.network.download import Downloader
1212
from pip._internal.network.session import PipSession
13-
from pip._internal.operations.prepare import (
14-
_copy_source_tree,
15-
_download_http_url,
16-
unpack_url,
17-
)
13+
from pip._internal.operations.prepare import _download_http_url, unpack_url
1814
from pip._internal.utils.hashes import Hashes
1915
from pip._internal.utils.urls import path_to_url
20-
from tests.lib.filesystem import (
21-
get_filelist,
22-
make_socket_file,
23-
make_unreadable_file,
24-
)
2516
from tests.lib.path import Path
2617
from tests.lib.requests_mocks import MockResponse
2718

@@ -101,76 +92,6 @@ def clean_project(tmpdir_factory, data):
10192
return new_project_dir
10293

10394

104-
def test_copy_source_tree(clean_project, tmpdir):
105-
target = tmpdir.joinpath("target")
106-
expected_files = get_filelist(clean_project)
107-
assert len(expected_files) == 3
108-
109-
_copy_source_tree(clean_project, target)
110-
111-
copied_files = get_filelist(target)
112-
assert expected_files == copied_files
113-
114-
115-
@pytest.mark.skipif("sys.platform == 'win32' or sys.version_info < (3,)")
116-
def test_copy_source_tree_with_socket(clean_project, tmpdir, caplog):
117-
target = tmpdir.joinpath("target")
118-
expected_files = get_filelist(clean_project)
119-
socket_path = str(clean_project.joinpath("aaa"))
120-
make_socket_file(socket_path)
121-
122-
_copy_source_tree(clean_project, target)
123-
124-
copied_files = get_filelist(target)
125-
assert expected_files == copied_files
126-
127-
# Warning should have been logged.
128-
assert len(caplog.records) == 1
129-
record = caplog.records[0]
130-
assert record.levelname == 'WARNING'
131-
assert socket_path in record.message
132-
133-
134-
@pytest.mark.skipif("sys.platform == 'win32' or sys.version_info < (3,)")
135-
def test_copy_source_tree_with_socket_fails_with_no_socket_error(
136-
clean_project, tmpdir
137-
):
138-
target = tmpdir.joinpath("target")
139-
expected_files = get_filelist(clean_project)
140-
make_socket_file(clean_project.joinpath("aaa"))
141-
unreadable_file = clean_project.joinpath("bbb")
142-
make_unreadable_file(unreadable_file)
143-
144-
with pytest.raises(shutil.Error) as e:
145-
_copy_source_tree(clean_project, target)
146-
147-
errored_files = [err[0] for err in e.value.args[0]]
148-
assert len(errored_files) == 1
149-
assert unreadable_file in errored_files
150-
151-
copied_files = get_filelist(target)
152-
# All files without errors should have been copied.
153-
assert expected_files == copied_files
154-
155-
156-
def test_copy_source_tree_with_unreadable_dir_fails(clean_project, tmpdir):
157-
target = tmpdir.joinpath("target")
158-
expected_files = get_filelist(clean_project)
159-
unreadable_file = clean_project.joinpath("bbb")
160-
make_unreadable_file(unreadable_file)
161-
162-
with pytest.raises(shutil.Error) as e:
163-
_copy_source_tree(clean_project, target)
164-
165-
errored_files = [err[0] for err in e.value.args[0]]
166-
assert len(errored_files) == 1
167-
assert unreadable_file in errored_files
168-
169-
copied_files = get_filelist(target)
170-
# All files without errors should have been copied.
171-
assert expected_files == copied_files
172-
173-
17495
class Test_unpack_url(object):
17596

17697
def prep(self, tmpdir, data):

tests/unit/test_utils_filesystem.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)