From 962a33e45bdaa2efa2b9f6a09692762aa87ea479 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Thu, 2 Feb 2023 10:36:40 +0100 Subject: [PATCH] style: Reformat the source code and unit tests in accordance with the rules of black v23.1.0 (new release). --- antarest/core/maintenance/main.py | 1 - antarest/core/maintenance/service.py | 2 -- antarest/core/persistence.py | 1 - antarest/core/tasks/main.py | 1 - antarest/core/tasks/service.py | 1 - antarest/core/utils/utils.py | 1 - antarest/eventbus/main.py | 1 - antarest/eventbus/web.py | 1 - antarest/launcher/adapters/slurm_launcher/slurm_launcher.py | 1 - antarest/launcher/main.py | 1 - antarest/launcher/service.py | 2 -- antarest/login/auth.py | 1 - antarest/login/service.py | 1 - antarest/matrixstore/business/matrix_editor.py | 2 +- antarest/study/business/timeseries_config_management.py | 1 - antarest/study/business/xpansion_management.py | 1 - .../study/storage/rawstudy/model/filesystem/raw_file_node.py | 1 - .../storage/rawstudy/model/filesystem/root/input/areas/list.py | 1 - .../model/filesystem/root/output/simulation/simulation.py | 1 - antarest/study/storage/study_download_utils.py | 3 --- antarest/study/storage/variantstudy/__init__.py | 1 - .../study/storage/variantstudy/business/command_extractor.py | 1 - .../study/storage/variantstudy/model/command/remove_area.py | 1 - .../study/storage/variantstudy/model/command/remove_cluster.py | 1 - antarest/study/storage/variantstudy/variant_study_service.py | 1 - antarest/study/web/watcher_blueprint.py | 1 - antarest/tools/lib.py | 1 - antarest/utils.py | 1 - tests/core/test_maintenance.py | 1 - tests/core/test_utils_bp.py | 1 - tests/storage/business/test_import.py | 1 - tests/storage/integration/test_exporter.py | 2 -- tests/storage/repository/filesystem/test_folder_node.py | 1 - tests/storage/repository/test_study.py | 1 - tests/storage/web/test_studies_bp.py | 1 - tests/variantstudy/test_command_factory.py | 2 +- 36 files changed, 2 insertions(+), 41 deletions(-) diff --git a/antarest/core/maintenance/main.py b/antarest/core/maintenance/main.py index b355b40d0c..bb0b9fe838 100644 --- a/antarest/core/maintenance/main.py +++ b/antarest/core/maintenance/main.py @@ -16,7 +16,6 @@ def build_maintenance_manager( cache: ICache, event_bus: IEventBus = DummyEventBusService(), ) -> MaintenanceService: - repository = MaintenanceRepository() service = MaintenanceService(config, repository, event_bus, cache) diff --git a/antarest/core/maintenance/service.py b/antarest/core/maintenance/service.py index dd257f14ef..99c4781892 100644 --- a/antarest/core/maintenance/service.py +++ b/antarest/core/maintenance/service.py @@ -66,7 +66,6 @@ def _get_maintenance_data( db_call: Callable[[], Optional[str]], default_value: str, ) -> str: - try: data_json = self.cache.get(cache_id) if data_json is not None and "content" in data_json.keys(): @@ -101,7 +100,6 @@ def _set_maintenance_data( db_call: Callable[[str], None], request_params: RequestParameters, ) -> None: - if not request_params.user or not request_params.user.is_site_admin(): raise UserHasNotPermissionError() diff --git a/antarest/core/persistence.py b/antarest/core/persistence.py index 777a0de0b0..6b8d6f51cb 100644 --- a/antarest/core/persistence.py +++ b/antarest/core/persistence.py @@ -16,7 +16,6 @@ def upgrade_db(config_file: Path) -> None: - os.environ.setdefault("ANTAREST_CONF", str(config_file)) alembic_cfg = Config(str(get_local_path() / "alembic.ini")) alembic_cfg.stdout = StringIO() diff --git a/antarest/core/tasks/main.py b/antarest/core/tasks/main.py index c5bae3cb0a..9996fb18b7 100644 --- a/antarest/core/tasks/main.py +++ b/antarest/core/tasks/main.py @@ -14,7 +14,6 @@ def build_taskjob_manager( config: Config, event_bus: IEventBus = DummyEventBusService(), ) -> ITaskService: - repository = TaskJobRepository() service = TaskJobService(config, repository, event_bus) diff --git a/antarest/core/tasks/service.py b/antarest/core/tasks/service.py index 21941e01c9..3480e3c592 100644 --- a/antarest/core/tasks/service.py +++ b/antarest/core/tasks/service.py @@ -348,7 +348,6 @@ def _run_task( task_id: str, custom_event_messages: Optional[CustomTaskEventMessages] = None, ) -> None: - self.event_bus.push( Event( type=EventType.TASK_RUNNING, diff --git a/antarest/core/utils/utils.py b/antarest/core/utils/utils.py index 5b3efcc9f2..ae56f8a874 100644 --- a/antarest/core/utils/utils.py +++ b/antarest/core/utils/utils.py @@ -106,7 +106,6 @@ def get_local_path() -> Path: def get_commit_id(path_resources: Path) -> Optional[str]: - commit_id = None path_commit_id = path_resources / "commit_id" diff --git a/antarest/eventbus/main.py b/antarest/eventbus/main.py index 6443754339..9398abf03c 100644 --- a/antarest/eventbus/main.py +++ b/antarest/eventbus/main.py @@ -17,7 +17,6 @@ def build_eventbus( autostart: bool = True, redis_client: Optional[Redis] = None, # type: ignore ) -> IEventBus: - eventbus = EventBusService( RedisEventBus(redis_client) if redis_client is not None diff --git a/antarest/eventbus/web.py b/antarest/eventbus/web.py index e4a1eae185..c2b01c0d96 100644 --- a/antarest/eventbus/web.py +++ b/antarest/eventbus/web.py @@ -95,7 +95,6 @@ async def broadcast( def configure_websockets( application: FastAPI, config: Config, event_bus: IEventBus ) -> None: - manager = ConnectionManager() async def send_event_to_ws(event: Event) -> None: diff --git a/antarest/launcher/adapters/slurm_launcher/slurm_launcher.py b/antarest/launcher/adapters/slurm_launcher/slurm_launcher.py index 69223d0327..a033bd1b26 100644 --- a/antarest/launcher/adapters/slurm_launcher/slurm_launcher.py +++ b/antarest/launcher/adapters/slurm_launcher/slurm_launcher.py @@ -610,7 +610,6 @@ def run_study( launcher_parameters: LauncherParametersDTO, params: RequestParameters, ) -> None: - thread = threading.Thread( target=self._run_study, args=(study_uuid, job_id, launcher_parameters, version), diff --git a/antarest/launcher/main.py b/antarest/launcher/main.py index c42e584a96..93920214cb 100644 --- a/antarest/launcher/main.py +++ b/antarest/launcher/main.py @@ -23,7 +23,6 @@ def build_launcher( event_bus: IEventBus = DummyEventBusService(), service_launcher: Optional[LauncherService] = None, ) -> Optional[LauncherService]: - if not service_launcher: repository = JobResultRepository() # keep old job results diff --git a/antarest/launcher/service.py b/antarest/launcher/service.py index 27d7a2639c..c335e27f7d 100644 --- a/antarest/launcher/service.py +++ b/antarest/launcher/service.py @@ -389,7 +389,6 @@ def get_jobs( filter_orphans: bool = True, latest: Optional[int] = None, ) -> List[JobResult]: - if study_uid is not None: job_results = self.job_result_repository.find_by_study(study_uid) else: @@ -501,7 +500,6 @@ def _import_fallback_output( shutil.copytree(output_path, imported_output_path) imported_output_path.rename(Path(job_output_path, output_name)) else: - shutil.copy( output_path, job_output_path / f"{output_name}.zip" ) diff --git a/antarest/login/auth.py b/antarest/login/auth.py index 81affaa49f..bfac797be7 100644 --- a/antarest/login/auth.py +++ b/antarest/login/auth.py @@ -31,7 +31,6 @@ def __init__( [], Dict[str, Any] ] = AuthJWT().get_raw_jwt, # Test only ): - self.disabled = config.security.disabled self.verify = verify self.get_identity = get_identity diff --git a/antarest/login/service.py b/antarest/login/service.py index fd51c11bce..9745a1ac94 100644 --- a/antarest/login/service.py +++ b/antarest/login/service.py @@ -811,7 +811,6 @@ def delete_bot(self, id: int, params: RequestParameters) -> None: ) ) ): - logger.info("bot %d deleted by user %s", id, params.get_user_id()) for role in self.roles.get_all_by_user(user=id): self.roles.delete(user=role.identity_id, group=role.group_id) diff --git a/antarest/matrixstore/business/matrix_editor.py b/antarest/matrixstore/business/matrix_editor.py index d4a99e7172..3e0fb4044f 100644 --- a/antarest/matrixstore/business/matrix_editor.py +++ b/antarest/matrixstore/business/matrix_editor.py @@ -96,7 +96,7 @@ def update_matrix_content_with_coordinates( coordinates: List[Tuple[int, int]], operation: Operation, ) -> pd.DataFrame: - for (row, column) in coordinates: + for row, column in coordinates: df.iat[row, column] = operation.compute( df.iat[row, column], use_coords=True ) diff --git a/antarest/study/business/timeseries_config_management.py b/antarest/study/business/timeseries_config_management.py index 55142495fd..9fa59ad33b 100644 --- a/antarest/study/business/timeseries_config_management.py +++ b/antarest/study/business/timeseries_config_management.py @@ -224,7 +224,6 @@ def __get_form_fields_for_type( ts_type: TSType, general_data: JSON, ) -> Optional[TSFormFieldsForType]: - general = general_data.get("general", {}) input_ = general_data.get("input", {}) output = general_data.get("output", {}) diff --git a/antarest/study/business/xpansion_management.py b/antarest/study/business/xpansion_management.py index 7a877b20cb..c540e8b3e6 100644 --- a/antarest/study/business/xpansion_management.py +++ b/antarest/study/business/xpansion_management.py @@ -552,7 +552,6 @@ def _assert_candidate_is_correct( def add_candidate( self, study: Study, xpansion_candidate_dto: XpansionCandidateDTO ) -> None: - file_study = self.study_storage_service.get_storage(study).get_raw( study ) diff --git a/antarest/study/storage/rawstudy/model/filesystem/raw_file_node.py b/antarest/study/storage/rawstudy/model/filesystem/raw_file_node.py index fe9c4b90d9..478d2c7742 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/raw_file_node.py +++ b/antarest/study/storage/rawstudy/model/filesystem/raw_file_node.py @@ -37,7 +37,6 @@ def load( expanded: bool = False, formatted: bool = True, ) -> bytes: - file_path, tmp_dir = self._get_real_file_path() if file_path.exists(): diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/input/areas/list.py b/antarest/study/storage/rawstudy/model/filesystem/root/input/areas/list.py index c6e22df06e..4b8944633a 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/input/areas/list.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/input/areas/list.py @@ -60,7 +60,6 @@ def check_errors( url: Optional[List[str]] = None, raising: bool = False, ) -> List[str]: - errors = [] if any( a not in data diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/simulation.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/simulation.py index 5ce80724a7..aa6b95ae0a 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/simulation.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/simulation.py @@ -70,7 +70,6 @@ def build(self) -> TREE: } if not self.simulation.error: - children["annualSystemCost"] = RawFileNode( self.context, self.config.next_file("annualSystemCost.txt") ) diff --git a/antarest/study/storage/study_download_utils.py b/antarest/study/storage/study_download_utils.py index f1e6b37938..0820fe7f55 100644 --- a/antarest/study/storage/study_download_utils.py +++ b/antarest/study/storage/study_download_utils.py @@ -122,7 +122,6 @@ def level_output_filter( url: str, data: StudyDownloadDTO, ) -> None: - cluster_details = [f"details-{data.level.value}"] if study.config.enr_modelling == ENR_MODELLING.CLUSTERS.value: cluster_details += [f"details-res-{data.level.value}"] @@ -150,7 +149,6 @@ def apply_type_filters( first_element_type_condition: bool, second_element_type_condition: Callable[[str], bool], ) -> None: - if first_element_type_condition: if data.type == StudyDownloadType.LINK and isinstance( type_elm[elm], Area @@ -415,7 +413,6 @@ def export( if filetype == ExportFormat.ZIP else tarfile.open(target_file, mode="w:gz") ) as output_data: - # 2 - Create CSV files for ts_data in matrix.data: output = StringIO() diff --git a/antarest/study/storage/variantstudy/__init__.py b/antarest/study/storage/variantstudy/__init__.py index 139597f9cb..8b13789179 100644 --- a/antarest/study/storage/variantstudy/__init__.py +++ b/antarest/study/storage/variantstudy/__init__.py @@ -1,2 +1 @@ - diff --git a/antarest/study/storage/variantstudy/business/command_extractor.py b/antarest/study/storage/variantstudy/business/command_extractor.py index 387d22d2fd..33f9d8d4a1 100644 --- a/antarest/study/storage/variantstudy/business/command_extractor.py +++ b/antarest/study/storage/variantstudy/business/command_extractor.py @@ -615,7 +615,6 @@ def generate_update_district( study: FileStudy, district_id: str, ) -> ICommand: - study_config = study.config study_tree = study.tree district_config = study_config.sets[district_id] diff --git a/antarest/study/storage/variantstudy/model/command/remove_area.py b/antarest/study/storage/variantstudy/model/command/remove_area.py index 68f292178f..eda840d148 100644 --- a/antarest/study/storage/variantstudy/model/command/remove_area.py +++ b/antarest/study/storage/variantstudy/model/command/remove_area.py @@ -171,7 +171,6 @@ def _remove_area_from_time_series(self, study_data: FileStudy) -> None: study_data.tree.delete(["input", "thermal", "series", self.id]) def _apply(self, study_data: FileStudy) -> CommandOutput: - study_data.tree.delete(["input", "areas", self.id]) study_data.tree.delete(["input", "hydro", "allocation", self.id]) diff --git a/antarest/study/storage/variantstudy/model/command/remove_cluster.py b/antarest/study/storage/variantstudy/model/command/remove_cluster.py index 91120ce611..8c761bbf2d 100644 --- a/antarest/study/storage/variantstudy/model/command/remove_cluster.py +++ b/antarest/study/storage/variantstudy/model/command/remove_cluster.py @@ -175,7 +175,6 @@ def get_inner_matrices(self) -> List[str]: def _remove_cluster_from_binding_constraints( self, study_data: FileStudy ) -> None: - binding_constraints = study_data.tree.get( ["input", "bindingconstraints", "bindingconstraints"] ) diff --git a/antarest/study/storage/variantstudy/variant_study_service.py b/antarest/study/storage/variantstudy/variant_study_service.py index ca9405dc9b..9ee6181f20 100644 --- a/antarest/study/storage/variantstudy/variant_study_service.py +++ b/antarest/study/storage/variantstudy/variant_study_service.py @@ -982,7 +982,6 @@ def _generate_config( config: FileStudyTreeConfig, notifier: TaskUpdateNotifier = noop_notifier, ) -> Tuple[GenerationResultInfoDTO, FileStudyTreeConfig]: - commands, notify = self._get_commands_and_notifier( variant_study=variant_study, notifier=notifier ) diff --git a/antarest/study/web/watcher_blueprint.py b/antarest/study/web/watcher_blueprint.py index ca1d33547a..b8e02927d5 100644 --- a/antarest/study/web/watcher_blueprint.py +++ b/antarest/study/web/watcher_blueprint.py @@ -46,7 +46,6 @@ def scan_dir( path: str, current_user: JWTUser = Depends(auth.get_current_user), ) -> Any: - params = RequestParameters(user=current_user) if path: # The front actually sends / diff --git a/antarest/tools/lib.py b/antarest/tools/lib.py index 88220aee7b..dda6feb33b 100644 --- a/antarest/tools/lib.py +++ b/antarest/tools/lib.py @@ -371,7 +371,6 @@ def generate_study( host: Optional[str] = None, token: Optional[str] = None, ) -> GenerationResultInfoDTO: - if study_id is not None and host is not None: generator: IVariantGenerator = RemoteVariantGenerator( study_id, host, token diff --git a/antarest/utils.py b/antarest/utils.py index 6670db062d..68319d9cf2 100644 --- a/antarest/utils.py +++ b/antarest/utils.py @@ -214,7 +214,6 @@ def create_matrix_gc( study_service: Optional[StudyService] = None, matrix_service: Optional[MatrixService] = None, ) -> MatrixGarbageCollector: - if study_service and matrix_service: return MatrixGarbageCollector( config=config, diff --git a/tests/core/test_maintenance.py b/tests/core/test_maintenance.py index ebae00b283..1ecc8cb2d0 100644 --- a/tests/core/test_maintenance.py +++ b/tests/core/test_maintenance.py @@ -125,7 +125,6 @@ def test_service_without_cache() -> None: def test_service_with_cache() -> None: - repo_mock = Mock(spec=MaintenanceRepository) cache = Mock() event_bus = Mock() diff --git a/tests/core/test_utils_bp.py b/tests/core/test_utils_bp.py index 33b5dbd96e..f9efb93dd4 100644 --- a/tests/core/test_utils_bp.py +++ b/tests/core/test_utils_bp.py @@ -27,7 +27,6 @@ @pytest.mark.unit_test def test_version() -> None: - mock_storage_service = Mock() mock_storage_service.study_service.path_resources = Path("/") diff --git a/tests/storage/business/test_import.py b/tests/storage/business/test_import.py index d217d43474..a3e555e02c 100644 --- a/tests/storage/business/test_import.py +++ b/tests/storage/business/test_import.py @@ -31,7 +31,6 @@ def build_storage_service(workspace: Path, uuid: str) -> RawStudyService: @pytest.mark.unit_test def test_import_study(tmp_path: Path) -> None: - name = "my-study" study_path = tmp_path / name study_path.mkdir() diff --git a/tests/storage/integration/test_exporter.py b/tests/storage/integration/test_exporter.py index f6053803f6..1220993f97 100644 --- a/tests/storage/integration/test_exporter.py +++ b/tests/storage/integration/test_exporter.py @@ -87,7 +87,6 @@ def assert_data(data: bytes): def test_exporter_file(tmp_path: Path, sta_mini_zip_path: Path): - data = assert_url_content( url="/v1/studies/STA-mini/export", tmp_dir=tmp_path, @@ -97,7 +96,6 @@ def test_exporter_file(tmp_path: Path, sta_mini_zip_path: Path): def test_exporter_file_no_output(tmp_path: Path, sta_mini_zip_path: Path): - data = assert_url_content( url="/v1/studies/STA-mini/export?no-output", tmp_dir=tmp_path, diff --git a/tests/storage/repository/filesystem/test_folder_node.py b/tests/storage/repository/filesystem/test_folder_node.py index 92e927ad84..20eba4c99c 100644 --- a/tests/storage/repository/filesystem/test_folder_node.py +++ b/tests/storage/repository/filesystem/test_folder_node.py @@ -114,7 +114,6 @@ def test_filter(): def test_delete(tmp_path: Path): - folder_node = tmp_path / "folder_node" folder_node.mkdir() sub_folder = folder_node / "sub_folder" diff --git a/tests/storage/repository/test_study.py b/tests/storage/repository/test_study.py index a6ea7cfe93..62c34f50a0 100644 --- a/tests/storage/repository/test_study.py +++ b/tests/storage/repository/test_study.py @@ -134,7 +134,6 @@ def test_study_inheritance(): @with_db_context def test_cache(): - user = User(id=0, name="admin") group = Group(id="my-group", name="group") diff --git a/tests/storage/web/test_studies_bp.py b/tests/storage/web/test_studies_bp.py index f98e82ad31..bd589e684e 100644 --- a/tests/storage/web/test_studies_bp.py +++ b/tests/storage/web/test_studies_bp.py @@ -732,7 +732,6 @@ def test_study_permission_management(tmp_path: Path) -> None: @pytest.mark.unit_test def test_get_study_versions(tmp_path: Path) -> None: - app = FastAPI(title=__name__) build_study_service( app, diff --git a/tests/variantstudy/test_command_factory.py b/tests/variantstudy/test_command_factory.py index 13fe371000..b66bb72ff5 100644 --- a/tests/variantstudy/test_command_factory.py +++ b/tests/variantstudy/test_command_factory.py @@ -22,7 +22,7 @@ class TestCommandFactory: def setup_class(self): - for (module_loader, name, ispkg) in pkgutil.iter_modules( + for module_loader, name, ispkg in pkgutil.iter_modules( ["antarest/study/storage/variantstudy/model/command"] ): importlib.import_module(