Skip to content

Commit

Permalink
lint with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
killian-scalian committed Oct 14, 2024
1 parent 36069c9 commit 08e65bf
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 216 deletions.
40 changes: 13 additions & 27 deletions src/antares/service/local_services/area_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ def _line_exists_in_file(file_content: str, line_to_add: str) -> bool:
areas_ini.add_section({"unserverdenergycost": {}})
areas_ini.add_section({"spilledenergycost": {}})
areas_ini.write_ini_file()
areas_ini.parsed_ini["unserverdenergycost"][
area_name
] = local_properties.nodal_optimization["average-unsupplied-energy-cost"]
areas_ini.parsed_ini["spilledenergycost"][
area_name
] = local_properties.nodal_optimization["average-spilled-energy-cost"]
areas_ini.parsed_ini["unserverdenergycost"][area_name] = local_properties.nodal_optimization[
"average-unsupplied-energy-cost"
]
areas_ini.parsed_ini["spilledenergycost"][area_name] = local_properties.nodal_optimization[
"average-spilled-energy-cost"
]
areas_ini.write_ini_file()

local_ui = AreaUiLocal(ui) if ui else AreaUiLocal()
Expand Down Expand Up @@ -325,13 +325,9 @@ def read_thermal_cluster(
thermal_name: str,
properties: Optional[ThermalClusterProperties] = None,
) -> ThermalCluster:
local_thermal_properties = ThermalClusterPropertiesLocal(
thermal_name, properties
)
local_thermal_properties = ThermalClusterPropertiesLocal(thermal_name, properties)

list_ini = IniFile(
self.config.study_path, IniFileTypes.THERMAL_LIST_INI, area_name=area_id
)
list_ini = IniFile(self.config.study_path, IniFileTypes.THERMAL_LIST_INI, area_name=area_id)
list_ini.add_section(local_thermal_properties.list_ini_fields)
list_ini.write_ini_file(sort_sections=True)

Expand Down Expand Up @@ -369,9 +365,7 @@ def read_st_storage(
) -> STStorage:
local_st_storage_properties = STStoragePropertiesLocal(st_storage_name, properties)

list_ini = IniFile(
self.config.study_path, IniFileTypes.ST_STORAGE_LIST_INI, area_name=area_id
)
list_ini = IniFile(self.config.study_path, IniFileTypes.ST_STORAGE_LIST_INI, area_name=area_id)
list_ini.add_section(local_st_storage_properties.list_ini_fields)
list_ini.write_ini_file(sort_sections=True)

Expand Down Expand Up @@ -438,27 +432,19 @@ def _line_exists_in_file(file_content: str, line_to_add: str) -> bool:
existing_path = self.config.local_path
study_path = existing_path / self.study_name

optimization_ini = IniFile(
study_path, IniFileTypes.AREA_OPTIMIZATION_INI, area_name
).parsed_ini
optimization_ini = IniFile(study_path, IniFileTypes.AREA_OPTIMIZATION_INI, area_name).parsed_ini

dict_optimization = {
section: {key: f"{value}" for key, value in optimization_ini.items(section)}
for section in optimization_ini.sections()
}

ui_ini = IniFile(study_path, IniFileTypes.AREA_UI_INI, area_name).parsed_ini
dict_ui = {
section: {key: f"{value}" for key, value in ui_ini.items(section)}
for section in ui_ini.sections()
}
dict_ui = {section: {key: f"{value}" for key, value in ui_ini.items(section)} for section in ui_ini.sections()}

patch_ini = IniFile(
study_path, IniFileTypes.AREA_ADEQUACY_PATCH_INI, area_name
).parsed_ini
patch_ini = IniFile(study_path, IniFileTypes.AREA_ADEQUACY_PATCH_INI, area_name).parsed_ini
dict_adequacy_patch = {
section: {key: f"{value}" for key, value in patch_ini.items(section)}
for section in patch_ini.sections()
section: {key: f"{value}" for key, value in patch_ini.items(section)} for section in patch_ini.sections()
}

return [dict_optimization, dict_ui, dict_adequacy_patch]
16 changes: 4 additions & 12 deletions src/antares/service/local_services/study_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@


class StudyLocalService(BaseStudyService):
def __init__(
self, config: LocalConfiguration, study_name: Path, **kwargs: Any
) -> None:
def __init__(self, config: LocalConfiguration, study_name: Path, **kwargs: Any) -> None:
super().__init__(**kwargs)
self._config = config
self._study_name = study_name
Expand All @@ -51,25 +49,19 @@ def read_areas(self) -> json:

patch_path = local_path / self._study_name / Path("patch.json")
if not os.path.exists(patch_path):
return json.loads(
f"Le fichier {patch_path} n'existe pas dans le dossier {local_path / self._study_name}"
)
return json.loads(f"Le fichier {patch_path} n'existe pas dans le dossier {local_path / self._study_name}")
try:
with open(patch_path, "r") as file:
content = file.read()
try:
data = json.loads(content)
except json.JSONDecodeError:
return json.loads(
f"Le fichier {patch_path} ne contient pas du JSON valide"
)
return json.loads(f"Le fichier {patch_path} ne contient pas du JSON valide")
if "areas" in data:
areas = data["areas"]
if isinstance(areas, dict):
return list(areas.keys())
else:
return json.loads(
f"The key 'areas' n'existe pas dans le fichier JSON"
)
return json.loads(f"The key 'areas' n'existe pas dans le fichier JSON")
except IOError:
return f"Impossible de lire le fichier {patch_path}"
Loading

0 comments on commit 08e65bf

Please sign in to comment.