diff --git a/backends/pep517.py b/backends/pep517.py index f165f26e95a1..4e4818007e84 100644 --- a/backends/pep517.py +++ b/backends/pep517.py @@ -136,11 +136,20 @@ def _inject_extra_sdist_files(tar_root): for filename in glob.glob(pattern, recursive=True): filename = os.path.relpath(filename, ROOT_DIR) path_to_add = os.path.join(ROOT_DIR, filename) + if not _should_copy(path_to_add): + continue target_path = os.path.join(tar_root, filename) _create_dir_if_not_exists(os.path.dirname(target_path)) shutil.copy2(path_to_add, target_path) +def _should_copy(path): + if "__pycache__" in path or path.endswith(".pyc"): + return False + if os.path.isdir(path): + return False + return True + def read_sdist_extras(): with open(ROOT_DIR / "pyproject.toml", "r") as f: data = f.read() diff --git a/pyproject.toml b/pyproject.toml index 02fc78519050..f7c7cd97c44c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ include = [ "backends/**/*.py", "bin/*", "CHANGELOG.rst", + "tests/**/*", ] # end of cli sdist tool section diff --git a/tests/backends/test_pep517.py b/tests/backends/test_pep517.py index 98b16f255464..e9a6ed285d3e 100644 --- a/tests/backends/test_pep517.py +++ b/tests/backends/test_pep517.py @@ -110,6 +110,13 @@ def test_build_sdist(tmpdir, config_settings): # Make sure the bin directory is included. assert unpacked_sdist.join("bin", "aws").check() + # Make sure the tests directory is included. + assert unpacked_sdist.join("tests", "__init__.py").check() + assert unpacked_sdist.join("tests", "unit", "__init__.py").check() + assert unpacked_sdist.join( + "tests", "backends", "build_system", "unit", "__init__.py").check() + assert unpacked_sdist.join("tests", "__init__.py").check() + # We do not build the ac.index in building the sdist. So we want to make # sure it is not being included. assert not unpacked_sdist.join("awscli", "data", "ac.index").check() @@ -245,6 +252,7 @@ def test_read_sdist_extras(): "backends/**/*.py", "bin/*", "CHANGELOG.rst", + "tests/**/*", } extras = set(backends.pep517.read_sdist_extras())