Skip to content

Commit af5264c

Browse files
authored
Merge pull request #7738 from stealthycoin/clean-up-build-env
Remove unnecessary metadata from cli v2 distributable
2 parents a8d7b9e + 15bd029 commit af5264c

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

backends/build_system/exe.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ def _update_metadata(self):
5151
self._final_dist_dir,
5252
distribution_source=DISTRIBUTION_SOURCE_EXE,
5353
)
54+
for distinfo in self._utils.glob(
55+
'**/*.dist-info',
56+
root=self._final_dist_dir
57+
):
58+
self._utils.rmtree(os.path.join(self._final_dist_dir, distinfo))
59+
5460

5561
def _ensure_no_existing_build_dir(self):
5662
if self._utils.isdir(self._dist_dir):

backends/build_system/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import re
1515
import sys
1616
import shlex
17+
import glob
1718
import json
1819
import shutil
1920
import subprocess
@@ -226,6 +227,10 @@ def path_exists(self, path: str) -> bool:
226227
def rmtree(self, path: str) -> None:
227228
shutil.rmtree(path)
228229

230+
def glob(self, pattern: str, root: str, recursive=True):
231+
with cd(root):
232+
return glob.glob(pattern, recursive=recursive)
233+
229234
def run(self, args: List[str], **kwargs: Dict[str, Any]):
230235
return subprocess.run(args, **kwargs)
231236

scripts/installers/make-exe

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from distutils.dir_util import copy_tree
1313

1414
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1515

16-
from utils import run, tmp_dir, update_metadata, save_to_zip
16+
from utils import run, tmp_dir, update_metadata, save_to_zip, remove_dist_info
1717
from install_deps import install_packages
1818

1919

@@ -50,6 +50,7 @@ def do_make_exe(workdir, exe_zipfile, ac_index):
5050
distribution_source=DISTRIBUTION_SOURCE)
5151
copy_directory_contents_into(aws_complete_exe_build, output_exe_dist_dir)
5252
copy_directory_contents_into(ASSETS_DIR, exe_dir)
53+
remove_dist_info(workdir)
5354
save_to_zip(workdir, exe_zipfile)
5455

5556

scripts/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import subprocess
88
import tempfile
99
import zipfile
10+
import glob
1011

1112
class BadRCError(Exception):
1213
pass
@@ -92,6 +93,13 @@ def update_metadata(dirname, **kwargs):
9293
json.dump(metadata, f)
9394

9495

96+
def remove_dist_info(dirname):
97+
with cd(dirname):
98+
for distinfo in glob.glob("**/*.dist-info", recursive=True):
99+
path = os.path.join(dirname, distinfo)
100+
shutil.rmtree(path)
101+
102+
95103
def save_to_zip(dirname, zipfile_name):
96104
if zipfile_name.endswith('.zip'):
97105
zipfile_name = zipfile_name[:-4]

tests/backends/build_system/integration/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ def assert_built_exe_is_correct(self, root_dir):
8888
"dist",
8989
"install",
9090
}
91+
dist_dir = aws_dir / "dist"
92+
dist_info_files = set(
93+
f for f in os.listdir(dist_dir)
94+
if '.dist-info' in f
95+
)
96+
assert dist_info_files == set(), \
97+
f"Expected no dist-info files, found: {dist_info_files}"
9198

9299
aws_exe = aws_dir / "dist" / "aws"
93100
self.assert_version_string_is_correct(aws_exe, "exe")

tests/backends/build_system/unit/test_exe.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def update_metadata(self, dirname, **kwargs):
4545
def rmtree(self, path):
4646
self.calls.append(("rmtree", path))
4747

48+
def glob(self, pattern, root, recursive=True):
49+
self.calls.append(('glob', pattern, root, recursive))
50+
return []
51+
4852

4953
class FakeAwsCliVenv:
5054
@property
@@ -116,7 +120,12 @@ def _expected_build_tasks(self):
116120
os.path.join("workspace", "aws", "dist"),
117121
{"distribution_source": "source-exe"},
118122
),
119-
123+
(
124+
"glob",
125+
"**/*.dist-info",
126+
os.path.join("workspace", "aws", "dist"),
127+
True
128+
),
120129
]
121130

122131
def test_build(self, fake_aws_cli_venv):

0 commit comments

Comments
 (0)