Skip to content

Commit 16c6f72

Browse files
committed
Automatically exclude top-level .tox|.nox|.ven from sdist
1 parent f3f2ca5 commit 16c6f72

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
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/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: 35 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,39 @@ 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": "global-include LICEN[CS]E* COPYING* NOTICE* AUTHORS*",
433+
# For the sake of being conservative and limiting unforeseen side-effects
434+
# we just exclude dev-only cache folders at the root of the repository
435+
"test/.venv/lib/python3.9/site-packages/bar-2.dist-info/AUTHORS.rst": "",
436+
"src/.nox/py/lib/python3.12/site-packages/bar-2.dist-info/COPYING.txt": "",
437+
"doc/.tox/default/lib/python3.11/site-packages/foo-4.dist-info/LICENSE": "",
438+
}
439+
440+
excluded = {
441+
# .tox/.nox/.venv are well-know folders present at the root of Python repos
442+
# and therefore should be excluded
443+
".tox/release/lib/python3.11/site-packages/foo-4.dist-info/LICENSE": "",
444+
".nox/py/lib/python3.12/site-packages/bar-2.dist-info/COPYING.txt": "",
445+
".venv/lib/python3.9/site-packages/bar-2.dist-info/AUTHORS.rst": "",
446+
}
447+
448+
for file, content in {**excluded, **included}.items():
449+
Path(source_dir, file).parent.mkdir(parents=True, exist_ok=True)
450+
Path(source_dir, file).write_text(content, encoding="utf-8")
451+
452+
cmd = self.setup_with_extension()
453+
self.assert_package_data_in_manifest(cmd)
454+
manifest = cmd.filelist.files
455+
for path in excluded:
456+
assert os.path.exists(path)
457+
assert path not in manifest
458+
for path in included:
459+
assert os.path.exists(path)
460+
assert path in manifest
461+
428462
@fail_on_ascii
429463
def test_manifest_is_written_with_utf8_encoding(self):
430464
# Test for #303.
@@ -915,4 +949,4 @@ def test_sanity_check_setuptools_own_sdist(setuptools_sdist):
915949

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

0 commit comments

Comments
 (0)