Skip to content

Commit e5ab7f6

Browse files
authored
Merge pull request #6051 from pradyunsg/fix/incorrect-source-copying-logic
Don't copy pip's non code files and folders in tests
2 parents ec3bacc + 7a23cc8 commit e5ab7f6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/conftest.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import compileall
2+
import fnmatch
23
import io
34
import os
45
import shutil
@@ -166,15 +167,24 @@ def isolate(tmpdir):
166167

167168
@pytest.fixture(scope='session')
168169
def pip_src(tmpdir_factory):
170+
def not_code_files_and_folders(path, names):
171+
# In the root directory, ignore all folders except "src"
172+
if path == SRC_DIR:
173+
folders = {name for name in names if os.path.isdir(path / name)}
174+
return folders - {"src"}
175+
176+
# Ignore all compiled files and egg-info.
177+
ignored = list()
178+
for pattern in ["__pycache__", "*.pyc", "pip.egg-info"]:
179+
ignored.extend(fnmatch.filter(names, pattern))
180+
return set(ignored)
181+
169182
pip_src = Path(str(tmpdir_factory.mktemp('pip_src'))).join('pip_src')
170183
# Copy over our source tree so that each use is self contained
171184
shutil.copytree(
172185
SRC_DIR,
173186
pip_src.abspath,
174-
ignore=shutil.ignore_patterns(
175-
"*.pyc", "__pycache__", "contrib", "docs", "tasks",
176-
"tests", "pip.egg-info", "build", "dist", ".tox", ".git",
177-
),
187+
ignore=not_code_files_and_folders,
178188
)
179189
return pip_src
180190

0 commit comments

Comments
 (0)