Skip to content

Commit

Permalink
Update metadata distribution field
Browse files Browse the repository at this point in the history
When building a portable exe dist from source you will now get the
distribuiton metadtata "source-exe".

When building a system-sandbox dist from source you will now get the
distribuiton metadtata "source-sandbox".
  • Loading branch information
stealthycoin committed Oct 24, 2022
1 parent 100ea4e commit 9b05024
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
8 changes: 8 additions & 0 deletions backends/build_system/awscli_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
BIN_DIRNAME,
PYTHON_EXE_NAME,
CLI_SCRIPTS,
DISTRIBUTION_SOURCE_SANDBOX,
)
from utils import Utils

Expand Down Expand Up @@ -56,6 +57,7 @@ def bootstrap(
else:
self._copy_parent_packages()
self._install_awscli()
self._update_metadata()
self._update_windows_script_header()

def _copy_parent_packages(self):
Expand Down Expand Up @@ -103,6 +105,12 @@ def _update_windows_script_header(self):
lines[0] = self._utils.get_script_header(python_exe_path)
self._utils.write_file(exe_path, "".join(lines))

def _update_metadata(self):
self._utils.update_metadata(
self._site_packages(),
distribution_source=DISTRIBUTION_SOURCE_SANDBOX,
)

@property
def bin_dir(self):
return os.path.join(self._venv_dir, BIN_DIRNAME)
Expand Down
3 changes: 2 additions & 1 deletion backends/build_system/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
INSTALL_DIRNAME = "aws-cli"


DISTRIBUTION_SOURCE = "exe"
DISTRIBUTION_SOURCE_EXE = "source-exe"
DISTRIBUTION_SOURCE_SANDBOX = "source-sandbox"


class ArtifactType(Enum):
Expand Down
13 changes: 8 additions & 5 deletions backends/build_system/exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os
from dataclasses import dataclass, field

from constants import EXE_ASSETS_DIR, PYINSTALLER_DIR, DISTRIBUTION_SOURCE, PYINSTALLER_EXE_NAME
from constants import EXE_ASSETS_DIR, PYINSTALLER_DIR, DISTRIBUTION_SOURCE_EXE, PYINSTALLER_EXE_NAME
from utils import Utils
from awscli_venv import AwsCliVenv

Expand Down Expand Up @@ -41,20 +41,23 @@ def build(self, cleanup=True):
self._build_aws()
self._build_aws_completer()
self._utils.copy_directory_contents_into(EXE_ASSETS_DIR, self._exe_dir)
self._update_metadata()
if cleanup:
self._cleanup()
print(f"Built exe at {self._exe_dir}")

def _update_metadata(self):
self._utils.update_metadata(
self._final_dist_dir,
distribution_source=DISTRIBUTION_SOURCE_EXE,
)

def _ensure_no_existing_build_dir(self):
if self._utils.isdir(self._dist_dir):
self._utils.rmtree(self._dist_dir)

def _build_aws(self):
aws_exe_build_dir = self._run_pyinstaller("aws.spec")
self._utils.update_metadata(
aws_exe_build_dir,
distribution_source=DISTRIBUTION_SOURCE,
)
self._utils.copy_directory(aws_exe_build_dir, self._final_dist_dir)

def _build_aws_completer(self):
Expand Down
12 changes: 6 additions & 6 deletions tests/backends/build_system/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def expected_python_version(self):
python_info = sys.version_info
return f"{python_info.major}.{python_info.minor}.{python_info.micro}"

def assert_version_string_is_correct(self, exe_path):
def assert_version_string_is_correct(self, exe_path, dist_type):
version_string = subprocess.check_output(
[str(exe_path), "--version"]
).decode()

assert f"aws-cli/{self.expected_cli_version()}" in version_string
assert f"Python/{self.expected_python_version()}" in version_string
assert "source/" in version_string
assert f"source-{dist_type}" in version_string

def assert_built_venv_is_correct(self, venv_dir):
self.assert_venv_is_correct(venv_dir)
Expand All @@ -70,7 +70,7 @@ def assert_built_venv_is_correct(self, venv_dir):
# The venv after building also includes the binary
assert BIN_DIRNAME in files
aws_exe = venv_dir / BIN_DIRNAME / CLI_SCRIPT_NAME
self.assert_version_string_is_correct(aws_exe)
self.assert_version_string_is_correct(aws_exe, "sandbox")

def assert_venv_is_correct(self, venv_dir):
files = os.listdir(venv_dir)
Expand All @@ -90,13 +90,13 @@ def assert_built_exe_is_correct(self, root_dir):
}

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

def assert_installed_exe_is_correct(self, exe_dir):
self.assert_version_string_is_correct(exe_dir / CLI_SCRIPT_NAME)
self.assert_version_string_is_correct(exe_dir / CLI_SCRIPT_NAME, "exe")

def assert_installed_venv_is_correct(self, exe_dir, lib_dir):
self.assert_version_string_is_correct(exe_dir / CLI_SCRIPT_NAME)
self.assert_version_string_is_correct(exe_dir / CLI_SCRIPT_NAME, "sandbox")
self.assert_venv_is_correct(lib_dir / "aws-cli")


Expand Down
2 changes: 1 addition & 1 deletion tests/backends/build_system/integration/test_makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def assert_venv_installed_correctly(self, bin_path, lib_path):
assert bins == {"aws", "aws_completer"}

aws_exe = bin_path / "aws"
self.assert_version_string_is_correct(aws_exe)
self.assert_version_string_is_correct(aws_exe, "sandbox")

@skip_if_windows(WINDOWS_SKIP_REASON)
def test_install(self, workspace: VEnvWorkspace):
Expand Down
12 changes: 7 additions & 5 deletions tests/backends/build_system/unit/test_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ def _expected_build_tasks(self):
],
{"cwd": PYINSTALLER_DIR, "check": True},
),
(
"update_metadata",
os.path.join("workspace", "dist", "aws"),
{"distribution_source": "exe"},
),
(
"copy_directory",
os.path.join("workspace", "dist", "aws"),
Expand Down Expand Up @@ -115,6 +110,13 @@ def _expected_build_tasks(self):
EXE_ASSETS_DIR,
os.path.join("workspace", "aws"),
),
# Update metadata
(
"update_metadata",
os.path.join("workspace", "aws", "dist"),
{"distribution_source": "source-exe"},
),

]

def test_build(self, fake_aws_cli_venv):
Expand Down

0 comments on commit 9b05024

Please sign in to comment.