Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/remove set global environment prompt when no global env is defined #58

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/lume-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ steps:
teardown: echo ${TEADOWN_MSG}
run: echo ${RUN_MSG}
setup-detach-example:
env:
SETUP_MSG: Setup
TEADOWN_MSG: Teardown
RUN_MSG: Run
setup_detach:
run: echo ${SETUP_MSG}-detach
setup: echo ${SETUP_MSG}
teardown: echo ${TEADOWN_MSG}
run: echo ${RUN_MSG}
setup-detach-example-set-filename:
env:
SETUP_MSG: Setup
TEADOWN_MSG: Teardown
Expand Down
7 changes: 4 additions & 3 deletions lume/src/application/use_cases/env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ def __init__(self, logger: Logger):
self.logger = logger

def set(self, envs: Dict[str, str]) -> None:
self.logger.log(
GLOBAL, f"{Colors.OKGREEN}Set Global Environment Variables{Colors.ENDC}"
)
if envs:
self.logger.log(
GLOBAL, f"{Colors.OKGREEN}Set Global Environment Variables{Colors.ENDC}"
)
for envar, value in envs.items():
env_original_value = os.environ.get(envar)
os.environ[envar] = str(value)
Expand Down
12 changes: 6 additions & 6 deletions lume/src/application/use_cases/lume_use_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def on_error_with_cwd(self, action):
)


SETUP_DETACH_DEFAULT_LOG_FILENAME = "setup_detach.log"
SETUP_DETACH_DEFAULT_LOG_FILENAME = "lume.setup_detach.log"


class LumeUseCase:
Expand Down Expand Up @@ -291,12 +291,12 @@ def _get_setup_detach_commands(
if not setup_detach or not setup_detach.get("run"):
return isFailure

return Success(
(
setup_detach.get("run"),
setup_detach.get("log_filename", SETUP_DETACH_DEFAULT_LOG_FILENAME),
return Success(
(
setup_detach.get("run"),
setup_detach.get("log_filename", f"lume.{action}.setup_detach.log"),
)
)
)

def _get_teardown_commands(self, action) -> Result[List[str], Error]:
if action in ["install", "uninstall"]:
Expand Down
4 changes: 3 additions & 1 deletion lume/src/domain/services/executor_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

from meiga import Error, NotImplementedMethodError, Result

DEFAULT_EXECUTOR_LOG_FILENAME = "lume.executor.log"


class ExecutorService(ABC):
@abstractmethod
def execute(self, command: str, cwd: str) -> Result[bool, Error]:
def execute(self, command: str, cwd: str, log_filename: str) -> Result[bool, Error]:
return NotImplementedMethodError
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from meiga import Error, Result, Success

from lume.src.domain.services.executor_service import ExecutorService
from lume.src.domain.services.executor_service import (
DEFAULT_EXECUTOR_LOG_FILENAME,
ExecutorService,
)
from lume.src.domain.services.logger import INFO, Logger


Expand All @@ -11,7 +14,7 @@ def __init__(self, logger: Logger):
self.logger = logger

def execute(
self, command: str, cwd: str, log_filename="setup_detach.log"
self, command: str, cwd: str, log_filename: str = DEFAULT_EXECUTOR_LOG_FILENAME
) -> Result[bool, Error]:

if not cwd:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from meiga import Error, Result, isSuccess

from lume.src.domain.services.executor_service import ExecutorService
from lume.src.domain.services.executor_service import (
DEFAULT_EXECUTOR_LOG_FILENAME,
ExecutorService,
)


class FakeExecutorService(ExecutorService):
def execute(self, command: str, cwd: str) -> Result[bool, Error]:
def execute(
self, command: str, cwd: str, log_filename: str = DEFAULT_EXECUTOR_LOG_FILENAME
) -> Result[bool, Error]:
print("executing")
return isSuccess
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

from meiga import Error, Result, isFailure, isSuccess

from lume.src.domain.services.executor_service import ExecutorService
from lume.src.domain.services.executor_service import (
DEFAULT_EXECUTOR_LOG_FILENAME,
ExecutorService,
)
from lume.src.domain.services.logger import ERROR, INFO, WARNING, Logger


class PopenExecutorService(ExecutorService):
def __init__(self, logger: Logger):
self.logger = logger

def execute(self, command: str, cwd: str) -> Result[bool, Error]:
def execute(
self, command: str, cwd: str, log_filename: str = DEFAULT_EXECUTOR_LOG_FILENAME
) -> Result[bool, Error]:

if not cwd:
cwd = "."
Expand Down
4 changes: 4 additions & 0 deletions tests/src/mothers/config_mother.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ class ConfigMother:
@staticmethod
def any():
return get_config("examples/lume-any.yml").unwrap_or_throw()

@staticmethod
def with_global_env():
return get_config("examples/lume-sample.yml").unwrap_or_throw()
33 changes: 20 additions & 13 deletions tests/src/test_lume_use_case.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from lume.src.application.use_cases.lume_use_case import LumeUseCase
from lume.src.domain.services.logger import GLOBAL, HIGHLIGHT
from lume.src.domain.services.logger import GLOBAL
from lume.src.infrastructure.services.executor.fake_executor_service import (
FakeExecutorService,
)
Expand All @@ -14,11 +14,24 @@
from tests.src.mothers.config_mother import ConfigMother


def assert_logging_messages(logging_messages: list, with_global_envs: bool):
first_logging_message = logging_messages[0]
if with_global_envs:
assert first_logging_message == (
GLOBAL,
f"{Colors.OKGREEN}Set Global Environment Variables{Colors.ENDC}",
)


@pytest.mark.unit
@pytest.mark.parametrize("given_command", ["install", "uninstall", "setup"])
def test_should_repr_as_expected_an_error_with_message(given_command):
@pytest.mark.parametrize(
"config,logging_messages_with_global_envs",
[(ConfigMother.any(), False), (ConfigMother.with_global_env(), True)],
)
def test_should_repr_as_expected_an_error_with_message(
config, logging_messages_with_global_envs
):

config = ConfigMother.any()
fake_executor_service = FakeExecutorService()
fake_detach_executor_service = FakeExecutorService()
fake_detach_killer_service = FakeKillerService()
Expand All @@ -36,13 +49,7 @@ def test_should_repr_as_expected_an_error_with_message(given_command):
logger=fake_logger,
)

lume_use_case.execute([f"{given_command}"])

first_logging_message = fake_logger.get_logging_messages()[0]
second_logging_message = fake_logger.get_logging_messages()[1]

assert first_logging_message == (
GLOBAL,
f"{Colors.OKGREEN}Set Global Environment Variables{Colors.ENDC}",
lume_use_case.execute(config.get_commands())
assert_logging_messages(
fake_logger.get_logging_messages(), logging_messages_with_global_envs
)
assert second_logging_message == (HIGHLIGHT, f"Step: {given_command}")