Skip to content

Commit

Permalink
typing
Browse files Browse the repository at this point in the history
  • Loading branch information
killian-scalian committed Dec 17, 2024
1 parent 82852f0 commit 094e172
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/andromede/input_converter/src/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

from pathlib import Path
from antares.model.study import read_study_local, Study
from typing import Optional
from pydantic import BaseModel
Expand All @@ -23,24 +23,24 @@


class StudyConverter:
def __init__(self, study_path: Optional[str]):
def __init__(self, study_path: Optional[Path]):
"""
Initialize processor
"""
self.study_path = resolve_path(study_path) if study_path else None
self.study = None
self.study: Study = None

def load_study(self) -> Study:
return read_study_local(self.study_path)

def convert_study_to_input_components(self):
def convert_study_to_input_components(self) -> BaseModel:
areas = self.study.read_areas()
convert_area_to_components(areas)
return convert_area_to_components(areas)

def validate_with_pydantic(self, data, model_class) -> BaseModel:
def validate_with_pydantic(self, data: dict, model_class: type[BaseModel]) -> BaseModel:
return model_class(**data)

def transform_to_yaml(self, data, output_path):
def transform_to_yaml(self, data: dict, output_path: str) -> None:
with open(output_path, "w") as yaml_file:
yaml.dump(data, yaml_file)

Expand Down
6 changes: 3 additions & 3 deletions src/andromede/input_converter/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def parse_commandline() -> argparse.Namespace:
return parser.parse_args()


def handle_env(config_parser) -> dict:
def handle_env(config_parser: configparser.ConfigParser) -> dict:
# Read configuration items from the config parser and set them as environment variables.
# Return a dictionary of the environment variables that were set.
config_env = {}
Expand All @@ -139,7 +139,7 @@ def handle_env(config_parser) -> dict:
os.environ[env_name] = value
config_env.update({env_name: value})
else:
config_env.update({env_name: os.environ.get(env_name)})
config_env.update({env_name: os.environ.get(env_name, "")})
return config_env


Expand All @@ -160,5 +160,5 @@ def handle_env(config_parser) -> dict:
config_parser.read(args.conf)

env_cfg = handle_env(config_parser)
processor = StudyConverter()
processor = StudyConverter(study_path=None)
processor.process_all()
2 changes: 1 addition & 1 deletion src/andromede/input_converter/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pydantic import BaseModel


def resolve_path(path_str):
def resolve_path(path_str: Path) -> Path:
path = Path(path_str)
if not path.exists():
raise FileNotFoundError
Expand Down

0 comments on commit 094e172

Please sign in to comment.