diff --git a/news/2195.feature b/news/2195.feature new file mode 100644 index 00000000000..947d6cd2f36 --- /dev/null +++ b/news/2195.feature @@ -0,0 +1 @@ +Add supporte for a `PIP_IGNORE` environment setting, which, when pointing to a valid file, causes `pip install` to ignore all file patterns listed in there. This can speed up installations from large source trees. diff --git a/src/pip/_internal/download.py b/src/pip/_internal/download.py index d56a1bb3bb2..4671857135b 100644 --- a/src/pip/_internal/download.py +++ b/src/pip/_internal/download.py @@ -690,11 +690,23 @@ def unpack_file_url(link, location, download_dir=None, hashes=None): """ link_path = url_to_path(link.url_without_fragment) + # if a .pipignore' file location is set and exists, '#' style + # comments are stripped. All other strings (space limited) are interpreted + # as glob-style pattersn to be passed to `shutil.copytree`, and are thus + # excluded from the file cloning operation. + ignored = list() + pipignore = os.environ.get('PIP_IGNORE') + if pipignore and os.path.isfile(pipignore): + with open(pipignore, 'r') as fin: + for line in fin.readlines(): + ignored.extend(line.split('#')[0].strip().split()) + # If it's a url to a local directory if is_dir_url(link): if os.path.isdir(location): rmtree(location) - shutil.copytree(link_path, location, symlinks=True) + shutil.copytree(link_path, location, symlinks=True, + ignore=shutil.ignore_patterns(*ignored)) if download_dir: logger.info('Link is a directory, ignoring download_dir') return