Skip to content

Commit fd20476

Browse files
authored
Merge pull request #7773 from stealthycoin/remove-pycache-from-source-tree
Remove __pycache__ folders from source tree when building
2 parents 37a1ec7 + 56dc129 commit fd20476

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ DOWNLOAD_DEPS_FLAG = @DOWNLOAD_DEPS_FLAG@
1717
all: build
1818

1919
build:
20-
"$(PYTHON)" "$(build_backend)" \
20+
PYTHONDONTWRITEBYTECODE=1 "$(PYTHON)" "$(build_backend)" \
2121
build \
2222
--artifact "$(INSTALL_TYPE)" \
2323
--build-dir "$(aws_cli_builddir)" $(DOWNLOAD_DEPS_FLAG)

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@ else $as_nop
20842084
fi
20852085

20862086
if test "$with_download_deps" = no; then
2087-
${PYTHON} ${srcdir}/backends/build_system validate-env --artifact $with_install_type || as_fn_error $? "\"Python dependencies not met.\"" "$LINENO" 5
2087+
PYTHONDONTWRITEBYTECODE=1 ${PYTHON} ${srcdir}/backends/build_system validate-env --artifact $with_install_type || as_fn_error $? "\"Python dependencies not met.\"" "$LINENO" 5
20882088
DOWNLOAD_DEPS_FLAG=""
20892089
else
20902090
DOWNLOAD_DEPS_FLAG=--download-deps

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ AC_ARG_WITH(download_deps,
4545
[with_download_deps=no]
4646
)
4747
if test "$with_download_deps" = no; then
48-
${PYTHON} ${srcdir}/backends/build_system validate-env --artifact $with_install_type || AC_MSG_ERROR("Python dependencies not met.")
48+
PYTHONDONTWRITEBYTECODE=1 ${PYTHON} ${srcdir}/backends/build_system validate-env --artifact $with_install_type || AC_MSG_ERROR("Python dependencies not met.")
4949
DOWNLOAD_DEPS_FLAG=""
5050
else
5151
DOWNLOAD_DEPS_FLAG=--download-deps

tests/backends/build_system/integration/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ def assert_version_string_is_correct(self, exe_path, dist_type):
6363
assert f"Python/{self.expected_python_version()}" in version_string
6464
assert f"source-{dist_type}" in version_string
6565

66+
def assert_no_pycache(self, directory: Path):
67+
failures = []
68+
for root, dirs, files in os.walk(directory):
69+
# Do not check the build directory since that is expected to have
70+
# __pycache__ folders generated inside it.
71+
if 'build' in dirs:
72+
dirs.remove('build')
73+
# If we are not in a build directory there should not be
74+
# any pycache directories.
75+
if '__pycache__' in dirs:
76+
failures.append(os.path.join(root, '__pycache__'))
77+
78+
assert failures == [], f"Expected no __pycache__ directories, found {failures}"
79+
6680
def assert_built_venv_is_correct(self, venv_dir):
6781
self.assert_venv_is_correct(venv_dir)
6882
files = os.listdir(venv_dir)
@@ -124,7 +138,12 @@ def _init_cli_directory(self):
124138
shutil.copytree(
125139
ROOT,
126140
self.cli_path,
127-
ignore=shutil.ignore_patterns(".git", "build", ".tox"),
141+
ignore=shutil.ignore_patterns(
142+
".git",
143+
"build",
144+
".tox",
145+
"__pycache__",
146+
),
128147
)
129148

130149
def _init_venv_directory(self):

tests/backends/build_system/integration/test_makefile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def test_exe_with_deps(self, workspace: VEnvWorkspace):
124124
workspace.make()
125125

126126
self.assert_built_exe_is_correct(workspace.cli_path)
127+
self.assert_no_pycache(workspace.cli_path)
127128

128129
@skip_if_windows(WINDOWS_SKIP_REASON)
129130
def test_exe_without_deps(self, workspace: VEnvWorkspace):
@@ -132,6 +133,7 @@ def test_exe_without_deps(self, workspace: VEnvWorkspace):
132133
workspace.configure(install_type="portable-exe")
133134
workspace.make()
134135

136+
self.assert_no_pycache(workspace.cli_path)
135137
self.assert_built_exe_is_correct(workspace.cli_path)
136138

137139
@skip_if_windows(WINDOWS_SKIP_REASON)
@@ -142,6 +144,7 @@ def test_venv_with_deps(self, workspace: VEnvWorkspace):
142144
)
143145
workspace.make()
144146

147+
self.assert_no_pycache(workspace.cli_path)
145148
self.assert_built_venv_is_correct(workspace.build_path)
146149

147150
@skip_if_windows(WINDOWS_SKIP_REASON)
@@ -152,4 +155,5 @@ def test_venv_without_deps(self, workspace: VEnvWorkspace):
152155
)
153156
workspace.make()
154157

158+
self.assert_no_pycache(workspace.cli_path)
155159
self.assert_built_venv_is_correct(workspace.build_path)

0 commit comments

Comments
 (0)