Skip to content

Commit

Permalink
fix: better env management
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbraun89 authored Mar 12, 2023
1 parent 372daf3 commit c137aaa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
8 changes: 5 additions & 3 deletions dcontainer/cli/generate/file_models/dependencies_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
)
18 changes: 11 additions & 7 deletions dcontainer/oci/oci_feature_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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] = ""
Expand Down
11 changes: 6 additions & 5 deletions dcontainer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit c137aaa

Please sign in to comment.