Skip to content

Commit

Permalink
chore(all): format
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Leclerc <[email protected]>
  • Loading branch information
sylvlecl committed Feb 13, 2025
1 parent a088d9a commit d9f48cc
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 54 deletions.
12 changes: 9 additions & 3 deletions src/antares/craft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"read_study_api",
"create_variant_api",
"read_study_local",
"create_study_local"
"create_study_local",
]


Expand All @@ -38,16 +38,20 @@
# opposite. Here we perform dependency injection, and because of python
# import mechanics, we need to use local imports to avoid circular dependencies.


def create_study_local(study_name: str, version: str, parent_directory: "Path") -> "Study":
# Here we inject implementation of this method,
# we need to have a local import to avoid python circular dependency
from antares.craft.service.local_services.factory import create_study_local

return create_study_local(study_name, version, parent_directory)


def read_study_local(study_path: "Path") -> "Study":
# Here we inject implementation of this method,
# we need to have a local import to avoid python circular dependency
from antares.craft.service.local_services.factory import read_study_local

return read_study_local(study_path)


Expand All @@ -68,16 +72,19 @@ def create_study_api(
StudyCreationError if an HTTP Exception occurs
"""
from antares.craft.service.api_services.factory import create_study_api

return create_study_api(study_name, version, api_config, parent_path)


def import_study_api(api_config: APIconf, study_path: "Path", destination_path: "Optional[Path]" = None) -> "Study":
from antares.craft.service.api_services.factory import import_study_api

return import_study_api(api_config, study_path, destination_path)


def read_study_api(api_config: APIconf, study_id: str) -> "Study":
from antares.craft.service.api_services.factory import read_study_api

return read_study_api(api_config, study_id)


Expand All @@ -91,6 +98,5 @@ def create_variant_api(api_config: APIconf, study_id: str, variant_name: str) ->
Returns: The variant in the form of a Study object
"""
from antares.craft.service.api_services.factory import create_variant_api
return create_variant_api(api_config, study_id, variant_name)


return create_variant_api(api_config, study_id, variant_name)
1 change: 0 additions & 1 deletion src/antares/craft/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,3 @@ def move(self, parent_path: Path) -> None:

def generate_thermal_timeseries(self) -> None:
self._study_service.generate_thermal_timeseries()

4 changes: 1 addition & 3 deletions src/antares/craft/service/api_services/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def create_hydro_service(self) -> BaseHydroService:
return HydroApiService(self.config, self.study_id)



def create_study_api(
study_name: str,
version: str,
Expand Down Expand Up @@ -171,7 +170,6 @@ def import_study_api(api_config: APIconf, study_path: Path, destination_path: Op
raise StudyImportError(study_path.name, e.message) from e



def read_study_api(api_config: APIconf, study_id: str) -> "Study":
session = api_config.set_up_api_conf()
wrapper = RequestWrapper(session)
Expand Down Expand Up @@ -205,4 +203,4 @@ def create_variant_api(api_config: APIconf, study_id: str, variant_name: str) ->
factory = ApiServiceFactory(api_config, study_id)
api_service = factory.create_study_service()

return api_service.create_variant(variant_name)
return api_service.create_variant(variant_name)
1 change: 1 addition & 0 deletions src/antares/craft/service/api_services/study_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def delete(self, children: bool) -> None:
@override
def create_variant(self, variant_name: str) -> "Study":
from antares.craft.service.api_services.factory import read_study_api

url = f"{self._base_url}/studies/{self.study_id}/variants?name={variant_name}"
try:
response = self._wrapper.post(url)
Expand Down
9 changes: 4 additions & 5 deletions src/antares/craft/service/local_services/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import logging
import os
import time
from pathlib import Path

from typing_extensions import override
from pathlib import Path

from antares.craft.config.local_configuration import LocalConfiguration
from antares.craft.model.settings.study_settings import StudySettings
Expand Down Expand Up @@ -45,6 +44,7 @@
from antares.craft.service.local_services.study_local import StudyLocalService
from antares.craft.service.service_factory import ServiceFactory
from antares.craft.tools.ini_tool import IniFile, InitializationFilesTypes
from typing_extensions import override


class LocalServiceFactory(ServiceFactory):
Expand Down Expand Up @@ -108,7 +108,6 @@ def create_hydro_service(self) -> BaseHydroService:
return HydroLocalService(self.config, self.study_name)



def _create_correlation_ini_files(study_directory: Path) -> None:
correlation_inis_to_create = [
getattr(InitializationFilesTypes, field.upper() + "_CORRELATION_INI")
Expand All @@ -128,7 +127,6 @@ def _create_correlation_ini_files(study_directory: Path) -> None:
ini_file.write_ini_file()



def _verify_study_already_exists(study_directory: Path) -> None:
if study_directory.exists():
raise FileExistsError(f"Study {study_directory.name} already exists.")
Expand Down Expand Up @@ -157,6 +155,7 @@ def _create_directory_structure(study_path: Path) -> None:
for subdirectory in subdirectories:
(study_path / subdirectory).mkdir(parents=True, exist_ok=True)


def create_study_local(study_name: str, version: str, parent_directory: Path) -> "Study":
"""
Create a directory structure for the study with empty files.
Expand Down Expand Up @@ -248,4 +247,4 @@ def _directory_not_exists(local_path: Path) -> None:
path=study_directory,
)
study.read_settings()
return study
return study
8 changes: 0 additions & 8 deletions src/antares/craft/service/local_services/study_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
import logging
import os
import time
from pathlib import Path, PurePath
from typing import TYPE_CHECKING, Any

from antares.craft.config.local_configuration import LocalConfiguration
from antares.craft.model.binding_constraint import BindingConstraint
from antares.craft.model.output import Output
from antares.craft.model.settings.study_settings import StudySettings
from antares.craft.service.base_services import BaseOutputService, BaseStudyService
from typing_extensions import override

from antares.craft.service.local_services.services.settings import edit_study_settings
from antares.craft.service.service_factory import ServiceFactory
from antares.craft.tools.ini_tool import InitializationFilesTypes, IniFile

if TYPE_CHECKING:
from antares.craft.model.study import Study

Expand Down
36 changes: 11 additions & 25 deletions src/antares/craft/service/service_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,34 @@ class ServiceFactory(ABC):
"""

@abstractmethod
def create_area_service(self) -> BaseAreaService:
...
def create_area_service(self) -> BaseAreaService: ...

@abstractmethod
def create_link_service(self) -> BaseLinkService:
...
def create_link_service(self) -> BaseLinkService: ...

@abstractmethod
def create_thermal_service(self) -> BaseThermalService:
...
def create_thermal_service(self) -> BaseThermalService: ...

@abstractmethod
def create_binding_constraints_service(self) -> BaseBindingConstraintService:
...
def create_binding_constraints_service(self) -> BaseBindingConstraintService: ...

@abstractmethod
def create_study_service(self) -> BaseStudyService:
...
def create_study_service(self) -> BaseStudyService: ...

@abstractmethod
def create_renewable_service(self) -> BaseRenewableService:
...
def create_renewable_service(self) -> BaseRenewableService: ...

@abstractmethod
def create_st_storage_service(self) -> BaseShortTermStorageService:
...
def create_st_storage_service(self) -> BaseShortTermStorageService: ...

@abstractmethod
def create_run_service(self) -> BaseRunService:
...
def create_run_service(self) -> BaseRunService: ...

@abstractmethod
def create_output_service(self) -> BaseOutputService:
...
def create_output_service(self) -> BaseOutputService: ...

@abstractmethod
def create_settings_service(self) -> BaseStudySettingsService:
...
def create_settings_service(self) -> BaseStudySettingsService: ...

@abstractmethod
def create_hydro_service(self) -> BaseHydroService:
...



def create_hydro_service(self) -> BaseHydroService: ...
2 changes: 1 addition & 1 deletion tests/antares/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import pytest

from antares.craft.model.area import Area
from antares.craft import Study, create_study_local
from antares.craft.model.area import Area


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion tests/antares/services/api_services/test_area_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
#
# This file is part of the Antares project.

import pandas as pd
import pytest
import requests_mock

import pandas as pd

from antares.craft.api_conf.api_conf import APIconf
from antares.craft.exceptions.exceptions import (
AreaPropertiesUpdateError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from antares.craft.model.binding_constraint import BindingConstraint, BindingConstraintProperties, ConstraintMatrixName
from antares.craft.model.study import Study
from antares.craft.service.api_services.factory import ApiServiceFactory
from antares.craft.service.service_factory import ServiceFactory


@pytest.fixture
Expand Down
1 change: 0 additions & 1 deletion tests/antares/services/api_services/test_link_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from antares.craft.model.link import Link, LinkProperties, LinkUi
from antares.craft.model.study import Study
from antares.craft.service.api_services.factory import ApiServiceFactory
from antares.craft.service.service_factory import ServiceFactory


@pytest.fixture()
Expand Down
1 change: 0 additions & 1 deletion tests/antares/services/api_services/test_matrix_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from antares.craft.model.area import Area
from antares.craft.model.hydro import Hydro, HydroProperties
from antares.craft.service.api_services.factory import ApiServiceFactory
from antares.craft.service.service_factory import ServiceFactory


class TestMatrixAPI:
Expand Down
1 change: 0 additions & 1 deletion tests/antares/services/api_services/test_renewable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from antares.craft.service.api_services.factory import ApiServiceFactory
from antares.craft.service.api_services.models.renewable import RenewableClusterPropertiesAPI
from antares.craft.service.api_services.services.renewable import RenewableApiService
from antares.craft.service.service_factory import ServiceFactory


class TestCreateAPI:
Expand Down
1 change: 0 additions & 1 deletion tests/antares/services/api_services/test_st_storage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from antares.craft.service.api_services.factory import ApiServiceFactory
from antares.craft.service.api_services.models.st_storage import STStoragePropertiesAPI
from antares.craft.service.api_services.services.st_storage import ShortTermStorageApiService
from antares.craft.service.service_factory import ServiceFactory


class TestCreateAPI:
Expand Down
5 changes: 3 additions & 2 deletions tests/antares/services/api_services/test_thermal_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
import pytest
import requests_mock

from unittest.mock import Mock

import pandas as pd
import pytest
import requests_mock

from antares.craft.api_conf.api_conf import APIconf
from antares.craft.exceptions.exceptions import (
Expand Down

0 comments on commit d9f48cc

Please sign in to comment.