Skip to content

Commit

Permalink
chore: make the package compatible with pydantic v2 (#79)
Browse files Browse the repository at this point in the history
* chore: make the package compatible with pydantic v2

* fix(typing): solve error in InstallConfig

* fix(mypy): fix typing errors errors and update handle Result interface

* fix(tests): add tests/__init__.py

* fix(tests): remove end2end test for a deprecated version of meiga (<1.5.0)

* fix(requirements): update mypy

* chore: set open pydantic version requirement
  • Loading branch information
acostapazo authored Jun 21, 2023
1 parent 2fd187d commit cc66028
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 30 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,4 @@ jobs:
env:
LUME_CONFIG_FILENAME: examples/lume-sample-with-syntax-error.yml
run: lume -job | true
- name: End2end test (With meiga version lower than 1.5.0)
env:
LUME_CONFIG_FILENAME: examples/lume-sample.yml
run: |
pip uninstall meiga -y
pip install "meiga<1.5.0" # force lower version of meiga
lume -install -all
pip install -U meiga # force curent version of meiga (we don't want to corrupt the following steps)

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
hooks:
- id: black
name: black
entry: black .
entry: black lume tests
language: system
types: [ python ]

Expand All @@ -15,6 +15,6 @@ repos:

- id: isort
name: isort
entry: isort .
entry: isort lume tests
language: system
types: [ python ]
12 changes: 6 additions & 6 deletions lume/config/install_config.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from typing import Dict, List, Optional
from typing import Dict, List, Union

from pydantic import BaseModel
from pydantic import BaseModel, Field

from lume.config.check_os_list_or_str_item import check_os_list_or_str_item
from lume.config.get_envs import get_envs


class InstallConfig(BaseModel):
run: List[str]
cwd: Optional[str] = None
envs: Dict[str, str] = dict()
overwrote_envs: List[str] = list()
run: List[str] = Field()
cwd: Union[str, None] = Field(default=None)
envs: Dict[str, str] = Field(default=dict())
overwrote_envs: List[str] = Field(default=list())

def add_shared_env(self, shared_envs: Dict[str, str]):
if shared_envs and self.envs:
Expand Down
4 changes: 2 additions & 2 deletions lume/config/step_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List, Optional
from typing import Any, Dict, List, Optional

from pydantic import BaseModel

Expand All @@ -10,7 +10,7 @@
class StepConfig(BaseModel):
run: List[str]
cwd: Optional[str] = None
envs: Dict[str, str] = dict()
envs: Dict[str, Any] = dict()
setup: Optional[List[str]] = None
teardown: Optional[List[str]] = None
setup_detach: Optional[Dict] = None
Expand Down
44 changes: 36 additions & 8 deletions lume/src/application/use_cases/lume_use_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
from typing import List, Tuple, Union

import requests
from meiga import Error, Failure, Result, Success, isFailure, isSuccess
from meiga import (
Error,
Failure,
OnFailureHandler,
Result,
Success,
isFailure,
isSuccess,
)
from meiga.decorators import meiga

from lume.config import Config
Expand Down Expand Up @@ -84,20 +92,32 @@ def execute(self, steps: List[str]):
else:
cwd = (
self._get_cwd(step)
.handle(on_failure=on_error_with_cwd, failure_args=(self, step))
.handle(
on_failure_handler=OnFailureHandler(
func=on_error_with_cwd, args=(self, step)
)
)
.unwrap_or_return()
)

self._set_env(step)
processes: List = (
self._run_setup_detach(step, cwd)
.handle(on_failure=self._run_teardown, failure_args=(cwd, step))
.handle(
on_failure_handler=OnFailureHandler(
func=self._run_teardown, args=(cwd, step)
)
)
.unwrap_or([])
)
self._run_setup(step, cwd).handle(
on_failure=self._run_teardown_detach, failure_args=processes
on_failure_handler=OnFailureHandler(
func=self._run_teardown_detach, args=processes
)
).handle(
on_failure=self._run_teardown, failure_args=(cwd, step)
on_failure_handler=OnFailureHandler(
func=self._run_teardown, args=(cwd, step)
)
).unwrap_or_return()
self._run_commands(step, cwd, processes).unwrap_or_return()
self._run_teardown_detach(processes)
Expand Down Expand Up @@ -227,16 +247,24 @@ def _run_commands(self, step, cwd, processes) -> Result:
self._wait_if_necessary(step)
commands: List[str] = (
self._get_commands(step)
.handle(on_failure=on_empty_config, failure_args=(self, step))
.handle(
on_failure_handler=OnFailureHandler(
func=on_empty_config, args=(self, step)
)
)
.unwrap_or([])
)
for command in commands:
message = get_colored_command_message(command, cwd, step)
self.logger.log(COMMAND, message)
self.executor_service.execute(command, cwd).handle(
on_failure=self._run_teardown_detach, failure_args=processes
on_failure_handler=OnFailureHandler(
func=self._run_teardown_detach, args=processes
)
).handle(
on_failure=self._run_teardown, failure_args=(cwd, step)
on_failure_handler=OnFailureHandler(
func=self._run_teardown, args=(cwd, step)
)
).unwrap_or_return()

return isSuccess
Expand Down
3 changes: 2 additions & 1 deletion lume/src/infrastructure/services/setup/setup_item_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Union
from zipfile import BadZipFile

import requests
Expand Down Expand Up @@ -47,7 +48,7 @@ def run(
return Success()

@staticmethod
def __download_file(dst: str, url: str, auth: HTTPBasicAuth = None):
def __download_file(dst: str, url: str, auth: Union[HTTPBasicAuth, None] = None):
r = requests.get(url, auth=auth, stream=True)
dst_filename = os.path.split(url)[-1]
with open(os.path.join(dst, dst_filename), "wb") as f:
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
black==22.3.0
flake8==4.0.1
isort[colors]==5.10.1
mypy==0.961
mypy==1.4.0
pre-commit==2.19.0
safety==1.10.3
pytest==7.1.2
Expand Down
4 changes: 2 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meiga<2
pydantic<2
meiga>=1.5.0,<2
pydantic<3
pyyaml<7
google-cloud-storage>= 1.32.0, < 3.0.0dev
google-api-core<3
Expand Down
Empty file added tests/__init__.py
Empty file.

0 comments on commit cc66028

Please sign in to comment.