From c137aaaedc273a5a200fd34a42d4d1dfb1d9ff17 Mon Sep 17 00:00:00 2001 From: Daniel Braun Date: Sun, 12 Mar 2023 15:26:54 +0000 Subject: [PATCH] fix: better env management --- .../generate/file_models/dependencies_sh.py | 8 +++++--- dcontainer/oci/oci_feature_installer.py | 18 +++++++++++------- dcontainer/settings.py | 11 ++++++----- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/dcontainer/cli/generate/file_models/dependencies_sh.py b/dcontainer/cli/generate/file_models/dependencies_sh.py index bd871a21..2a2562bf 100644 --- a/dcontainer/cli/generate/file_models/dependencies_sh.py +++ b/dcontainer/cli/generate/file_models/dependencies_sh.py @@ -7,7 +7,7 @@ FeatureDependencies, FeatureDependency, ) -from dcontainer.settings import ENV_CLI_LOCATION, ENV_REUSE_CLI_LOCATION +from dcontainer.settings import ENV_CLI_LOCATION, ENV_FORCE_CLI_INSTALLATION DCONTAINER_LINK = "https://github.com/devcontainers-contrib/cli/releases/download/v0.0.27beta15/dcontainer" @@ -27,8 +27,10 @@ fi # Download the dcontainer cli program + + dcontainer_location="" -if [[ -z "${{{reuse_cli_location_env}}}" ]]; then +if [[ -z "${{{force_cli_installation_env}}}" ]]; then if [[ -z "${{{cli_location_env}}}" ]]; then if type dcontainer >/dev/null 2>&1; then dcontainer_location=dcontainer @@ -140,6 +142,6 @@ def to_str(self) -> str: ), dcontainer_link=DCONTAINER_LINK, checksums_link=CHECKSUM_LINK, - reuse_cli_location_env=ENV_REUSE_CLI_LOCATION, + force_cli_installation_env=ENV_FORCE_CLI_INSTALLATION, cli_location_env=ENV_CLI_LOCATION ) diff --git a/dcontainer/oci/oci_feature_installer.py b/dcontainer/oci/oci_feature_installer.py index 0a49837b..1cf93bb5 100644 --- a/dcontainer/oci/oci_feature_installer.py +++ b/dcontainer/oci/oci_feature_installer.py @@ -9,7 +9,7 @@ from dcontainer.models.devcontainer_feature import Feature from dcontainer.oci.oci_feature import OCIFeature -from dcontainer.settings import DContainerSettings, ENV_CLI_LOCATION, ENV_PROPAGATE_CLI_LOCATION, ENV_REUSE_CLI_LOCATION +from dcontainer.settings import DContainerSettings, ENV_CLI_LOCATION, ENV_PROPAGATE_CLI_LOCATION, ENV_FORCE_CLI_INSTALLATION, ENV_VERBOSE logger = logging.getLogger(__name__) @@ -58,14 +58,18 @@ def install( try: settings = DContainerSettings() - if settings.verbose is not None: - verbose = settings.verbose + if settings.verbose == "1": + verbose = True - env_variables[ENV_REUSE_CLI_LOCATION] = str(settings.reuse_cli_location) - env_variables[ENV_PROPAGATE_CLI_LOCATION] = str(settings.propagate_cli_location) + env_variables[ENV_VERBOSE] = settings.verbose + env_variables[ENV_FORCE_CLI_INSTALLATION] = settings.force_cli_installation + env_variables[ENV_PROPAGATE_CLI_LOCATION] = settings.propagate_cli_location - if settings.propagate_cli_location and getattr(sys, 'frozen', False): - env_variables[ENV_CLI_LOCATION] = sys.executable + if settings.propagate_cli_location == "1": + if settings.cli_location != "": + env_variables[ENV_CLI_LOCATION] = settings.cli_location + elif getattr(sys, 'frozen', False): + env_variables[ENV_CLI_LOCATION] = sys.executable else: # override it with empty string in case it already exists env_variables[ENV_CLI_LOCATION] = "" diff --git a/dcontainer/settings.py b/dcontainer/settings.py index 82bf3588..6480692d 100644 --- a/dcontainer/settings.py +++ b/dcontainer/settings.py @@ -7,11 +7,12 @@ class DContainerSettings(BaseSettings): class Config: env_prefix = "DCONTAINER_" - cli_location: Optional[str] = "" - propagate_cli_location: Optional[bool] = True - reuse_cli_location: Optional[bool] = True - verbose: Optional[bool] = None + cli_location: str = "" + propagate_cli_location: str = "1" + force_cli_installation: str = "" + verbose: str = "" ENV_CLI_LOCATION = f"{DContainerSettings.Config.env_prefix}CLI_LOCATION" ENV_PROPAGATE_CLI_LOCATION = f"{DContainerSettings.Config.env_prefix}PROPAGATE_CLI_LOCATION" -ENV_REUSE_CLI_LOCATION = f"{DContainerSettings.Config.env_prefix}REUSE_CLI_LOCATION" +ENV_FORCE_CLI_INSTALLATION = f"{DContainerSettings.Config.env_prefix}FORCE_CLI_INSTALLATION" +ENV_VERBOSE = f"{DContainerSettings.Config.env_prefix}VERBOSE"