Skip to content

Commit

Permalink
feedback from PR: return enum
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <[email protected]>
  • Loading branch information
mr-cal committed Sep 7, 2023
1 parent b9f29cc commit d5c8a45
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions snapcraft/commands/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,28 @@ def fill_parser(self, parser: argparse.ArgumentParser) -> None:
help="acknowledge that uploaded code will be publicly available.",
)

def _get_build_strategy(self) -> Optional[str]:
def _get_build_strategy(self) -> Optional[_Strategies]:
"""Get the build strategy from the envvar `SNAPCRAFT_REMOTE_BUILD_STRATEGY`.
:returns: A string of the strategy or None.
:returns: The strategy or None.
:raises SnapcraftError: If the variable is set to an invalid value.
"""
all_strategies = {strategy.value for strategy in _Strategies}

strategy = os.getenv(_STRATEGY_ENVVAR)

if strategy and strategy not in all_strategies:
if not strategy:
return None

try:
return _Strategies(strategy)
except ValueError as err:
valid_strategies = humanize_list(
(strategy.value for strategy in _Strategies), "and"
)
raise SnapcraftError(
f"Unknown value {strategy!r} in environment variable "
f"{_STRATEGY_ENVVAR!r}. Valid values are "
f"{humanize_list(all_strategies, 'and')}."
)

return strategy
f"{_STRATEGY_ENVVAR!r}. Valid values are {valid_strategies}."
) from err

def _get_effective_base(self) -> str:
"""Get a valid effective base from the project's snapcraft.yaml.
Expand Down Expand Up @@ -162,7 +165,7 @@ def _run_remote_build(self, base: str) -> None:

strategy = self._get_build_strategy()

if strategy == _Strategies.DISABLE_FALLBACK.value:
if strategy == _Strategies.DISABLE_FALLBACK:
emit.debug(
f"Environment variable {_STRATEGY_ENVVAR!r} is "
f"{_Strategies.DISABLE_FALLBACK.value!r} but running fallback "
Expand All @@ -171,7 +174,7 @@ def _run_remote_build(self, base: str) -> None:
run_legacy()
return

if strategy == _Strategies.FORCE_FALLBACK.value:
if strategy == _Strategies.FORCE_FALLBACK:
emit.debug(
"Running fallback remote-build because environment variable "
f"{_STRATEGY_ENVVAR!r} is {_Strategies.FORCE_FALLBACK.value!r}."
Expand Down

0 comments on commit d5c8a45

Please sign in to comment.