summaryrefslogtreecommitdiff
path: root/setuptools/tests
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-05-05 19:33:20 +0100
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2022-05-05 19:33:20 +0100
commited5d4bf58c70d5b4ad7b8ad42b27599e6a24be13 (patch)
tree3f2400f6c2dd17047ccfec74b593acadff422425 /setuptools/tests
parentddb8844eac49e0bf3b4f20067b425ffeac1531a2 (diff)
downloadpython-setuptools-git-ed5d4bf58c70d5b4ad7b8ad42b27599e6a24be13.tar.gz
Add test that capture transitional behaviour for build_py
During the transition, `build_py` should warn when a module or package is included in the distribution as if it was "package data".
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/test_build_py.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/setuptools/tests/test_build_py.py b/setuptools/tests/test_build_py.py
index 19c8b780..ab591adc 100644
--- a/setuptools/tests/test_build_py.py
+++ b/setuptools/tests/test_build_py.py
@@ -3,9 +3,14 @@ import stat
import shutil
import pytest
+import jaraco.path
+from path import Path
+from setuptools import SetuptoolsDeprecationWarning
from setuptools.dist import Distribution
+from .textwrap import DALS
+
def test_directories_in_package_data_glob(tmpdir_cwd):
"""
@@ -79,3 +84,69 @@ def test_executable_data(tmpdir_cwd):
assert os.stat('build/lib/pkg/run-me').st_mode & stat.S_IEXEC, \
"Script is not executable"
+
+
+def test_excluded_subpackages(tmp_path):
+ files = {
+ "setup.cfg": DALS("""
+ [metadata]
+ name = mypkg
+ version = 42
+
+ [options]
+ include_package_data = True
+ packages = find:
+
+ [options.packages.find]
+ exclude = *.tests*
+ """),
+ "mypkg": {
+ "__init__.py": "",
+ "resource_file.txt": "",
+ "tests": {
+ "__init__.py": "",
+ "test_mypkg.py": "",
+ "test_file.txt": "",
+ }
+ },
+ "MANIFEST.in": DALS("""
+ global-include *.py *.txt
+ global-exclude *.py[cod]
+ prune dist
+ prune build
+ prune *.egg-info
+ """)
+ }
+
+ with Path(tmp_path):
+ jaraco.path.build(files)
+ dist = Distribution({"script_name": "%PEP 517%"})
+ dist.parse_config_files()
+
+ build_py = dist.get_command_obj("build_py")
+ msg = r"Python recognizes 'mypkg\.tests' as an importable package"
+ with pytest.warns(SetuptoolsDeprecationWarning, match=msg):
+ # TODO: To fix #3260 we need some transition period to deprecate the
+ # existing behavior of `include_package_data`. After the transition, we
+ # should remove the warning and fix the behaviour.
+ build_py.finalize_options()
+ build_py.run()
+
+ build_dir = Path(dist.get_command_obj("build_py").build_lib)
+ assert (build_dir / "mypkg/__init__.py").exists()
+ assert (build_dir / "mypkg/resource_file.txt").exists()
+
+ # Setuptools is configured to ignore `mypkg.tests`, therefore the following
+ # files/dirs should not be included in the distribution.
+ for f in [
+ "mypkg/tests/__init__.py",
+ "mypkg/tests/test_mypkg.py",
+ "mypkg/tests/test_file.txt",
+ "mypkg/tests",
+ ]:
+ with pytest.raises(AssertionError):
+ # TODO: Enforce the following assertion once #3260 is fixed
+ # (remove context manager and the following xfail).
+ assert not (build_dir / f).exists()
+
+ pytest.xfail("#3260")