diff options
| author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-05-16 18:34:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-16 18:34:35 +0100 |
| commit | e66ee6206feb49fe4bdec417c84d601d6b4bbf72 (patch) | |
| tree | 465f4f09951508299000c9ae25573a68fde2d385 /setuptools/tests/test_build_py.py | |
| parent | aec2215be6711c850339484cd7f47d542a6c06a1 (diff) | |
| parent | 2b218927334c58a655fc285a5c241828d394cffe (diff) | |
| download | python-setuptools-git-e66ee6206feb49fe4bdec417c84d601d6b4bbf72.tar.gz | |
Warn about deprecation of behaviour that considers modules/packages as data when include_package_data=True (#3308)
Diffstat (limited to 'setuptools/tests/test_build_py.py')
| -rw-r--r-- | setuptools/tests/test_build_py.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/setuptools/tests/test_build_py.py b/setuptools/tests/test_build_py.py index f6f0d944..13fa64de 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): """ @@ -102,3 +107,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") |
