Skip to content

Commit e90dfd5

Browse files
authored
Exclude top-level .tox|.nox|.venv from sdist (#4603)
2 parents e55c19e + 67e854f commit e90dfd5

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ include tox.ini
1919
include setuptools/tests/config/setupcfg_examples.txt
2020
include setuptools/config/*.schema.json
2121
global-exclude *.py[cod] __pycache__
22-
prune .tox

setuptools/command/egg_info.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -606,16 +606,6 @@ def _add_referenced_files(self):
606606
log.debug("adding file referenced by config '%s'", rf)
607607
self.filelist.extend(referenced)
608608

609-
def prune_file_list(self):
610-
build = self.get_finalized_command('build')
611-
base_dir = self.distribution.get_fullname()
612-
self.filelist.prune(build.build_base)
613-
self.filelist.prune(base_dir)
614-
sep = re.escape(os.sep)
615-
self.filelist.exclude_pattern(
616-
r'(^|' + sep + r')(RCS|CVS|\.svn)' + sep, is_regex=True
617-
)
618-
619609
def _safe_data_files(self, build_py):
620610
"""
621611
The parent class implementation of this method

setuptools/command/sdist.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import contextlib
44
import os
5+
import re
56
from itertools import chain
67

78
from .._importlib import metadata
@@ -156,6 +157,12 @@ def _add_defaults_data_files(self):
156157
except TypeError:
157158
log.warn("data_files contains unexpected objects")
158159

160+
def prune_file_list(self):
161+
super().prune_file_list()
162+
# Prevent accidental inclusion of test-related cache dirs at the project root
163+
sep = re.escape(os.sep)
164+
self.filelist.exclude_pattern(r"^(\.tox|\.nox|\.venv)" + sep, is_regex=True)
165+
159166
def check_readme(self):
160167
for f in self.READMES:
161168
if os.path.exists(f):

setuptools/tests/test_sdist.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tempfile
1010
import unicodedata
1111
from inspect import cleandoc
12+
from pathlib import Path
1213
from unittest import mock
1314

1415
import jaraco.path
@@ -425,6 +426,46 @@ def test_defaults_case_sensitivity(self, source_dir):
425426
assert 'setup.py' not in manifest, manifest
426427
assert 'setup.cfg' not in manifest, manifest
427428

429+
def test_exclude_dev_only_cache_folders(self, source_dir):
430+
included = {
431+
# Emulate problem in https://github.com/pypa/setuptools/issues/4601
432+
"MANIFEST.in": (
433+
"global-include LICEN[CS]E* COPYING* NOTICE* AUTHORS*\n"
434+
"global-include *.txt\n"
435+
),
436+
# For the sake of being conservative and limiting unforeseen side-effects
437+
# we just exclude dev-only cache folders at the root of the repository:
438+
"test/.venv/lib/python3.9/site-packages/bar-2.dist-info/AUTHORS.rst": "",
439+
"src/.nox/py/lib/python3.12/site-packages/bar-2.dist-info/COPYING.txt": "",
440+
"doc/.tox/default/lib/python3.11/site-packages/foo-4.dist-info/LICENSE": "",
441+
# Let's test against false positives with similarly named files:
442+
".venv-requirements.txt": "",
443+
".tox-coveragerc.txt": "",
444+
".noxy/coveragerc.txt": "",
445+
}
446+
447+
excluded = {
448+
# .tox/.nox/.venv are well-know folders present at the root of Python repos
449+
# and therefore should be excluded
450+
".tox/release/lib/python3.11/site-packages/foo-4.dist-info/LICENSE": "",
451+
".nox/py/lib/python3.12/site-packages/bar-2.dist-info/COPYING.txt": "",
452+
".venv/lib/python3.9/site-packages/bar-2.dist-info/AUTHORS.rst": "",
453+
}
454+
455+
for file, content in {**excluded, **included}.items():
456+
Path(source_dir, file).parent.mkdir(parents=True, exist_ok=True)
457+
Path(source_dir, file).write_text(content, encoding="utf-8")
458+
459+
cmd = self.setup_with_extension()
460+
self.assert_package_data_in_manifest(cmd)
461+
manifest = {f.replace(os.sep, '/') for f in cmd.filelist.files}
462+
for path in excluded:
463+
assert os.path.exists(path)
464+
assert path not in manifest, (path, manifest)
465+
for path in included:
466+
assert os.path.exists(path)
467+
assert path in manifest, (path, manifest)
468+
428469
@fail_on_ascii
429470
def test_manifest_is_written_with_utf8_encoding(self):
430471
# Test for #303.
@@ -915,4 +956,4 @@ def test_sanity_check_setuptools_own_sdist(setuptools_sdist):
915956

916957
# setuptools sdist should not include the .tox folder
917958
tox_files = [name for name in files if ".tox" in name]
918-
assert len(tox_files) == 0
959+
assert len(tox_files) == 0, f"not empty {tox_files}"

0 commit comments

Comments
 (0)