diff --git a/antarest/study/storage/variantstudy/variant_study_service.py b/antarest/study/storage/variantstudy/variant_study_service.py index cc4bd2b6c2..947fc4bfd9 100644 --- a/antarest/study/storage/variantstudy/variant_study_service.py +++ b/antarest/study/storage/variantstudy/variant_study_service.py @@ -48,7 +48,7 @@ from antarest.core.utils.utils import assert_this, suppress_exception from antarest.matrixstore.service import MatrixService from antarest.study.model import RawStudy, Study, StudyAdditionalData, StudyMetadataDTO, StudySimResultDTO -from antarest.study.repository import StudyFilter, StudySortBy, AccessPermissions +from antarest.study.repository import AccessPermissions, StudyFilter, StudySortBy from antarest.study.storage.abstract_storage_service import AbstractStorageService from antarest.study.storage.patch_service import PatchService from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig, FileStudyTreeConfigDTO @@ -1054,18 +1054,18 @@ def initialize_additional_data(self, variant_study: VariantStudy) -> bool: def clear_all_snapshots(self, limit: int, params: t.Optional[RequestParameters] = None) -> None: """ - Clear all variant snapshots older than `limit` (in hours). - Only available for admin users. - `limit` must be a positive integer. - Raises a UserHasNotPermissionError if the user is not administrator - Args: - limit (integer): number of hours - params: request parameters used to identify the user status - Returns: None - - Raises: - UserHasNotPermissionError - HTTPException + Clear all variant snapshots older than `limit` (in hours). + Only available for admin users. + `limit` must be a positive integer. + Raises a UserHasNotPermissionError if the user is not administrator + Args: + limit (integer): number of hours + params: request parameters used to identify the user status + Returns: None + + Raises: + UserHasNotPermissionError + HTTPException """ if limit < 0: raise HTTPException(status_code=400, detail=f"Limit cannot be negative (limit={limit})") @@ -1077,9 +1077,9 @@ def clear_all_snapshots(self, limit: int, params: t.Optional[RequestParameters] ) ) for variant in result: - if variant.updated_at < datetime.now() - timedelta(hours=limit) or \ - (variant.last_access and - variant.last_access < datetime.now() - timedelta(hours=limit)): + if variant.updated_at < datetime.now() - timedelta(hours=limit) or ( + variant.last_access and variant.last_access < datetime.now() - timedelta(hours=limit) + ): self.clear_snapshot(variant) else: raise UserHasNotPermissionError diff --git a/antarest/study/web/variant_blueprint.py b/antarest/study/web/variant_blueprint.py index 6e2ce04d17..2480b6c9de 100644 --- a/antarest/study/web/variant_blueprint.py +++ b/antarest/study/web/variant_blueprint.py @@ -24,7 +24,7 @@ from antarest.core.utils.web import APITag from antarest.login.auth import Auth from antarest.study.model import StudyMetadataDTO -from antarest.study.repository import StudyFilter, AccessPermissions +from antarest.study.repository import AccessPermissions, StudyFilter from antarest.study.service import StudyService from antarest.study.storage.variantstudy.model.command.update_config import UpdateConfig from antarest.study.storage.variantstudy.model.model import CommandDTO, VariantTreeDTO @@ -33,8 +33,8 @@ def create_study_variant_routes( - study_service: StudyService, - config: Config, + study_service: StudyService, + config: Config, ) -> APIRouter: """ Endpoint implementation for studies area management @@ -60,9 +60,9 @@ def create_study_variant_routes( }, ) def create_variant( - uuid: str, - name: str, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + name: str, + current_user: JWTUser = Depends(auth.get_current_user), ) -> str: """ Creates a study variant. @@ -116,8 +116,8 @@ def create_variant( }, ) def get_variants( - uuid: str, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + current_user: JWTUser = Depends(auth.get_current_user), ) -> VariantTreeDTO: logger.info( f"Fetching variant children of study {uuid}", @@ -139,9 +139,9 @@ def get_variants( }, ) def get_parents( - uuid: str, - direct: Optional[bool] = False, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + direct: Optional[bool] = False, + current_user: JWTUser = Depends(auth.get_current_user), ) -> Union[List[StudyMetadataDTO], Optional[StudyMetadataDTO]]: logger.info( f"Fetching variant parents of study {uuid}", @@ -167,8 +167,8 @@ def get_parents( }, ) def list_commands( - uuid: str, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + current_user: JWTUser = Depends(auth.get_current_user), ) -> List[CommandDTO]: logger.info( f"Fetching command list of variant study {uuid}", @@ -185,8 +185,8 @@ def list_commands( response_model=FileDownloadTaskDTO, ) def export_matrices( - uuid: str, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + current_user: JWTUser = Depends(auth.get_current_user), ) -> FileDownloadTaskDTO: logger.info( f"Exporting commands matrices for variant study {uuid}", @@ -207,9 +207,9 @@ def export_matrices( }, ) def append_commands( - uuid: str, - commands: List[CommandDTO] = Body(...), - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + commands: List[CommandDTO] = Body(...), + current_user: JWTUser = Depends(auth.get_current_user), ) -> Optional[List[str]]: logger.info( f"Appending new command to variant study {uuid}", @@ -230,9 +230,9 @@ def append_commands( }, ) def replace_commands( - uuid: str, - commands: List[CommandDTO] = Body(...), - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + commands: List[CommandDTO] = Body(...), + current_user: JWTUser = Depends(auth.get_current_user), ) -> str: logger.info( f"Replacing all commands of variant study {uuid}", @@ -253,9 +253,9 @@ def replace_commands( }, ) def append_command( - uuid: str, - command: CommandDTO, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + command: CommandDTO, + current_user: JWTUser = Depends(auth.get_current_user), ) -> str: logger.info( f"Appending new command to variant study {uuid}", @@ -277,9 +277,9 @@ def append_command( }, ) def get_command( - uuid: str, - cid: str, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + cid: str, + current_user: JWTUser = Depends(auth.get_current_user), ) -> CommandDTO: logger.info( f"Fetching command {cid} info of variant study {uuid}", @@ -296,10 +296,10 @@ def get_command( summary="Move a command to an other index", ) def move_command( - uuid: str, - cid: str, - index: int, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + cid: str, + index: int, + current_user: JWTUser = Depends(auth.get_current_user), ) -> None: logger.info( f"Moving command {cid} to index {index} for variant study {uuid}", @@ -316,10 +316,10 @@ def move_command( summary="Move a command to an other index", ) def update_command( - uuid: str, - cid: str, - command: CommandDTO, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + cid: str, + command: CommandDTO, + current_user: JWTUser = Depends(auth.get_current_user), ) -> None: logger.info( f"Update command {cid} for variant study {uuid}", @@ -336,9 +336,9 @@ def update_command( summary="Remove a command", ) def remove_command( - uuid: str, - cid: str, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + cid: str, + current_user: JWTUser = Depends(auth.get_current_user), ) -> None: logger.info( f"Removing command {cid} of variant study {uuid}", @@ -355,8 +355,8 @@ def remove_command( summary="Clear variant's commands", ) def remove_all_commands( - uuid: str, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + current_user: JWTUser = Depends(auth.get_current_user), ) -> None: logger.info( f"Removing all commands from variant study {uuid}", @@ -373,10 +373,10 @@ def remove_all_commands( response_model=str, ) def generate_variant( - uuid: str, - denormalize: bool = False, - from_scratch: bool = False, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + denormalize: bool = False, + from_scratch: bool = False, + current_user: JWTUser = Depends(auth.get_current_user), ) -> str: logger.info( f"Generating snapshot for variant study {uuid}", @@ -393,8 +393,8 @@ def generate_variant( response_model=TaskDTO, ) def get_study_generation_task( - uuid: str, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + current_user: JWTUser = Depends(auth.get_current_user), ) -> TaskDTO: request_params = RequestParameters(user=current_user) sanitized_uuid = sanitize_uuid(uuid) @@ -411,9 +411,9 @@ def get_study_generation_task( }, ) def create_from_variant( - uuid: str, - name: str, - current_user: JWTUser = Depends(auth.get_current_user), + uuid: str, + name: str, + current_user: JWTUser = Depends(auth.get_current_user), ) -> str: logger.info( f"Creating new raw study {name} from variant study {uuid}", @@ -430,18 +430,18 @@ def create_from_variant( 200: { "description": "Delete snapshots older than a specific number of hours. By default, this number is 24." } - } + }, ) def clear_variant_snapshots( - limit: int = 24, - current_user: JWTUser = Depends(auth.get_current_user), - ): + limit: int = 24, + current_user: JWTUser = Depends(auth.get_current_user), + ) -> None: """ - Endpoint that clear `limit` hours old and older variant snapshots. + Endpoint that clear `limit` hours old and older variant snapshots. - Args: limit (int, optional): Number of hours to clear. Defaults to 24. + Args: limit (int, optional): Number of hours to clear. Defaults to 24. - Returns: None + Returns: None """ logger.info( f"Delete all variant snapshots older than {limit} hours (24 by default)",