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

exclude '.tox', '.nox' from being copied during 'pip install .' #6770

Merged
merged 14 commits into from
Aug 5, 2019
13 changes: 12 additions & 1 deletion docs/html/reference/pip_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,21 @@ does not satisfy the ``--require-hashes`` demand that every package have a
local hash.


Local project installs
++++++++++++++++++++++
pip supports installing local project in both regular mode and editable mode.
You can install local projects by specifying the project path to pip::

$ pip install path/to/SomeProject

During the installation, pip will copy the entire project directory to a temporary location and install from there.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say regular installation just so people don't get the idea that it may apply to editable installs.

The exception is that pip will exclude .tox and .nox directories present in the top level of the project from being copied.


.. _`editable-installs`:

"Editable" Installs
+++++++++++++++++++
~~~~~~~~~~~~~~~~~~~

"Editable" installs are fundamentally `"setuptools develop mode"
<https://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode>`_
Expand Down
1 change: 1 addition & 0 deletions news/6770.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip copying .tox and .nox directories to temporary build directories
15 changes: 13 additions & 2 deletions src/pip/_internal/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,12 +934,23 @@ def unpack_file_url(
of the link file inside download_dir.
"""
link_path = url_to_path(link.url_without_fragment)

# If it's a url to a local directory
if is_dir_url(link):

def ignore(d, names):
# Pulling in those directories can potentially be very slow,
# exclude the following directories if they appear in the top
# level dir (and only it).
# See discussion at https://github.com/pypa/pip/pull/6770
return ['.tox', '.nox'] if d == link_path else []

if os.path.isdir(location):
rmtree(location)
shutil.copytree(link_path, location, symlinks=True)
shutil.copytree(link_path,
location,
symlinks=True,
ignore=ignore)

if download_dir:
logger.info('Link is a directory, ignoring download_dir')
return
Expand Down
37 changes: 36 additions & 1 deletion tests/unit/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pip._internal.models.link import Link
from pip._internal.utils.hashes import Hashes
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")
Expand Down Expand Up @@ -413,6 +413,41 @@ def test_unpack_file_url_thats_a_dir(self, tmpdir, data):
assert os.path.isdir(os.path.join(self.build_dir, 'fspkg'))


@pytest.mark.parametrize('exclude_dir', [
'.nox',
'.tox'
])
def test_unpack_file_url_excludes_expected_dirs(tmpdir, exclude_dir):
src_dir = tmpdir / 'src'
dst_dir = tmpdir / 'dst'
src_included_file = Path.joinpath(src_dir, 'file.txt')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my previous comment was not very good - I meant using the joinpath method on src_dir which is now a Path, like src_dir.joinpath('file.txt'). Likewise with joinpath and touch below.

src_excluded_dir = Path.joinpath(src_dir, exclude_dir)
src_excluded_file = Path.joinpath(src_dir, exclude_dir, 'file.txt')
src_included_dir = Path.joinpath(src_dir, 'subdir', exclude_dir)

# set up source directory
src_excluded_dir.mkdir(parents=True)
src_included_dir.mkdir(parents=True)
Path.touch(src_included_file)
Path.touch(src_excluded_file)

dst_included_file = Path.joinpath(dst_dir, 'file.txt')
dst_excluded_dir = Path.joinpath(dst_dir, exclude_dir)
dst_excluded_file = Path.joinpath(dst_dir, exclude_dir, 'file.txt')
dst_included_dir = Path.joinpath(dst_dir, 'subdir', exclude_dir)

src_link = Link(path_to_url(src_dir))
unpack_file_url(
src_link,
dst_dir,
download_dir=None
)
assert not os.path.isdir(dst_excluded_dir)
assert not os.path.isfile(dst_excluded_file)
assert os.path.isfile(dst_included_file)
assert os.path.isdir(dst_included_dir)


class TestSafeFileCache:
"""
The no_perms test are useless on Windows since SafeFileCache uses
Expand Down