From cf6622ea6aea620a249a301071ee593773af24d8 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Mon, 30 Sep 2024 17:18:55 +0200 Subject: [PATCH 01/56] test --- .github/workflows/deploy.yml | 2 +- .github/workflows/license_header.yml | 2 +- .github/workflows/main.yml | 4 ++-- .github/workflows/worker.yml | 3 ++- requirements-dev.txt | 5 +++-- requirements.txt | 8 +++++--- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e34aef58ae..fc44a21f74 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -42,7 +42,7 @@ jobs: - name: 🐍 Set up Python uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - name: 🐍 Install development dependencies run: | diff --git a/.github/workflows/license_header.yml b/.github/workflows/license_header.yml index 51b8172825..cf577e51c9 100644 --- a/.github/workflows/license_header.yml +++ b/.github/workflows/license_header.yml @@ -13,7 +13,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7a590a8214..0e41bf08b1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - name: Install dependencies run: | python -m pip install --upgrade pip @@ -46,7 +46,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/worker.yml b/.github/workflows/worker.yml index 4839670d62..feca22fdb6 100644 --- a/.github/workflows/worker.yml +++ b/.github/workflows/worker.yml @@ -4,6 +4,7 @@ on: branches: - "master" - "worker/**" + - "bump-python/**" jobs: binary: @@ -18,7 +19,7 @@ jobs: - name: 🐍 Set up Python uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.11 - name: 🐍 Install dependencies run: | diff --git a/requirements-dev.txt b/requirements-dev.txt index 973973dc76..af134f12be 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -10,9 +10,10 @@ pyinstaller-hooks-contrib==2024.6 # IMPORTANT: Make sure the versions of these typing libraries match the versions # of the corresponding implementation libraries used in production (in `requirements.txt`). -pandas-stubs~=1.4.0 +pandas-stubs~=1.4.0; python_version <= '3.8' +pandas-stubs~=2.2.2; python_version > '3.8' types-paramiko~=3.4.0 -types-psycopg2~=2.9.4 +types-psycopg2~=2.9.9 types-redis~=4.1.2 types-requests~=2.27.1 types-PyYAML~=5.4.1 diff --git a/requirements.txt b/requirements.txt index 2a7ff60a2d..970558c60c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,11 +31,13 @@ gunicorn~=20.1.0 jsonref~=0.2 PyJWT~=2.9.0 MarkupSafe~=2.0.1 -numpy~=1.22.1 -pandas~=1.4.0 +numpy~=1.22.1; python_version <= '3.8' +numpy~=1.26.4; python_version > '3.8' +pandas~=1.4.0; python_version <= '3.8' +pandas~=2.2.3; python_version > '3.8' paramiko~=2.12.0 plyer~=2.0.0 -psycopg2-binary==2.9.4 +psycopg2-binary~=2.9.9 py7zr~=0.20.6 PyQt5~=5.15.6 python-json-logger~=2.0.7 From 549faffeb4e933106092e2ece69c6489bc177e93 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Mon, 30 Sep 2024 17:27:12 +0200 Subject: [PATCH 02/56] also test the binary --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fc44a21f74..476a2b5781 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,6 +4,7 @@ on: branches: - "master" - "hotfix/**" + - "bump-python/**" jobs: binary: From 3d0c49a550e86b36a8fd6918c907085e79a6ec56 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Mon, 30 Sep 2024 17:33:53 +0200 Subject: [PATCH 03/56] fix little mypy issue --- antarest/study/business/aggregator_management.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/antarest/study/business/aggregator_management.py b/antarest/study/business/aggregator_management.py index a040faf1de..7f961f7e91 100644 --- a/antarest/study/business/aggregator_management.py +++ b/antarest/study/business/aggregator_management.py @@ -308,7 +308,7 @@ def _process_df(self, file_path: Path, is_details: bool) -> pd.DataFrame: # loop over the cluster id to extract the values of the actual columns for cluster_id, dummy_component in cluster_dummy_product_cols: for actual_col in actual_cols: - col_values = un_normalized_df[(cluster_id, actual_col, dummy_component)].tolist() # type: ignore + col_values = un_normalized_df[(cluster_id, actual_col, dummy_component)].tolist() new_obj[actual_col] += col_values new_obj[CLUSTER_ID_COL] += [cluster_id for _ in range(df_len)] new_obj[TIME_ID_COL] += list(range(1, df_len + 1)) From 7d41963fcfedc1592f9cdb388fde9cca8d4a1afa Mon Sep 17 00:00:00 2001 From: belthlemar Date: Mon, 30 Sep 2024 18:08:26 +0200 Subject: [PATCH 04/56] still 51 tests failures --- .../filesystem/root/output/simulation/mode/common/set.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py index 4c8a624a5c..7ac2b3cd5e 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py @@ -33,9 +33,9 @@ def build(self) -> TREE: freq: MatrixFrequency for freq in MatrixFrequency: for output_type in ["id", "values"]: - file_name = f"{output_type}-{freq}.txt" + file_name = f"{output_type}-{freq.value}.txt" if (self.config.path / file_name).exists(): - children[f"{output_type}-{freq}"] = AreaOutputSeriesMatrix( + children[f"{output_type}-{freq.value}"] = AreaOutputSeriesMatrix( self.context, self.config.next_file(file_name), freq, From 1cdda23d3428102354305e00c7f1518a4b0c17a6 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Mon, 30 Sep 2024 18:13:24 +0200 Subject: [PATCH 05/56] fix issue but still 52 test failures --- .../filesystem/root/output/simulation/mode/common/area.py | 4 ++-- .../filesystem/root/output/simulation/mode/common/link.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py index 0b97fa5735..d3aa73a8d5 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py @@ -33,9 +33,9 @@ def build(self) -> TREE: freq: MatrixFrequency for freq in MatrixFrequency: for output_type in ["id", "values", "details", "details-res", "details-STstorage"]: - file_name = f"{output_type}-{freq}.txt" + file_name = f"{output_type}-{freq.value}" if (self.config.path / file_name).exists(): - children[f"{output_type}-{freq}"] = AreaOutputSeriesMatrix( + children[f"{output_type}-{freq.value}"] = AreaOutputSeriesMatrix( self.context, self.config.next_file(file_name), freq, diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py index b5f0b15dcb..8039b664e5 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py @@ -35,9 +35,9 @@ def build(self) -> TREE: freq: MatrixFrequency for freq in MatrixFrequency: for output_type in ["id", "values"]: - file_name = f"{output_type}-{freq}.txt" + file_name = f"{output_type}-{freq.value}" if (self.config.path / file_name).exists(): - children[f"{output_type}-{freq}"] = LinkOutputSeriesMatrix( + children[f"{output_type}-{freq.value}"] = LinkOutputSeriesMatrix( self.context, self.config.next_file(file_name), freq, From acb7ec25e55c66ebfc3938c420fea971259210dd Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 09:34:19 +0200 Subject: [PATCH 06/56] still 47 test failures --- antarest/study/business/xpansion_management.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/antarest/study/business/xpansion_management.py b/antarest/study/business/xpansion_management.py index ad459d036f..f34b7f3497 100644 --- a/antarest/study/business/xpansion_management.py +++ b/antarest/study/business/xpansion_management.py @@ -341,10 +341,12 @@ def create_xpansion_configuration(self, study: Study, zipped_config: t.Optional[ xpansion_settings = XpansionSettings() settings_obj = xpansion_settings.model_dump( - by_alias=True, exclude_none=True, exclude={"sensitivity_config"} + mode="json", by_alias=True, exclude_none=True, exclude={"sensitivity_config"} ) if xpansion_settings.sensitivity_config: - sensitivity_obj = xpansion_settings.sensitivity_config.model_dump(by_alias=True, exclude_none=True) + sensitivity_obj = xpansion_settings.sensitivity_config.model_dump( + mode="json", by_alias=True, exclude_none=True + ) else: sensitivity_obj = {} @@ -385,7 +387,7 @@ def update_xpansion_settings( actual_settings = self.get_xpansion_settings(study) settings_fields = new_xpansion_settings.model_dump( - by_alias=False, exclude_none=True, exclude={"sensitivity_config"} + mode="json", by_alias=False, exclude_none=True, exclude={"sensitivity_config"} ) updated_settings = actual_settings.copy(deep=True, update=settings_fields) @@ -406,11 +408,11 @@ def update_xpansion_settings( msg = f"Additional constraints file '{constraints_file}' does not exist" raise XpansionFileNotFoundError(msg) from None - config_obj = updated_settings.model_dump(by_alias=True, exclude={"sensitivity_config"}) + config_obj = updated_settings.model_dump(mode="json", by_alias=True, exclude={"sensitivity_config"}) file_study.tree.save(config_obj, ["user", "expansion", "settings"]) if new_xpansion_settings.sensitivity_config: - sensitivity_obj = new_xpansion_settings.sensitivity_config.model_dump(by_alias=True) + sensitivity_obj = new_xpansion_settings.sensitivity_config.model_dump(mode="json", by_alias=True) file_study.tree.save(sensitivity_obj, ["user", "expansion", "sensitivity", "sensitivity_in"]) return self.get_xpansion_settings(study) @@ -550,7 +552,7 @@ def add_candidate(self, study: Study, xpansion_candidate: XpansionCandidateDTO) ) # The primary key is actually the name, the id does not matter and is never checked. logger.info(f"Adding candidate '{xpansion_candidate.name}' to study '{study.id}'") - candidates_obj[next_id] = xpansion_candidate.model_dump(by_alias=True, exclude_none=True) + candidates_obj[next_id] = xpansion_candidate.model_dump(mode="json", by_alias=True, exclude_none=True) candidates_data = {"user": {"expansion": {"candidates": candidates_obj}}} file_study.tree.save(candidates_data) # Should we add a field in the study config containing the xpansion candidates like the links or the areas ? @@ -591,7 +593,9 @@ def update_candidate( for candidate_id, candidate in candidates.items(): if candidate["name"] == candidate_name: logger.info(f"Updating candidate '{candidate_name}' of study '{study.id}'") - candidates[candidate_id] = xpansion_candidate_dto.model_dump(by_alias=True, exclude_none=True) + candidates[candidate_id] = xpansion_candidate_dto.model_dump( + mode="json", by_alias=True, exclude_none=True + ) file_study.tree.save(candidates, ["user", "expansion", "candidates"]) return raise CandidateNotFoundError(f"The candidate '{xpansion_candidate_dto.name}' does not exist") From abe010bdd2d7af1a2e9fb9290906c1ac5b75ba57 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 09:37:46 +0200 Subject: [PATCH 07/56] 45 --- .../model/filesystem/root/output/simulation/mode/common/link.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py index 8039b664e5..e3b83c1349 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py @@ -35,7 +35,7 @@ def build(self) -> TREE: freq: MatrixFrequency for freq in MatrixFrequency: for output_type in ["id", "values"]: - file_name = f"{output_type}-{freq.value}" + file_name = f"{output_type}-{freq.value}.txt" if (self.config.path / file_name).exists(): children[f"{output_type}-{freq.value}"] = LinkOutputSeriesMatrix( self.context, From c1ff88fdc3ce1a13d15a549c895230d0885bd04b Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 09:38:35 +0200 Subject: [PATCH 08/56] 43 --- .../model/filesystem/root/output/simulation/mode/common/area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py index d3aa73a8d5..f42637b298 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py @@ -33,7 +33,7 @@ def build(self) -> TREE: freq: MatrixFrequency for freq in MatrixFrequency: for output_type in ["id", "values", "details", "details-res", "details-STstorage"]: - file_name = f"{output_type}-{freq.value}" + file_name = f"{output_type}-{freq.value}.txt" if (self.config.path / file_name).exists(): children[f"{output_type}-{freq.value}"] = AreaOutputSeriesMatrix( self.context, From f922ceadefe6f98c1aa8ad6bddcdb70d896ee6bf Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 09:53:46 +0200 Subject: [PATCH 09/56] fix lots of tests --- .../rawstudy/model/filesystem/config/ruleset_matrices.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/ruleset_matrices.py b/antarest/study/storage/rawstudy/model/filesystem/config/ruleset_matrices.py index 29da19c30e..6ed47a3e17 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/ruleset_matrices.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/ruleset_matrices.py @@ -397,11 +397,11 @@ def update_table_form(self, table_form: TableForm, scenario_type: str, *, nan_va scenario = self.scenarios[scenario_type] if isinstance(scenario, pd.DataFrame): simple_table_form = t.cast(SimpleTableForm, table_form) - df = pd.DataFrame(simple_table_form).transpose().replace([None, nan_value], np.nan) - scenario.at[df.index, df.columns] = df + df = pd.DataFrame.from_dict(simple_table_form, orient="index").replace([None, nan_value], np.nan) + scenario.loc[df.index, df.columns] = df else: cluster_table_form = t.cast(ClusterTableForm, table_form) for area, simple_table_form in cluster_table_form.items(): scenario = t.cast(pd.DataFrame, self.scenarios[scenario_type][area]) df = pd.DataFrame(simple_table_form).transpose().replace([None, nan_value], np.nan) - scenario.at[df.index, df.columns] = df + scenario.loc[df.index, df.columns] = df From 2fc280e9127105bae1ec592c5c7813c5da668b41 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 10:06:46 +0200 Subject: [PATCH 10/56] 23 failures --- .../launcher/adapters/abstractlauncher.py | 2 +- antarest/launcher/model.py | 2 +- antarest/launcher/service.py | 2 +- antarest/study/business/area_management.py | 8 +++---- .../business/areas/renewable_management.py | 2 +- .../business/areas/st_storage_management.py | 24 +++++++++++-------- .../business/areas/thermal_management.py | 20 +++++++++------- antarest/study/business/link_management.py | 6 +++-- .../study/business/table_mode_management.py | 4 ++-- .../business/thematic_trimming_management.py | 2 +- .../business/timeseries_config_management.py | 2 +- antarest/study/service.py | 4 ++-- .../variantstudy/model/command/icommand.py | 4 ++-- tests/cache/test_local_cache.py | 6 ++--- tests/cache/test_redis_cache.py | 6 ++--- tests/integration/test_integration.py | 10 ++++---- 16 files changed, 56 insertions(+), 48 deletions(-) diff --git a/antarest/launcher/adapters/abstractlauncher.py b/antarest/launcher/adapters/abstractlauncher.py index 4b845f8de0..e096eae2a2 100644 --- a/antarest/launcher/adapters/abstractlauncher.py +++ b/antarest/launcher/adapters/abstractlauncher.py @@ -114,6 +114,6 @@ def update_log(log_line: str) -> None: channel=EventChannelDirectory.JOB_STATUS + job_id, ) ) - self.cache.put(f"Launch_Progress_{job_id}", launch_progress_dto.model_dump()) + self.cache.put(f"Launch_Progress_{job_id}", launch_progress_dto.model_dump(mode="json")) return update_log diff --git a/antarest/launcher/model.py b/antarest/launcher/model.py index d80400a4ba..b26a502795 100644 --- a/antarest/launcher/model.py +++ b/antarest/launcher/model.py @@ -139,7 +139,7 @@ def json_schema_extra(schema: t.MutableMapping[str, t.Any]) -> None: exit_code=0, solver_stats="time: 1651s, call_count: 1, optimization_issues: []", owner=UserInfo(id=0o007, name="James BOND"), - ).model_dump() + ).model_dump(mode="json") class JobLog(Base): # type: ignore diff --git a/antarest/launcher/service.py b/antarest/launcher/service.py index 2dad1aef00..969789dee8 100644 --- a/antarest/launcher/service.py +++ b/antarest/launcher/service.py @@ -183,7 +183,7 @@ def update( self.event_bus.push( Event( type=EventType.STUDY_JOB_COMPLETED if final_status else EventType.STUDY_JOB_STATUS_UPDATE, - payload=job_result.to_dto().model_dump(), + payload=job_result.to_dto().model_dump(mode="json"), permissions=PermissionInfo(public_mode=PublicMode.READ), channel=EventChannelDirectory.JOB_STATUS + job_result.id, ) diff --git a/antarest/study/business/area_management.py b/antarest/study/business/area_management.py index 5682a6fa60..e49eb6a9d6 100644 --- a/antarest/study/business/area_management.py +++ b/antarest/study/business/area_management.py @@ -228,11 +228,11 @@ def from_model( obj = { "average_unsupplied_energy_cost": average_unsupplied_energy_cost, "average_spilled_energy_cost": average_spilled_energy_cost, - **area_folder.optimization.filtering.model_dump(by_alias=False), - **area_folder.optimization.nodal_optimization.model_dump(by_alias=False), + **area_folder.optimization.filtering.model_dump(mode="json", by_alias=False), + **area_folder.optimization.nodal_optimization.model_dump(mode="json", by_alias=False), # adequacy_patch is only available if study version >= 830. **( - area_folder.adequacy_patch.adequacy_patch.model_dump(by_alias=False) + area_folder.adequacy_patch.adequacy_patch.model_dump(mode="json", by_alias=False) if area_folder.adequacy_patch else {} ), @@ -362,7 +362,7 @@ def update_areas_props( for area_id, update_area in update_areas_by_ids.items(): # Update the area properties. old_area = old_areas_by_ids[area_id] - new_area = old_area.copy(update=update_area.model_dump(by_alias=False, exclude_none=True)) + new_area = old_area.copy(update=update_area.model_dump(mode="json", by_alias=False, exclude_none=True)) new_areas_by_ids[area_id] = new_area # Convert the DTO to a configuration object and update the configuration file. diff --git a/antarest/study/business/areas/renewable_management.py b/antarest/study/business/areas/renewable_management.py index 12af8abdb5..dbe844a056 100644 --- a/antarest/study/business/areas/renewable_management.py +++ b/antarest/study/business/areas/renewable_management.py @@ -64,7 +64,7 @@ def json_schema_extra(schema: t.MutableMapping[str, t.Any]) -> None: unit_count=100, nominal_capacity=1000.0, ts_interpretation="power-generation", - ).model_dump() + ).model_dump(mode="json") class RenewableClusterCreation(RenewableClusterInput): diff --git a/antarest/study/business/areas/st_storage_management.py b/antarest/study/business/areas/st_storage_management.py index dcb5db5dc8..23f1052a8b 100644 --- a/antarest/study/business/areas/st_storage_management.py +++ b/antarest/study/business/areas/st_storage_management.py @@ -66,7 +66,7 @@ def json_schema_extra(schema: t.MutableMapping[str, t.Any]) -> None: efficiency=0.94, initial_level=0.5, initial_level_optim=True, - ).model_dump() + ).model_dump(mode="json") class STStorageCreation(STStorageInput): @@ -86,7 +86,7 @@ def validate_name(cls, name: t.Optional[str]) -> str: # noinspection PyUnusedLocal def to_config(self, study_version: t.Union[str, int]) -> STStorageConfigType: - values = self.model_dump(by_alias=False, exclude_none=True) + values = self.model_dump(mode="json", by_alias=False, exclude_none=True) return create_st_storage_config(study_version=study_version, **values) @@ -109,7 +109,7 @@ def json_schema_extra(schema: t.MutableMapping[str, t.Any]) -> None: reservoir_capacity=600, efficiency=0.94, initial_level_optim=True, - ).model_dump() + ).model_dump(mode="json") # ============= @@ -244,7 +244,7 @@ def create_storage_output( config: t.Mapping[str, t.Any], ) -> "STStorageOutput": obj = create_st_storage_config(study_version=study_version, **config, id=cluster_id) - kwargs = obj.model_dump(by_alias=False) + kwargs = obj.model_dump(mode="json", by_alias=False) return STStorageOutput(**kwargs) @@ -388,12 +388,14 @@ def update_storages_props( for storage_id, update_cluster in update_storages_by_ids.items(): # Update the storage cluster properties. old_cluster = old_storages_by_ids[storage_id] - new_cluster = old_cluster.copy(update=update_cluster.model_dump(by_alias=False, exclude_none=True)) + new_cluster = old_cluster.copy( + update=update_cluster.model_dump(mode="json", by_alias=False, exclude_none=True) + ) new_storages_by_areas[area_id][storage_id] = new_cluster # Convert the DTO to a configuration object and update the configuration file. properties = create_st_storage_config( - study.version, **new_cluster.model_dump(by_alias=False, exclude_none=True) + study.version, **new_cluster.model_dump(mode="json", by_alias=False, exclude_none=True) ) path = _STORAGE_LIST_PATH.format(area_id=area_id, storage_id=storage_id) cmd = UpdateConfig( @@ -467,7 +469,7 @@ def update_storage( old_config = create_st_storage_config(study_version, **values) # use Python values to synchronize Config and Form values - new_values = form.model_dump(by_alias=False, exclude_none=True) + new_values = form.model_dump(mode="json", by_alias=False, exclude_none=True) new_config = old_config.copy(exclude={"id"}, update=new_values) new_data = new_config.model_dump(mode="json", by_alias=True, exclude={"id"}) @@ -487,7 +489,7 @@ def update_storage( ] execute_or_add_commands(study, file_study, commands, self.storage_service) - values = new_config.model_dump(by_alias=False) + values = new_config.model_dump(mode="json", by_alias=False) return STStorageOutput(**values, id=storage_id) def delete_storages( @@ -549,7 +551,9 @@ def duplicate_cluster(self, study: Study, area_id: str, source_id: str, new_clus # We should remove the field 'enabled' for studies before v8.8 as it didn't exist if int(study.version) < 880: fields_to_exclude.add("enabled") - creation_form = STStorageCreation(**current_cluster.model_dump(by_alias=False, exclude=fields_to_exclude)) + creation_form = STStorageCreation( + **current_cluster.model_dump(mode="json", by_alias=False, exclude=fields_to_exclude) + ) new_config = creation_form.to_config(study.version) create_cluster_cmd = self._make_create_cluster_cmd(area_id, new_config) @@ -578,7 +582,7 @@ def duplicate_cluster(self, study: Study, area_id: str, source_id: str, new_clus execute_or_add_commands(study, self._get_file_study(study), commands, self.storage_service) - return STStorageOutput(**new_config.model_dump(by_alias=False)) + return STStorageOutput(**new_config.model_dump(mode="json", by_alias=False)) def get_matrix( self, diff --git a/antarest/study/business/areas/thermal_management.py b/antarest/study/business/areas/thermal_management.py index c1a06068aa..74f6be680d 100644 --- a/antarest/study/business/areas/thermal_management.py +++ b/antarest/study/business/areas/thermal_management.py @@ -71,7 +71,7 @@ def json_schema_extra(schema: t.MutableMapping[str, t.Any]) -> None: nominal_capacity=1000.0, gen_ts="use global", co2=7.0, - ).model_dump() + ).model_dump(mode="json") @camel_case_model @@ -91,7 +91,7 @@ def validate_name(cls, name: t.Optional[str]) -> str: return name def to_config(self, study_version: t.Union[str, int]) -> ThermalConfigType: - values = self.model_dump(by_alias=False, exclude_none=True) + values = self.model_dump(mode="json", by_alias=False, exclude_none=True) return create_thermal_config(study_version=study_version, **values) @@ -114,7 +114,7 @@ def json_schema_extra(schema: t.MutableMapping[str, t.Any]) -> None: nominal_capacity=1000.0, gen_ts="use global", co2=7.0, - ).model_dump() + ).model_dump(mode="json") def create_thermal_output( @@ -123,7 +123,7 @@ def create_thermal_output( config: t.Mapping[str, t.Any], ) -> "ThermalClusterOutput": obj = create_thermal_config(study_version=study_version, **config, id=cluster_id) - kwargs = obj.model_dump(by_alias=False) + kwargs = obj.model_dump(mode="json", by_alias=False) return ThermalClusterOutput(**kwargs) @@ -254,12 +254,14 @@ def update_thermals_props( for thermal_id, update_cluster in update_thermals_by_ids.items(): # Update the thermal cluster properties. old_cluster = old_thermals_by_ids[thermal_id] - new_cluster = old_cluster.copy(update=update_cluster.model_dump(by_alias=False, exclude_none=True)) + new_cluster = old_cluster.copy( + update=update_cluster.model_dump(mode="json", by_alias=False, exclude_none=True) + ) new_thermals_by_areas[area_id][thermal_id] = new_cluster # Convert the DTO to a configuration object and update the configuration file. properties = create_thermal_config( - study.version, **new_cluster.model_dump(by_alias=False, exclude_none=True) + study.version, **new_cluster.model_dump(mode="json", by_alias=False, exclude_none=True) ) path = _CLUSTER_PATH.format(area_id=area_id, cluster_id=thermal_id) cmd = UpdateConfig( @@ -351,7 +353,7 @@ def update_cluster( old_config = create_thermal_config(study_version, **values) # Use Python values to synchronize Config and Form values - new_values = cluster_data.model_dump(by_alias=False, exclude_none=True) + new_values = cluster_data.model_dump(mode="json", by_alias=False, exclude_none=True) new_config = old_config.copy(exclude={"id"}, update=new_values) new_data = new_config.model_dump(mode="json", by_alias=True, exclude={"id"}) @@ -423,7 +425,7 @@ def duplicate_cluster( # Cluster duplication source_cluster = self.get_cluster(study, area_id, source_id) source_cluster.name = new_cluster_name - creation_form = ThermalClusterCreation(**source_cluster.model_dump(by_alias=False, exclude={"id"})) + creation_form = ThermalClusterCreation(**source_cluster.model_dump(mode="json", by_alias=False, exclude={"id"})) new_config = creation_form.to_config(study.version) create_cluster_cmd = self._make_create_cluster_cmd(area_id, new_config) @@ -456,7 +458,7 @@ def duplicate_cluster( execute_or_add_commands(study, self._get_file_study(study), commands, self.storage_service) - return ThermalClusterOutput(**new_config.model_dump(by_alias=False)) + return ThermalClusterOutput(**new_config.model_dump(mode="json", by_alias=False)) def validate_series(self, study: Study, area_id: str, cluster_id: str) -> bool: lower_cluster_id = cluster_id.lower() diff --git a/antarest/study/business/link_management.py b/antarest/study/business/link_management.py index 6f696d2a5e..65c8a415e5 100644 --- a/antarest/study/business/link_management.py +++ b/antarest/study/business/link_management.py @@ -122,7 +122,7 @@ def get_all_links_props(self, study: RawStudy) -> t.Mapping[t.Tuple[str, str], L for area2_id, properties_cfg in property_map.items(): area1_id, area2_id = sorted([area1_id, area2_id]) properties = LinkProperties(**properties_cfg) - links_by_ids[(area1_id, area2_id)] = LinkOutput(**properties.model_dump(by_alias=False)) + links_by_ids[(area1_id, area2_id)] = LinkOutput(**properties.model_dump(mode="json", by_alias=False)) return links_by_ids @@ -138,7 +138,9 @@ def update_links_props( for (area1, area2), update_link_dto in update_links_by_ids.items(): # Update the link properties. old_link_dto = old_links_by_ids[(area1, area2)] - new_link_dto = old_link_dto.copy(update=update_link_dto.model_dump(by_alias=False, exclude_none=True)) + new_link_dto = old_link_dto.copy( + update=update_link_dto.model_dump(mode="json", by_alias=False, exclude_none=True) + ) new_links_by_ids[(area1, area2)] = new_link_dto # Convert the DTO to a configuration object and update the configuration file. diff --git a/antarest/study/business/table_mode_management.py b/antarest/study/business/table_mode_management.py index 342c1c5abb..b108c57cb8 100644 --- a/antarest/study/business/table_mode_management.py +++ b/antarest/study/business/table_mode_management.py @@ -95,11 +95,11 @@ def __init__( def _get_table_data_unsafe(self, study: RawStudy, table_type: TableModeType) -> TableDataDTO: if table_type == TableModeType.AREA: areas_map = self._area_manager.get_all_area_props(study) - data = {area_id: area.model_dump(by_alias=True) for area_id, area in areas_map.items()} + data = {area_id: area.model_dump(mode="json", by_alias=True) for area_id, area in areas_map.items()} elif table_type == TableModeType.LINK: links_map = self._link_manager.get_all_links_props(study) data = { - f"{area1_id} / {area2_id}": link.model_dump(by_alias=True) + f"{area1_id} / {area2_id}": link.model_dump(mode="json", by_alias=True) for (area1_id, area2_id), link in links_map.items() } elif table_type == TableModeType.THERMAL: diff --git a/antarest/study/business/thematic_trimming_management.py b/antarest/study/business/thematic_trimming_management.py index 96bd5732d6..74325215dd 100644 --- a/antarest/study/business/thematic_trimming_management.py +++ b/antarest/study/business/thematic_trimming_management.py @@ -49,7 +49,7 @@ def set_field_values(self, study: Study, field_values: ThematicTrimmingFormField Set Thematic Trimming config from the webapp form """ file_study = self.storage_service.get_storage(study).get_raw(study) - field_values_dict = field_values.model_dump() + field_values_dict = field_values.model_dump(mode="json") keys_by_bool: t.Dict[bool, t.List[t.Any]] = {True: [], False: []} fields_info = get_fields_info(int(study.version)) diff --git a/antarest/study/business/timeseries_config_management.py b/antarest/study/business/timeseries_config_management.py index 7e77612fd8..20f389a6aa 100644 --- a/antarest/study/business/timeseries_config_management.py +++ b/antarest/study/business/timeseries_config_management.py @@ -133,7 +133,7 @@ def __set_field_values_for_type( field_values: TSFormFieldsForType, ) -> None: commands: t.List[UpdateConfig] = [] - values = field_values.model_dump() + values = field_values.model_dump(mode="json") for field, path in PATH_BY_TS_STR_FIELD.items(): field_val = values[field] diff --git a/antarest/study/service.py b/antarest/study/service.py index 1f8ff6a09d..65e3c474e4 100644 --- a/antarest/study/service.py +++ b/antarest/study/service.py @@ -1331,7 +1331,7 @@ def export_task(_notifier: TaskUpdateNotifier) -> TaskResult: return FileResponse(tmp_export_file, headers=headers, media_type=filetype) else: - json_response = to_json(matrix.model_dump()) + json_response = to_json(matrix.model_dump(mode="json")) return Response(content=json_response, media_type="application/json") def get_study_sim_result(self, study_id: str, params: RequestParameters) -> t.List[StudySimResultDTO]: @@ -2426,7 +2426,7 @@ def unarchive_output_task( src=str(src), dest=str(dest), remove_src=not keep_src_zip, - ).model_dump(), + ).model_dump(mode="json"), name=task_name, ref_id=study.id, request_params=params, diff --git a/antarest/study/storage/variantstudy/model/command/icommand.py b/antarest/study/storage/variantstudy/model/command/icommand.py index eb9a1f1285..537b5ddb5b 100644 --- a/antarest/study/storage/variantstudy/model/command/icommand.py +++ b/antarest/study/storage/variantstudy/model/command/icommand.py @@ -139,8 +139,8 @@ def match(self, other: "ICommand", equal: bool = False) -> bool: if not isinstance(other, self.__class__): return False excluded_fields = set(ICommand.model_fields) - this_values = self.model_dump(exclude=excluded_fields) - that_values = other.model_dump(exclude=excluded_fields) + this_values = self.model_dump(mode="json", exclude=excluded_fields) + that_values = other.model_dump(mode="json", exclude=excluded_fields) return this_values == that_values @abstractmethod diff --git a/tests/cache/test_local_cache.py b/tests/cache/test_local_cache.py index 8f8643d2f4..b779a2df08 100644 --- a/tests/cache/test_local_cache.py +++ b/tests/cache/test_local_cache.py @@ -41,11 +41,11 @@ def test_lifecycle(): id = "some_id" duration = 3600 timeout = int(time.time()) + duration - cache_element = LocalCacheElement(duration=duration, data=config.model_dump(), timeout=timeout) + cache_element = LocalCacheElement(duration=duration, data=config.model_dump(mode="json"), timeout=timeout) # PUT - cache.put(id=id, data=config.model_dump(), duration=duration) + cache.put(id=id, data=config.model_dump(mode="json"), duration=duration) assert cache.cache[id] == cache_element # GET - assert cache.get(id=id) == config.model_dump() + assert cache.get(id=id) == config.model_dump(mode="json") diff --git a/tests/cache/test_redis_cache.py b/tests/cache/test_redis_cache.py index b3d9cabefd..54affdc8f7 100644 --- a/tests/cache/test_redis_cache.py +++ b/tests/cache/test_redis_cache.py @@ -40,7 +40,7 @@ def test_lifecycle(): id = "some_id" redis_key = f"cache:{id}" duration = 3600 - cache_element = RedisCacheElement(duration=duration, data=config.model_dump()).model_dump_json() + cache_element = RedisCacheElement(duration=duration, data=config.model_dump(mode="json")).model_dump_json() # GET redis_client.get.return_value = cache_element @@ -51,7 +51,7 @@ def test_lifecycle(): # PUT duration = 7200 - cache_element = RedisCacheElement(duration=duration, data=config.model_dump()).model_dump_json() - cache.put(id=id, data=config.model_dump(), duration=duration) + cache_element = RedisCacheElement(duration=duration, data=config.model_dump(mode="json")).model_dump_json() + cache.put(id=id, data=config.model_dump(mode="json"), duration=duration) redis_client.set.assert_called_once_with(redis_key, cache_element) redis_client.expire.assert_called_with(redis_key, duration) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 42b8cb2407..50eb2e267b 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -606,15 +606,15 @@ def test_area_management(client: TestClient, admin_access_token: str) -> None: res = client.get(f"/v1/studies/{study_id}/layers") res.raise_for_status() - assert res.json() == [LayerInfoDTO(id="0", name="All", areas=["area 1", "area 2"]).model_dump()] + assert res.json() == [LayerInfoDTO(id="0", name="All", areas=["area 1", "area 2"]).model_dump(mode="json")] res = client.post(f"/v1/studies/{study_id}/layers?name=test") assert res.json() == "1" res = client.get(f"/v1/studies/{study_id}/layers") assert res.json() == [ - LayerInfoDTO(id="0", name="All", areas=["area 1", "area 2"]).model_dump(), - LayerInfoDTO(id="1", name="test", areas=[]).model_dump(), + LayerInfoDTO(id="0", name="All", areas=["area 1", "area 2"]).model_dump(mode="json"), + LayerInfoDTO(id="1", name="test", areas=[]).model_dump(mode="json"), ] res = client.put(f"/v1/studies/{study_id}/layers/1?name=test2") @@ -625,8 +625,8 @@ def test_area_management(client: TestClient, admin_access_token: str) -> None: assert res.status_code in {200, 201}, res.json() res = client.get(f"/v1/studies/{study_id}/layers") assert res.json() == [ - LayerInfoDTO(id="0", name="All", areas=["area 1", "area 2"]).model_dump(), - LayerInfoDTO(id="1", name="test2", areas=["area 2"]).model_dump(), + LayerInfoDTO(id="0", name="All", areas=["area 1", "area 2"]).model_dump(mode="json"), + LayerInfoDTO(id="1", name="test2", areas=["area 2"]).model_dump(mode="json"), ] # Delete the layer '1' that has 1 area From 2a705eeac5d6bcbd6606e3a61d22406ba19eb4ac Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 10:16:32 +0200 Subject: [PATCH 11/56] use StrEnum --- antarest/core/config.py | 4 ++-- antarest/core/configdata/model.py | 4 ++-- antarest/core/interfaces/eventbus.py | 4 ++-- antarest/core/maintenance/model.py | 4 ++-- antarest/core/model.py | 4 ++-- antarest/core/tasks/model.py | 4 ++-- antarest/eventbus/web.py | 4 ++-- antarest/launcher/model.py | 6 +++--- antarest/service_creator.py | 4 ++-- antarest/study/business/aggregator_management.py | 12 ++++++------ antarest/study/business/enum_ignore_case.py | 2 +- .../study/business/scenario_builder_management.py | 2 +- antarest/study/model.py | 6 +++--- antarest/study/repository.py | 2 +- .../rawstudy/model/filesystem/matrix/matrix.py | 4 ++-- .../root/output/simulation/mode/common/area.py | 4 ++-- .../root/output/simulation/mode/common/link.py | 4 ++-- .../root/output/simulation/mode/common/set.py | 4 ++-- antarest/study/web/study_data_blueprint.py | 2 +- 19 files changed, 40 insertions(+), 40 deletions(-) diff --git a/antarest/core/config.py b/antarest/core/config.py index 4b85331d6a..0f76ef0be4 100644 --- a/antarest/core/config.py +++ b/antarest/core/config.py @@ -13,7 +13,7 @@ import multiprocessing import tempfile from dataclasses import asdict, dataclass, field -from enum import Enum +from enum import StrEnum from pathlib import Path from typing import Dict, List, Optional @@ -25,7 +25,7 @@ DEFAULT_WORKSPACE_NAME = "default" -class Launcher(str, Enum): +class Launcher(StrEnum): SLURM = "slurm" LOCAL = "local" DEFAULT = "default" diff --git a/antarest/core/configdata/model.py b/antarest/core/configdata/model.py index 3e0d6b970e..af599d8861 100644 --- a/antarest/core/configdata/model.py +++ b/antarest/core/configdata/model.py @@ -10,7 +10,7 @@ # # This file is part of the Antares project. -from enum import Enum +from enum import StrEnum from typing import Any, Optional from pydantic import BaseModel @@ -43,6 +43,6 @@ def to_dto(self) -> ConfigDataDTO: # APP MAIN CONFIG KEYS -class ConfigDataAppKeys(str, Enum): +class ConfigDataAppKeys(StrEnum): MAINTENANCE_MODE = "MAINTENANCE_MODE" MESSAGE_INFO = "MESSAGE_INFO" diff --git a/antarest/core/interfaces/eventbus.py b/antarest/core/interfaces/eventbus.py index 10965ea831..8ac715e459 100644 --- a/antarest/core/interfaces/eventbus.py +++ b/antarest/core/interfaces/eventbus.py @@ -11,7 +11,7 @@ # This file is part of the Antares project. from abc import ABC, abstractmethod -from enum import Enum +from enum import StrEnum from typing import Any, Awaitable, Callable, List, Optional from pydantic import BaseModel @@ -19,7 +19,7 @@ from antarest.core.model import PermissionInfo -class EventType(str, Enum): +class EventType(StrEnum): ANY = "_ANY" STUDY_CREATED = "STUDY_CREATED" STUDY_DELETED = "STUDY_DELETED" diff --git a/antarest/core/maintenance/model.py b/antarest/core/maintenance/model.py index c133e4ea9f..c17beadbc3 100644 --- a/antarest/core/maintenance/model.py +++ b/antarest/core/maintenance/model.py @@ -10,10 +10,10 @@ # # This file is part of the Antares project. -from enum import Enum +from enum import StrEnum -class MaintenanceMode(str, Enum): +class MaintenanceMode(StrEnum): NORMAL_MODE = "NORMAL" MAINTENANCE_MODE = "MAINTENANCE" diff --git a/antarest/core/model.py b/antarest/core/model.py index b500e9a5c5..b086745064 100644 --- a/antarest/core/model.py +++ b/antarest/core/model.py @@ -24,7 +24,7 @@ SUB_JSON = Union[ELEMENT, JSON, List[Any], None] -class PublicMode(str, enum.Enum): +class PublicMode(enum.StrEnum): NONE = "NONE" READ = "READ" EXECUTE = "EXECUTE" @@ -32,7 +32,7 @@ class PublicMode(str, enum.Enum): FULL = "FULL" -class StudyPermissionType(str, enum.Enum): +class StudyPermissionType(enum.StrEnum): """ User permission belongs to Study """ diff --git a/antarest/core/tasks/model.py b/antarest/core/tasks/model.py index a7ca9aedb9..7c73506604 100644 --- a/antarest/core/tasks/model.py +++ b/antarest/core/tasks/model.py @@ -13,7 +13,7 @@ import typing as t import uuid from datetime import datetime -from enum import Enum +from enum import Enum, StrEnum from pydantic import BaseModel from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, Sequence, String # type: ignore @@ -28,7 +28,7 @@ from antarest.study.model import Study -class TaskType(str, Enum): +class TaskType(StrEnum): EXPORT = "EXPORT" VARIANT_GENERATION = "VARIANT_GENERATION" COPY = "COPY" diff --git a/antarest/eventbus/web.py b/antarest/eventbus/web.py index a04a4571bb..d997e1251d 100644 --- a/antarest/eventbus/web.py +++ b/antarest/eventbus/web.py @@ -12,7 +12,7 @@ import dataclasses import logging -from enum import Enum +from enum import StrEnum from http import HTTPStatus from typing import List, Optional @@ -33,7 +33,7 @@ logger = logging.getLogger(__name__) -class WebsocketMessageAction(str, Enum): +class WebsocketMessageAction(StrEnum): SUBSCRIBE = "SUBSCRIBE" UNSUBSCRIBE = "UNSUBSCRIBE" diff --git a/antarest/launcher/model.py b/antarest/launcher/model.py index b26a502795..5096228635 100644 --- a/antarest/launcher/model.py +++ b/antarest/launcher/model.py @@ -57,7 +57,7 @@ def from_launcher_params(cls, params: t.Optional[str]) -> "LauncherParametersDTO return cls.model_validate(from_json(params)) -class LogType(str, enum.Enum): +class LogType(enum.StrEnum): STDOUT = "STDOUT" STDERR = "STDERR" @@ -79,14 +79,14 @@ def to_suffix(self) -> str: return "out.log" -class JobStatus(str, enum.Enum): +class JobStatus(enum.StrEnum): PENDING = "pending" FAILED = "failed" SUCCESS = "success" RUNNING = "running" -class JobLogType(str, enum.Enum): +class JobLogType(enum.StrEnum): BEFORE = "BEFORE" AFTER = "AFTER" diff --git a/antarest/service_creator.py b/antarest/service_creator.py index 5859806a61..04d9da626a 100644 --- a/antarest/service_creator.py +++ b/antarest/service_creator.py @@ -12,7 +12,7 @@ import logging import typing as t -from enum import Enum +from enum import StrEnum from pathlib import Path import redis @@ -67,7 +67,7 @@ """ -class Module(str, Enum): +class Module(StrEnum): APP = "app" WATCHER = "watcher" MATRIX_GC = "matrix_gc" diff --git a/antarest/study/business/aggregator_management.py b/antarest/study/business/aggregator_management.py index 7f961f7e91..df5bbaa30b 100644 --- a/antarest/study/business/aggregator_management.py +++ b/antarest/study/business/aggregator_management.py @@ -12,7 +12,7 @@ import logging import typing as t -from enum import Enum +from enum import StrEnum from pathlib import Path import numpy as np @@ -54,19 +54,19 @@ logger = logging.getLogger(__name__) -class MCRoot(str, Enum): +class MCRoot(StrEnum): MC_IND = "mc-ind" MC_ALL = "mc-all" -class MCIndAreasQueryFile(str, Enum): +class MCIndAreasQueryFile(StrEnum): VALUES = "values" DETAILS = "details" DETAILS_ST_STORAGE = "details-STstorage" DETAILS_RES = "details-res" -class MCAllAreasQueryFile(str, Enum): +class MCAllAreasQueryFile(StrEnum): VALUES = "values" DETAILS = "details" DETAILS_ST_STORAGE = "details-STstorage" @@ -74,11 +74,11 @@ class MCAllAreasQueryFile(str, Enum): ID = "id" -class MCIndLinksQueryFile(str, Enum): +class MCIndLinksQueryFile(StrEnum): VALUES = "values" -class MCAllLinksQueryFile(str, Enum): +class MCAllLinksQueryFile(StrEnum): VALUES = "values" ID = "id" diff --git a/antarest/study/business/enum_ignore_case.py b/antarest/study/business/enum_ignore_case.py index 2259d229f7..9d0bcf3396 100644 --- a/antarest/study/business/enum_ignore_case.py +++ b/antarest/study/business/enum_ignore_case.py @@ -14,7 +14,7 @@ import typing -class EnumIgnoreCase(str, enum.Enum): +class EnumIgnoreCase(enum.StrEnum): """ Case-insensitive enum base class diff --git a/antarest/study/business/scenario_builder_management.py b/antarest/study/business/scenario_builder_management.py index c8a38b28c3..ac5a6a2bb6 100644 --- a/antarest/study/business/scenario_builder_management.py +++ b/antarest/study/business/scenario_builder_management.py @@ -37,7 +37,7 @@ Rulesets: te.TypeAlias = t.MutableMapping[str, Ruleset] -class ScenarioType(str, enum.Enum): +class ScenarioType(enum.StrEnum): """ Scenario type diff --git a/antarest/study/model.py b/antarest/study/model.py index 081fd48b4a..b7e7435f6f 100644 --- a/antarest/study/model.py +++ b/antarest/study/model.py @@ -409,13 +409,13 @@ class StudySimResultDTO(BaseModel): archived: bool -class StudyDownloadType(str, enum.Enum): +class StudyDownloadType(enum.StrEnum): LINK = "LINK" DISTRICT = "DISTRICT" AREA = "AREA" -class StudyDownloadLevelDTO(str, enum.Enum): +class StudyDownloadLevelDTO(enum.StrEnum): ANNUAL = "annual" MONTHLY = "monthly" WEEKLY = "weekly" @@ -440,7 +440,7 @@ def inc_date(self, date: datetime) -> datetime: raise ShouldNotHappenException() -class ExportFormat(str, enum.Enum): +class ExportFormat(enum.StrEnum): ZIP = "application/zip" TAR_GZ = "application/tar+gz" JSON = "application/json" diff --git a/antarest/study/repository.py b/antarest/study/repository.py index f4d2e691c1..3b21511e0b 100644 --- a/antarest/study/repository.py +++ b/antarest/study/repository.py @@ -118,7 +118,7 @@ class StudyFilter(BaseModel, frozen=True, extra="forbid"): access_permissions: AccessPermissions = AccessPermissions() -class StudySortBy(str, enum.Enum): +class StudySortBy(enum.StrEnum): """How to sort the results of studies query results""" NAME_ASC = "+name" diff --git a/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py b/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py index 364a5e3524..95d994d7df 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py +++ b/antarest/study/storage/rawstudy/model/filesystem/matrix/matrix.py @@ -12,7 +12,7 @@ import logging from abc import ABC, abstractmethod -from enum import Enum +from enum import StrEnum from pathlib import Path from typing import Any, List, Optional, Union, cast @@ -27,7 +27,7 @@ logger = logging.getLogger(__name__) -class MatrixFrequency(str, Enum): +class MatrixFrequency(StrEnum): """ An enumeration of matrix frequencies. diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py index f42637b298..0b97fa5735 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/area.py @@ -33,9 +33,9 @@ def build(self) -> TREE: freq: MatrixFrequency for freq in MatrixFrequency: for output_type in ["id", "values", "details", "details-res", "details-STstorage"]: - file_name = f"{output_type}-{freq.value}.txt" + file_name = f"{output_type}-{freq}.txt" if (self.config.path / file_name).exists(): - children[f"{output_type}-{freq.value}"] = AreaOutputSeriesMatrix( + children[f"{output_type}-{freq}"] = AreaOutputSeriesMatrix( self.context, self.config.next_file(file_name), freq, diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py index e3b83c1349..b5f0b15dcb 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/link.py @@ -35,9 +35,9 @@ def build(self) -> TREE: freq: MatrixFrequency for freq in MatrixFrequency: for output_type in ["id", "values"]: - file_name = f"{output_type}-{freq.value}.txt" + file_name = f"{output_type}-{freq}.txt" if (self.config.path / file_name).exists(): - children[f"{output_type}-{freq.value}"] = LinkOutputSeriesMatrix( + children[f"{output_type}-{freq}"] = LinkOutputSeriesMatrix( self.context, self.config.next_file(file_name), freq, diff --git a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py index 7ac2b3cd5e..4c8a624a5c 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py +++ b/antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/common/set.py @@ -33,9 +33,9 @@ def build(self) -> TREE: freq: MatrixFrequency for freq in MatrixFrequency: for output_type in ["id", "values"]: - file_name = f"{output_type}-{freq.value}.txt" + file_name = f"{output_type}-{freq}.txt" if (self.config.path / file_name).exists(): - children[f"{output_type}-{freq.value}"] = AreaOutputSeriesMatrix( + children[f"{output_type}-{freq}"] = AreaOutputSeriesMatrix( self.context, self.config.next_file(file_name), freq, diff --git a/antarest/study/web/study_data_blueprint.py b/antarest/study/web/study_data_blueprint.py index 2128ed849c..a6d39c7164 100644 --- a/antarest/study/web/study_data_blueprint.py +++ b/antarest/study/web/study_data_blueprint.py @@ -94,7 +94,7 @@ class BCKeyValueType(te.TypedDict): value: t.Union[str, int, float, bool] -class ClusterType(str, enum.Enum): +class ClusterType(enum.StrEnum): """ Cluster type: From c86bc8acfe6db20040ef80ca4d6101f13c94c601 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 10:27:58 +0200 Subject: [PATCH 12/56] fix 2 mypy issues still 10 test failures --- .../variantstudy/model/command/update_binding_constraint.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py b/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py index 530cc92dfd..043111a312 100644 --- a/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py +++ b/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py @@ -166,7 +166,7 @@ def _apply(self, study_data: FileStudy) -> CommandOutput: # rename matrices if the operator has changed for version >= 870 if self.operator and study_data.config.version >= 870: - existing_operator = BindingConstraintOperator(actual_cfg.get("operator")) + existing_operator = BindingConstraintOperator(actual_cfg["operator"]) new_operator = self.operator _update_matrices_names(study_data, self.id, existing_operator, new_operator) @@ -176,7 +176,7 @@ def _apply(self, study_data: FileStudy) -> CommandOutput: term for term in [m.value for m in TermMatrices] if hasattr(self, term) and getattr(self, term) ] study_version = study_data.config.version - time_step = self.time_step or BindingConstraintFrequency(actual_cfg.get("type")) + time_step = self.time_step or BindingConstraintFrequency(actual_cfg["type"]) self.validates_and_fills_matrices( time_step=time_step, specific_matrices=updated_matrices or None, version=study_version, create=False ) From 663e2931e53a67fd399225f272acce7b26463118 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 10:31:33 +0200 Subject: [PATCH 13/56] fix last failing tests --- tests/variantstudy/model/command/test_create_area.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/variantstudy/model/command/test_create_area.py b/tests/variantstudy/model/command/test_create_area.py index 0bb8c104c7..49d17eb9ac 100644 --- a/tests/variantstudy/model/command/test_create_area.py +++ b/tests/variantstudy/model/command/test_create_area.py @@ -23,6 +23,7 @@ from antarest.study.storage.variantstudy.model.command.remove_area import RemoveArea from antarest.study.storage.variantstudy.model.command.update_config import UpdateConfig from antarest.study.storage.variantstudy.model.command_context import CommandContext +from study.storage.rawstudy.ini_reader import IniReader class TestCreateArea: @@ -96,9 +97,9 @@ def test_apply( # Allocation assert (study_path / "input" / "hydro" / "allocation" / f"{area_id}.ini").exists() - allocation = configparser.ConfigParser() - allocation.read(study_path / "input" / "hydro" / "allocation" / f"{area_id}.ini") - assert int(allocation["[allocation"][area_id]) == 1 + reader = IniReader() + allocation = reader.read(study_path / "input" / "hydro" / "allocation" / f"{area_id}.ini") + assert int(allocation["[allocation]"][area_id]) == 1 # Capacity assert (study_path / "input" / "hydro" / "common" / "capacity" / f"maxpower_{area_id}.txt.link").exists() From 534df03b5f1b13f4cedc117dd0716fdad52ff612 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 10:45:50 +0200 Subject: [PATCH 14/56] fix all mypy issues --- .../filesystem/matrix/date_serializer.py | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/matrix/date_serializer.py b/antarest/study/storage/rawstudy/model/filesystem/matrix/date_serializer.py index cdc67b8ac5..4f2c6213cc 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/matrix/date_serializer.py +++ b/antarest/study/storage/rawstudy/model/filesystem/matrix/date_serializer.py @@ -10,6 +10,8 @@ # # This file is part of the Antares project. +from __future__ import annotations + import re from abc import ABC, abstractmethod from typing import Hashable, List, Sequence, Tuple, cast @@ -43,7 +45,7 @@ def __init__(self, area: str): self.area = area @abstractmethod - def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index, pd.DataFrame]: + def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index[str], pd.DataFrame]: """ Extract date from raw columns inside matrix file Args: @@ -54,7 +56,7 @@ def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index, pd.DataFrame]: raise NotImplementedError() @abstractmethod - def build_date(self, index: pd.Index) -> pd.DataFrame: + def build_date(self, index: pd.Index[str]) -> pd.DataFrame: """ Format in antares style date index Args: @@ -78,7 +80,7 @@ class HourlyMatrixSerializer(IDateMatrixSerializer): Class implementation for hourly index """ - def build_date(self, index: pd.Index) -> pd.DataFrame: + def build_date(self, index: pd.Index[str]) -> pd.DataFrame: def _map(row: str) -> Tuple[str, int, str, str, str]: m, d, h = re.split(r"[\s/]", row) return "", 1, d, IDateMatrixSerializer._R_MONTHS[m], h @@ -97,7 +99,7 @@ def _map(row: str) -> Tuple[str, int, str, str, str]: return pd.concat([headers, matrix], axis=0) - def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index, pd.DataFrame]: + def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index[str], pd.DataFrame]: # Extract left part with date df_date = df.iloc[:, 2:5] df_date.columns = pd.Index(data=["day", "month", "hour"]) @@ -108,7 +110,7 @@ def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index, pd.DataFrame]: to_remove = cast(Sequence[Hashable], df.columns[0:5]) body = df.drop(to_remove, axis=1) - return pd.Index(date), body + return cast(pd.Index[str], pd.Index(date)), body class DailyMatrixSerializer(IDateMatrixSerializer): @@ -116,7 +118,7 @@ class DailyMatrixSerializer(IDateMatrixSerializer): Class implementation for daily index """ - def build_date(self, index: pd.Index) -> pd.DataFrame: + def build_date(self, index: pd.Index[str]) -> pd.DataFrame: def _map(row: str) -> Tuple[str, int, str, str]: m, d = row.split("/") return "", 1, d, IDateMatrixSerializer._R_MONTHS[m] @@ -135,7 +137,7 @@ def _map(row: str) -> Tuple[str, int, str, str]: return pd.concat([headers, matrix], axis=0) - def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index, pd.DataFrame]: + def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index[str], pd.DataFrame]: # Extract left part with date df_date = df.iloc[:, 2:4] df_date.columns = pd.Index(["day", "month"]) @@ -146,7 +148,7 @@ def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index, pd.DataFrame]: to_remove = cast(Sequence[Hashable], df.columns[0:4]) body = df.drop(to_remove, axis=1) - return pd.Index(date), body + return cast(pd.Index[str], pd.Index(date)), body class WeeklyMatrixSerializer(IDateMatrixSerializer): @@ -154,7 +156,7 @@ class WeeklyMatrixSerializer(IDateMatrixSerializer): Class implementation for weekly index """ - def build_date(self, index: pd.Index) -> pd.DataFrame: + def build_date(self, index: pd.Index[str]) -> pd.DataFrame: matrix = pd.DataFrame({0: [""] * index.size, 1: index.values}) headers = pd.DataFrame( @@ -167,7 +169,7 @@ def build_date(self, index: pd.Index) -> pd.DataFrame: return pd.concat([headers, matrix], axis=0) - def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index, pd.DataFrame]: + def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index[str], pd.DataFrame]: # Extract left part with date df_date = df.iloc[:, 1:2] df_date.columns = pd.Index(["weekly"]) @@ -184,7 +186,7 @@ class MonthlyMatrixSerializer(IDateMatrixSerializer): Class implementation for monthly index """ - def build_date(self, index: pd.Index) -> pd.DataFrame: + def build_date(self, index: pd.Index[str]) -> pd.DataFrame: matrix = pd.DataFrame( { 0: [""] * index.size, @@ -203,7 +205,7 @@ def build_date(self, index: pd.Index) -> pd.DataFrame: return pd.concat([headers, matrix], axis=0) - def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index, pd.DataFrame]: + def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index[str], pd.DataFrame]: # Extract left part with date df_date = df.iloc[:, 2:3] df_date.columns = pd.Index(["month"]) @@ -222,7 +224,7 @@ class AnnualMatrixSerializer(IDateMatrixSerializer): Class implementation for annual index """ - def build_date(self, index: pd.Index) -> pd.DataFrame: + def build_date(self, index: pd.Index[str]) -> pd.DataFrame: return pd.DataFrame( [ [self.area.upper(), "annual"], @@ -232,7 +234,7 @@ def build_date(self, index: pd.Index) -> pd.DataFrame: ] ) - def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index, pd.DataFrame]: + def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index[str], pd.DataFrame]: # Extract left part with date df_date = df.iloc[:, 1:2] df_date.columns = pd.Index(["annual"]) From 6271165e4e4fb8ebea55618b5819951dc660f1b1 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 11:06:30 +0200 Subject: [PATCH 15/56] fix test --- .../rawstudy/model/filesystem/matrix/date_serializer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/antarest/study/storage/rawstudy/model/filesystem/matrix/date_serializer.py b/antarest/study/storage/rawstudy/model/filesystem/matrix/date_serializer.py index 4f2c6213cc..2b8c431085 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/matrix/date_serializer.py +++ b/antarest/study/storage/rawstudy/model/filesystem/matrix/date_serializer.py @@ -110,7 +110,7 @@ def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index[str], pd.DataFrame]: to_remove = cast(Sequence[Hashable], df.columns[0:5]) body = df.drop(to_remove, axis=1) - return cast(pd.Index[str], pd.Index(date)), body + return pd.Index(date), body # type: ignore class DailyMatrixSerializer(IDateMatrixSerializer): @@ -148,7 +148,7 @@ def extract_date(self, df: pd.DataFrame) -> Tuple[pd.Index[str], pd.DataFrame]: to_remove = cast(Sequence[Hashable], df.columns[0:4]) body = df.drop(to_remove, axis=1) - return cast(pd.Index[str], pd.Index(date)), body + return pd.Index(date), body # type: ignore class WeeklyMatrixSerializer(IDateMatrixSerializer): From d18a21595d7d9eb138b3c363379f8b1826a8e49b Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 11:38:41 +0200 Subject: [PATCH 16/56] try to bump pyinstaller to make desktop version work --- requirements-dev.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index af134f12be..274fe3cecd 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,8 +3,8 @@ black~=23.7.0 isort~=5.12.0 mypy~=1.11.1 -pyinstaller==5.6.2 -pyinstaller-hooks-contrib==2024.6 +pyinstaller==5.13.2 +pyinstaller-hooks-contrib==2024.8 # Extra requirements installed by `mypy --install-types`. # IMPORTANT: Make sure the versions of these typing libraries match the versions From 50a2bb4b860f23a3732ae5d468b2db668e33c012 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 13:30:45 +0200 Subject: [PATCH 17/56] fix test that failed the CI --- tests/variantstudy/model/command/test_create_area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/variantstudy/model/command/test_create_area.py b/tests/variantstudy/model/command/test_create_area.py index 49d17eb9ac..d6593a929b 100644 --- a/tests/variantstudy/model/command/test_create_area.py +++ b/tests/variantstudy/model/command/test_create_area.py @@ -15,6 +15,7 @@ import pytest +from antarest.study.storage.rawstudy.ini_reader import IniReader from antarest.study.storage.rawstudy.model.filesystem.config.model import EnrModelling, transform_name_to_id from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy from antarest.study.storage.variantstudy.business.command_reverter import CommandReverter @@ -23,7 +24,6 @@ from antarest.study.storage.variantstudy.model.command.remove_area import RemoveArea from antarest.study.storage.variantstudy.model.command.update_config import UpdateConfig from antarest.study.storage.variantstudy.model.command_context import CommandContext -from study.storage.rawstudy.ini_reader import IniReader class TestCreateArea: From 133635d161ffe771c0bdf14dbda7928334293b9c Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 14:22:24 +0200 Subject: [PATCH 18/56] update requirements to work only with 3.11 --- requirements-dev.txt | 3 +-- requirements.txt | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 274fe3cecd..f870f93f61 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -10,8 +10,7 @@ pyinstaller-hooks-contrib==2024.8 # IMPORTANT: Make sure the versions of these typing libraries match the versions # of the corresponding implementation libraries used in production (in `requirements.txt`). -pandas-stubs~=1.4.0; python_version <= '3.8' -pandas-stubs~=2.2.2; python_version > '3.8' +pandas-stubs~=2.2.2 types-paramiko~=3.4.0 types-psycopg2~=2.9.9 types-redis~=4.1.2 diff --git a/requirements.txt b/requirements.txt index 970558c60c..754e687968 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,21 +31,17 @@ gunicorn~=20.1.0 jsonref~=0.2 PyJWT~=2.9.0 MarkupSafe~=2.0.1 -numpy~=1.22.1; python_version <= '3.8' -numpy~=1.26.4; python_version > '3.8' -pandas~=1.4.0; python_version <= '3.8' -pandas~=2.2.3; python_version > '3.8' +numpy~=1.26.4 +pandas~=2.2.3 paramiko~=2.12.0 plyer~=2.0.0 psycopg2-binary~=2.9.9 py7zr~=0.20.6 PyQt5~=5.15.6 python-json-logger~=2.0.7 -PyYAML~=5.4.1; python_version <= '3.9' -PyYAML~=5.3.1; python_version > '3.9' +PyYAML~=5.3.1 redis~=4.1.2 SQLAlchemy~=1.4.46 -tables==3.6.1; python_version <= '3.8' -tables==3.9.2; python_version > '3.8' +tables==3.9.2 typing_extensions~=4.12.2 xlsxwriter~=3.2.0 \ No newline at end of file From 7e67b01ab85d3ff93c8d1825b1096df222d14bfc Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 14:34:22 +0200 Subject: [PATCH 19/56] simplify small parts of code with new python api --- antarest/matrixstore/service.py | 6 +----- tests/study/storage/test_abstract_storage_service.py | 7 +------ tests/variantstudy/conftest.py | 6 +----- tests/variantstudy/test_command_factory.py | 6 +----- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/antarest/matrixstore/service.py b/antarest/matrixstore/service.py index 7e9450fdec..b894600fb5 100644 --- a/antarest/matrixstore/service.py +++ b/antarest/matrixstore/service.py @@ -100,11 +100,7 @@ def get_matrix_id(self, matrix: t.Union[t.List[t.List[float]], str]) -> str: """ # noinspection SpellCheckingInspection if isinstance(matrix, str): - # str.removeprefix() is not available in Python 3.8 - prefix = "matrix://" - if matrix.startswith(prefix): - return matrix[len(prefix) :] - return matrix + return matrix.removeprefix("matrix://") elif isinstance(matrix, list): return self.create(matrix) else: diff --git a/tests/study/storage/test_abstract_storage_service.py b/tests/study/storage/test_abstract_storage_service.py index 97793c206d..8a7be798bd 100644 --- a/tests/study/storage/test_abstract_storage_service.py +++ b/tests/study/storage/test_abstract_storage_service.py @@ -91,12 +91,7 @@ def __init__(self, tmp_path: Path): def __eq__(self, other: Path): if isinstance(other, Path) and other.name == "tmp_copy": - # `is_relative_to` is not available for Python < 3.9 - try: - other.relative_to(self.tmp_path) - return True - except ValueError: - return False + return other.is_relative_to(self.tmp_path) def __ne__(self, other): return not self.__eq__(other) diff --git a/tests/variantstudy/conftest.py b/tests/variantstudy/conftest.py index beaaf34065..6d3039d4f9 100644 --- a/tests/variantstudy/conftest.py +++ b/tests/variantstudy/conftest.py @@ -94,11 +94,7 @@ def get_matrix_id(matrix: t.Union[t.List[t.List[float]], str]) -> str: Get the matrix ID from a matrix or a matrix link. """ if isinstance(matrix, str): - # str.removeprefix() is not available in Python 3.8 - prefix = "matrix://" - if matrix.startswith(prefix): - return matrix[len(prefix) :] - return matrix + return matrix.removeprefix("matrix://") elif isinstance(matrix, list): return create(matrix) else: diff --git a/tests/variantstudy/test_command_factory.py b/tests/variantstudy/test_command_factory.py index b78ba393e5..dd47e0453c 100644 --- a/tests/variantstudy/test_command_factory.py +++ b/tests/variantstudy/test_command_factory.py @@ -386,11 +386,7 @@ @pytest.fixture def command_factory() -> CommandFactory: def get_matrix_id(matrix: str) -> str: - # str.removeprefix() is not available in Python 3.8 - prefix = "matrix://" - if matrix.startswith(prefix): - return matrix[len(prefix) :] - return matrix + return matrix.removeprefix("matrix://") return CommandFactory( generator_matrix_constants=Mock(spec=GeneratorMatrixConstants), From 0e598b6f5872455cb84d7d37b31deca8bfade5bd Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 14:40:42 +0200 Subject: [PATCH 20/56] use 3.11 inside other files than .py --- docs/install/0-INSTALL.md | 2 +- pyproject.toml | 9 +++------ readthedocs.yml | 2 +- sonar-project.properties | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/docs/install/0-INSTALL.md b/docs/install/0-INSTALL.md index 388f98b5f7..8206af7c6e 100644 --- a/docs/install/0-INSTALL.md +++ b/docs/install/0-INSTALL.md @@ -8,7 +8,7 @@ A local build allows using Antares Web as a desktop application. Requirements: -- python : 3.8.x +- python : 3.11.x - node : 18.16.1 Then perform the following steps: diff --git a/pyproject.toml b/pyproject.toml index 42c259d133..cfde64c238 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,12 +8,9 @@ authors = [{name="RTE, Antares Web Team", email="andrea.sgattoni@rte-france.com" description="Antares Server" readme = {file = "README.md", content-type = "text/markdown"} license = {file = "LICENSE"} -requires-python = ">=3.8" +requires-python = ">=3.11" classifiers=[ "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "License :: Apache License :: 2.0", "Operating System :: OS Independent", @@ -126,8 +123,8 @@ exclude = [ line-length = 120 indent-width = 4 -# Assume Python 3.8 -target-version = "py38" +# Assumes Python 3.11 +target-version = "py311" [tool.ruff.lint] # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. diff --git a/readthedocs.yml b/readthedocs.yml index bf990c8405..d0135160a8 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -8,7 +8,7 @@ version: 2 build: os: ubuntu-22.04 tools: - python: '3.8' + python: '3.11' mkdocs: configuration: mkdocs.yml diff --git a/sonar-project.properties b/sonar-project.properties index fa40909147..dd7384df7d 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -4,7 +4,7 @@ sonar.sources=antarest, webapp/src sonar.language=python, js sonar.exclusions=antarest/gui.py,antarest/main.py sonar.python.coverage.reportPaths=coverage.xml -sonar.python.version=3.8 +sonar.python.version=3.11 sonar.javascript.lcov.reportPaths=webapp/coverage/lcov.info sonar.projectVersion=2.17.6 sonar.coverage.exclusions=antarest/gui.py,antarest/main.py,antarest/singleton_services.py,antarest/worker/archive_worker_service.py,webapp/**/*,,antarest/fastapi_jwt_auth/** \ No newline at end of file From 134ada2bf84a54f6799ab88e0b6693791b614319 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 1 Oct 2024 15:02:33 +0200 Subject: [PATCH 21/56] bump version inside dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 975ef9b776..3c1ec7a8ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.8-slim-bullseye +FROM python:3.11-slim-bullseye # RUN apt update && apt install -y procps gdb From 7ea7c699e0ae5cd3a50ddf6225d4f12d477e15b6 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 2 Oct 2024 16:06:32 +0200 Subject: [PATCH 22/56] fix typing --- antarest/study/business/areas/st_storage_management.py | 3 ++- antarest/study/business/areas/thermal_management.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/antarest/study/business/areas/st_storage_management.py b/antarest/study/business/areas/st_storage_management.py index 3cd4641410..8c1a197861 100644 --- a/antarest/study/business/areas/st_storage_management.py +++ b/antarest/study/business/areas/st_storage_management.py @@ -397,7 +397,8 @@ def update_storages_props( # Convert the DTO to a configuration object and update the configuration file. properties = create_st_storage_config( - StudyVersion.parse(study.version), **new_cluster.model_dump(mode="json", by_alias=False, exclude_none=True) + StudyVersion.parse(study.version), + **new_cluster.model_dump(mode="json", by_alias=False, exclude_none=True), ) path = _STORAGE_LIST_PATH.format(area_id=area_id, storage_id=storage_id) cmd = UpdateConfig( diff --git a/antarest/study/business/areas/thermal_management.py b/antarest/study/business/areas/thermal_management.py index 9775a71265..2786617cc1 100644 --- a/antarest/study/business/areas/thermal_management.py +++ b/antarest/study/business/areas/thermal_management.py @@ -262,7 +262,8 @@ def update_thermals_props( # Convert the DTO to a configuration object and update the configuration file. properties = create_thermal_config( - StudyVersion.parse(study.version), **new_cluster.model_dump(mode="json", by_alias=False, exclude_none=True) + StudyVersion.parse(study.version), + **new_cluster.model_dump(mode="json", by_alias=False, exclude_none=True), ) path = _CLUSTER_PATH.format(area_id=area_id, cluster_id=thermal_id) cmd = UpdateConfig( From 6a1303b8287789baae6f49b010bfef7ae30298f7 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Mon, 7 Oct 2024 11:26:15 +0200 Subject: [PATCH 23/56] try to bump pyinstaller --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index f870f93f61..42db471fc0 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ black~=23.7.0 isort~=5.12.0 mypy~=1.11.1 -pyinstaller==5.13.2 +pyinstaller==6.10.0 pyinstaller-hooks-contrib==2024.8 # Extra requirements installed by `mypy --install-types`. From 02845d3b11d32bf8b87667bba92b19cc8670bf11 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Mon, 7 Oct 2024 13:24:26 +0200 Subject: [PATCH 24/56] test debug=True inside EXE .spec file --- .github/workflows/deploy.yml | 2 +- .github/workflows/license_header.yml | 2 +- .github/workflows/main.yml | 2 +- .github/workflows/worker.yml | 4 +--- AntaresWebWin.spec | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 476a2b5781..410a8d40ce 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,7 +12,7 @@ jobs: strategy: max-parallel: 3 matrix: - os: [ windows-latest, ubuntu-20.04, ubuntu-22.04] + os: [windows-latest] steps: - name: 🐙 Checkout GitHub repo (+ download lfs dependencies) diff --git a/.github/workflows/license_header.yml b/.github/workflows/license_header.yml index cf577e51c9..70176d69a5 100644 --- a/.github/workflows/license_header.yml +++ b/.github/workflows/license_header.yml @@ -2,7 +2,7 @@ name: check license headers on: push: branches: - - "**" + - "ohohohoh" jobs: check-license-headers: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0e41bf08b1..068b4dfa8c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: main on: push: branches: - - "**" + - "ohohoh" jobs: python-lint: diff --git a/.github/workflows/worker.yml b/.github/workflows/worker.yml index feca22fdb6..3bd0d1e9c0 100644 --- a/.github/workflows/worker.yml +++ b/.github/workflows/worker.yml @@ -2,9 +2,7 @@ name: worker on: push: branches: - - "master" - - "worker/**" - - "bump-python/**" + - "ohohoh" jobs: binary: diff --git a/AntaresWebWin.spec b/AntaresWebWin.spec index baa0c614db..eee324b50f 100644 --- a/AntaresWebWin.spec +++ b/AntaresWebWin.spec @@ -36,7 +36,7 @@ antares_web_server_exe = EXE(antares_web_server_pyz, [], exclude_binaries=True, name='AntaresWebServer', - debug=False, + debug=True, bootloader_ignore_signals=False, strip=False, upx=True, From f80dfbec4e75f212fdfd2f5f31adeac893d511d6 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Mon, 7 Oct 2024 14:12:28 +0200 Subject: [PATCH 25/56] add debug True always --- AntaresWebWin.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AntaresWebWin.spec b/AntaresWebWin.spec index eee324b50f..62c9a66b17 100644 --- a/AntaresWebWin.spec +++ b/AntaresWebWin.spec @@ -67,7 +67,7 @@ antares_tool_exe = EXE(antares_tool_pyz, [], exclude_binaries=True, name='AntaresTool', - debug=False, + debug=True, bootloader_ignore_signals=False, strip=False, upx=True, From 1e58a52791927938dd90e3585bc43ae85fd2d2d1 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 8 Oct 2024 09:54:45 +0200 Subject: [PATCH 26/56] try to change stdout --- antarest/gui.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/antarest/gui.py b/antarest/gui.py index f36904a060..8b0c57d7c9 100644 --- a/antarest/gui.py +++ b/antarest/gui.py @@ -10,6 +10,14 @@ # # This file is part of the Antares project. +import os +import sys + +if sys.stdout is None: + sys.stdout = open(os.devnull, "w") +if sys.stderr is None: + sys.stderr = open(os.devnull, "w") + import contextlib import multiprocessing import platform From 449b28c4e87945769994b06e83aded22c0314687 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 15 Oct 2024 16:37:50 +0200 Subject: [PATCH 27/56] revert changes inside gh actions --- .github/workflows/deploy.yml | 3 +-- .github/workflows/license_header.yml | 2 +- .github/workflows/main.yml | 2 +- .github/workflows/worker.yml | 3 ++- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 410a8d40ce..fc44a21f74 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,7 +4,6 @@ on: branches: - "master" - "hotfix/**" - - "bump-python/**" jobs: binary: @@ -12,7 +11,7 @@ jobs: strategy: max-parallel: 3 matrix: - os: [windows-latest] + os: [ windows-latest, ubuntu-20.04, ubuntu-22.04] steps: - name: 🐙 Checkout GitHub repo (+ download lfs dependencies) diff --git a/.github/workflows/license_header.yml b/.github/workflows/license_header.yml index 70176d69a5..cf577e51c9 100644 --- a/.github/workflows/license_header.yml +++ b/.github/workflows/license_header.yml @@ -2,7 +2,7 @@ name: check license headers on: push: branches: - - "ohohohoh" + - "**" jobs: check-license-headers: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 068b4dfa8c..0e41bf08b1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: main on: push: branches: - - "ohohoh" + - "**" jobs: python-lint: diff --git a/.github/workflows/worker.yml b/.github/workflows/worker.yml index 3bd0d1e9c0..bbaa285c78 100644 --- a/.github/workflows/worker.yml +++ b/.github/workflows/worker.yml @@ -2,7 +2,8 @@ name: worker on: push: branches: - - "ohohoh" + - "master" + - "worker/**" jobs: binary: From 1bb22f4d5bcfaffe1dca64f2411d44b58132c9e8 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 15 Oct 2024 16:39:32 +0200 Subject: [PATCH 28/56] revert changes on .spec file --- AntaresWebWin.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AntaresWebWin.spec b/AntaresWebWin.spec index 9c24677755..8afcb62dae 100644 --- a/AntaresWebWin.spec +++ b/AntaresWebWin.spec @@ -43,7 +43,7 @@ antares_web_server_exe = EXE(antares_web_server_pyz, [], exclude_binaries=True, name='AntaresWebServer', - debug=True, + debug=False, bootloader_ignore_signals=False, strip=False, upx=True, @@ -74,7 +74,7 @@ antares_tool_exe = EXE(antares_tool_pyz, [], exclude_binaries=True, name='AntaresTool', - debug=True, + debug=False, bootloader_ignore_signals=False, strip=False, upx=True, From b6bb16bef60a2f76fe4bd7026bb10766ab7dfb68 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 10:17:46 +0200 Subject: [PATCH 29/56] remove useless scripts --- scripts/install-debug.sh | 8 -------- scripts/stacktrace.sh | 6 ------ 2 files changed, 14 deletions(-) delete mode 100755 scripts/install-debug.sh delete mode 100755 scripts/stacktrace.sh diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh deleted file mode 100755 index 2ada4a30c4..0000000000 --- a/scripts/install-debug.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -e - -python3 -m venv /debug_env -source /debug_env/bin/activate -pip3 install pystack-debugger -deactivate \ No newline at end of file diff --git a/scripts/stacktrace.sh b/scripts/stacktrace.sh deleted file mode 100755 index 4ce721ad78..0000000000 --- a/scripts/stacktrace.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -source /debug_env/bin/activate -echo "Printing stacktraces" -ps aux | grep python | awk '{print $2}' | xargs -I{} bash -c "echo {}; pystack --include-greenlet {}" -echo "Done" \ No newline at end of file From 63e5160ef4288deff72c41a3df1072587d0376d4 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:23:07 +0200 Subject: [PATCH 30/56] update Dockerfile --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3c1ec7a8ff..fabe4026ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,6 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini -RUN ./scripts/install-debug.sh - RUN pip3 install --upgrade pip \ && pip3 install -r /conf/requirements.txt From 5940e4cb9148b383a368399738cc990e72ca72ba Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:27:42 +0200 Subject: [PATCH 31/56] use pip instead of pip3 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index fabe4026ee..c93fb2a025 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,8 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini -RUN pip3 install --upgrade pip \ - && pip3 install -r /conf/requirements.txt +RUN pip install --upgrade pip \ + && pip install -r /conf/requirements.txt ENTRYPOINT ["./scripts/start.sh"] From 3633afcc77075a080990d3d35eafe24bce5e4003 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:32:08 +0200 Subject: [PATCH 32/56] try to fix error with pip --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c93fb2a025..9fb7ebb4a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,6 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini -RUN pip install --upgrade pip \ - && pip install -r /conf/requirements.txt - +RUN python3 -m pip install --upgrade pip && python3 -m pip install -r /conf/requirements.txt ENTRYPOINT ["./scripts/start.sh"] From 00ccf7422d0216a030d554a264f2fbf43bee3925 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:39:49 +0200 Subject: [PATCH 33/56] try to install pip --- Dockerfile | 2 +- scripts/install_pip.sh | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 scripts/install_pip.sh diff --git a/Dockerfile b/Dockerfile index 9fb7ebb4a2..3a6896aa3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,6 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini -RUN python3 -m pip install --upgrade pip && python3 -m pip install -r /conf/requirements.txt +RUN ./scripts/install_pip.sh ENTRYPOINT ["./scripts/start.sh"] diff --git a/scripts/install_pip.sh b/scripts/install_pip.sh new file mode 100644 index 0000000000..c5e2b953f0 --- /dev/null +++ b/scripts/install_pip.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +python3 -m venv /venv +source /venv/bin/activate +pip install --upgrade pip && pip install -r /conf/requirements.txt \ No newline at end of file From 6214bd835ceaf64aaeb6eb6d3ed31a847940d78d Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:45:12 +0200 Subject: [PATCH 34/56] try to understand permission error --- Dockerfile | 2 ++ scripts/install_pip.sh | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3a6896aa3f..40f0dac3e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,6 @@ COPY ./alembic.ini /alembic.ini RUN ./scripts/install_pip.sh +RUN pip install --upgrade pip && pip install -r /conf/requirements.txt + ENTRYPOINT ["./scripts/start.sh"] diff --git a/scripts/install_pip.sh b/scripts/install_pip.sh index c5e2b953f0..1f5824fa7c 100644 --- a/scripts/install_pip.sh +++ b/scripts/install_pip.sh @@ -4,4 +4,3 @@ set -e python3 -m venv /venv source /venv/bin/activate -pip install --upgrade pip && pip install -r /conf/requirements.txt \ No newline at end of file From ef73be01f84a07f64abb9e0182c56f26d1fe9707 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:47:42 +0200 Subject: [PATCH 35/56] use debug venv --- scripts/install_pip.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_pip.sh b/scripts/install_pip.sh index 1f5824fa7c..d74a99b65c 100644 --- a/scripts/install_pip.sh +++ b/scripts/install_pip.sh @@ -2,5 +2,5 @@ set -e -python3 -m venv /venv -source /venv/bin/activate +python3 -m venv /debug_env +source /debug_env/bin/activate From 058359564cb7fd4b413065d85c425e17a50ac58f Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:49:37 +0200 Subject: [PATCH 36/56] use venv not at the root --- scripts/install_pip.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_pip.sh b/scripts/install_pip.sh index d74a99b65c..e9aca1ed14 100644 --- a/scripts/install_pip.sh +++ b/scripts/install_pip.sh @@ -2,5 +2,5 @@ set -e -python3 -m venv /debug_env -source /debug_env/bin/activate +python3 -m venv venv_test +source venv_test/bin/activate From e32e40abd68721599fd0c3d55d6e1b03d051ee13 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:53:16 +0200 Subject: [PATCH 37/56] try to undrestand --- Dockerfile | 2 +- scripts/install-debug.sh | 6 ++++++ scripts/install_pip.sh | 6 ------ 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 scripts/install-debug.sh delete mode 100644 scripts/install_pip.sh diff --git a/Dockerfile b/Dockerfile index 40f0dac3e8..b62fc91ec3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini -RUN ./scripts/install_pip.sh +RUN ./scripts/install-debug.sh RUN pip install --upgrade pip && pip install -r /conf/requirements.txt diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh new file mode 100644 index 0000000000..852a6ee903 --- /dev/null +++ b/scripts/install-debug.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e + +python3 -m venv /debug_env +source /debug_env/bin/activate \ No newline at end of file diff --git a/scripts/install_pip.sh b/scripts/install_pip.sh deleted file mode 100644 index e9aca1ed14..0000000000 --- a/scripts/install_pip.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -set -e - -python3 -m venv venv_test -source venv_test/bin/activate From c13cfd214fc2891d8dec713b1d30396f2819cfda Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:55:16 +0200 Subject: [PATCH 38/56] im lost --- scripts/install-debug.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index 852a6ee903..1160eeb2ab 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -3,4 +3,5 @@ set -e python3 -m venv /debug_env -source /debug_env/bin/activate \ No newline at end of file +source /debug_env/bin/activate +deactivate \ No newline at end of file From b9f9b6a37f362b527baeca5475911d07f0b3ce22 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 13:59:06 +0200 Subject: [PATCH 39/56] im lost --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index b62fc91ec3..e67f83d59b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini +RUN chmod 777 /scripts/install-debug.sh RUN ./scripts/install-debug.sh RUN pip install --upgrade pip && pip install -r /conf/requirements.txt From 3b4f235205a387bdfd87077a60291c210493cdce Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 14:04:15 +0200 Subject: [PATCH 40/56] put pip inside .sh --- Dockerfile | 5 +---- scripts/install-debug.sh | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index e67f83d59b..32d6ec4e7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,9 +16,6 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini -RUN chmod 777 /scripts/install-debug.sh -RUN ./scripts/install-debug.sh - -RUN pip install --upgrade pip && pip install -r /conf/requirements.txt +RUN chmod 777 /scripts/install-debug.sh && ./scripts/install-debug.sh ENTRYPOINT ["./scripts/start.sh"] diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index 1160eeb2ab..40308f08ee 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -4,4 +4,5 @@ set -e python3 -m venv /debug_env source /debug_env/bin/activate +pip install --upgrade pip && pip install -r /conf/requirements.txt deactivate \ No newline at end of file From 47d50dc549235494fcf02ab1e24c9dcba8b93cac Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 14:10:36 +0200 Subject: [PATCH 41/56] use pip3 instead of pip --- scripts/install-debug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index 40308f08ee..eadd67ffda 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -4,5 +4,5 @@ set -e python3 -m venv /debug_env source /debug_env/bin/activate -pip install --upgrade pip && pip install -r /conf/requirements.txt +pip3 install --upgrade pip && pip3 install -r /conf/requirements.txt deactivate \ No newline at end of file From 40ad8746bb2ac137a6299e185758d1d158898ab8 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 14:19:03 +0200 Subject: [PATCH 42/56] try to put pip inside docker file instead of .sh --- Dockerfile | 2 ++ scripts/install-debug.sh | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 32d6ec4e7f..2f155f505d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,6 @@ COPY ./alembic.ini /alembic.ini RUN chmod 777 /scripts/install-debug.sh && ./scripts/install-debug.sh +RUN pip3 install --upgrade pip && pip3 install -r /conf/requirements.txt + ENTRYPOINT ["./scripts/start.sh"] diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index eadd67ffda..852a6ee903 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -3,6 +3,4 @@ set -e python3 -m venv /debug_env -source /debug_env/bin/activate -pip3 install --upgrade pip && pip3 install -r /conf/requirements.txt -deactivate \ No newline at end of file +source /debug_env/bin/activate \ No newline at end of file From 37511c99b1bf39b4c2e2e6d848c958fe7fd5971b Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 14:26:12 +0200 Subject: [PATCH 43/56] use python3.11 instead of python3 --- Dockerfile | 2 -- scripts/install-debug.sh | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2f155f505d..32d6ec4e7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,4 @@ COPY ./alembic.ini /alembic.ini RUN chmod 777 /scripts/install-debug.sh && ./scripts/install-debug.sh -RUN pip3 install --upgrade pip && pip3 install -r /conf/requirements.txt - ENTRYPOINT ["./scripts/start.sh"] diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index 852a6ee903..93d19dfea9 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -2,5 +2,7 @@ set -e -python3 -m venv /debug_env -source /debug_env/bin/activate \ No newline at end of file +python3.11 -m venv /debug_env +source /debug_env/bin/activate +pip3 install --upgrade pip && pip3 install -r /conf/requirements.txt +deactivate \ No newline at end of file From 8ff02d664f39410b8dac420f67320e3115929c71 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 15:05:53 +0200 Subject: [PATCH 44/56] force pip reinstall --- scripts/install-debug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index 93d19dfea9..1d51da4d50 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -4,5 +4,5 @@ set -e python3.11 -m venv /debug_env source /debug_env/bin/activate -pip3 install --upgrade pip && pip3 install -r /conf/requirements.txt +pip3 install --upgrade --force-reinstall pip && pip3 install -r /conf/requirements.txt deactivate \ No newline at end of file From 930c6ee968eb8d6f695b6da88bc2137547a41514 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 15:29:08 +0200 Subject: [PATCH 45/56] try to use pip outside ouf venv --- Dockerfile | 2 ++ scripts/install-debug.sh | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 32d6ec4e7f..66faeda39a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,6 @@ COPY ./alembic.ini /alembic.ini RUN chmod 777 /scripts/install-debug.sh && ./scripts/install-debug.sh +RUN pip3 install --upgrade --force-reinstall pip && pip3 install -r /conf/requirements.txt + ENTRYPOINT ["./scripts/start.sh"] diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index 1d51da4d50..172a1e13ba 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -4,5 +4,4 @@ set -e python3.11 -m venv /debug_env source /debug_env/bin/activate -pip3 install --upgrade --force-reinstall pip && pip3 install -r /conf/requirements.txt deactivate \ No newline at end of file From a110c0369bedd4ae9a3dffc24bfcf7c7be99c62f Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 16:20:47 +0200 Subject: [PATCH 46/56] use pip instead of pip3 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 66faeda39a..aef23e4c9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,6 @@ COPY ./alembic.ini /alembic.ini RUN chmod 777 /scripts/install-debug.sh && ./scripts/install-debug.sh -RUN pip3 install --upgrade --force-reinstall pip && pip3 install -r /conf/requirements.txt +RUN pip install --upgrade --force-reinstall pip && pip install -r /conf/requirements.txt ENTRYPOINT ["./scripts/start.sh"] From 9f6185e7dd0ded25580f47c48246e3bf68c6bbe0 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 16:21:07 +0200 Subject: [PATCH 47/56] use +x instead of 777 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index aef23e4c9a..201b7fdbe7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini -RUN chmod 777 /scripts/install-debug.sh && ./scripts/install-debug.sh +RUN chmod +x /scripts/install-debug.sh && ./scripts/install-debug.sh RUN pip install --upgrade --force-reinstall pip && pip install -r /conf/requirements.txt From d86c2da2f7fc847dbb5fb8434c8b7d1edbe55b63 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 16:26:27 +0200 Subject: [PATCH 48/56] try to use pip outside of venv --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 201b7fdbe7..8eac0bbed1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,8 @@ COPY ./alembic.ini /alembic.ini RUN chmod +x /scripts/install-debug.sh && ./scripts/install-debug.sh -RUN pip install --upgrade --force-reinstall pip && pip install -r /conf/requirements.txt +RUN python3.11 -m pip install --upgrade --force-reinstall pip + +RUN python3.11 -m pip install -r /conf/requirements.txt ENTRYPOINT ["./scripts/start.sh"] From 9eab19744cf82fe16d23bd0f1723c04a9648b83c Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 16:29:43 +0200 Subject: [PATCH 49/56] last chance --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8eac0bbed1..f55bba54db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,8 +18,8 @@ COPY ./alembic.ini /alembic.ini RUN chmod +x /scripts/install-debug.sh && ./scripts/install-debug.sh -RUN python3.11 -m pip install --upgrade --force-reinstall pip +RUN python3.11 -m pip3 install --upgrade --force-reinstall pip -RUN python3.11 -m pip install -r /conf/requirements.txt +RUN python3.11 -m pip3 install -r /conf/requirements.txt ENTRYPOINT ["./scripts/start.sh"] From 3ce1b702ee91ab422078d7ad0ec8a89e2fcb18b3 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 16:32:29 +0200 Subject: [PATCH 50/56] never deactivate the venv --- Dockerfile | 4 ---- scripts/install-debug.sh | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index f55bba54db..d42174b1d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,8 +18,4 @@ COPY ./alembic.ini /alembic.ini RUN chmod +x /scripts/install-debug.sh && ./scripts/install-debug.sh -RUN python3.11 -m pip3 install --upgrade --force-reinstall pip - -RUN python3.11 -m pip3 install -r /conf/requirements.txt - ENTRYPOINT ["./scripts/start.sh"] diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index 172a1e13ba..b2d5310589 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -4,4 +4,4 @@ set -e python3.11 -m venv /debug_env source /debug_env/bin/activate -deactivate \ No newline at end of file +pip3 install --upgrade --force-reinstall pip && pip3 install -r /conf/requirements.txt \ No newline at end of file From 8efb04238ee0d8362fc9e3b567cff3b25763ee1f Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 16:37:56 +0200 Subject: [PATCH 51/56] .... --- scripts/install-debug.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index b2d5310589..1d51da4d50 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -4,4 +4,5 @@ set -e python3.11 -m venv /debug_env source /debug_env/bin/activate -pip3 install --upgrade --force-reinstall pip && pip3 install -r /conf/requirements.txt \ No newline at end of file +pip3 install --upgrade --force-reinstall pip && pip3 install -r /conf/requirements.txt +deactivate \ No newline at end of file From 5982b0de64f507ddd34536447e9047b2dc2ac047 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 16:43:03 +0200 Subject: [PATCH 52/56] remove deactivate keyword --- scripts/install-debug.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh index 1d51da4d50..5f80b5873b 100644 --- a/scripts/install-debug.sh +++ b/scripts/install-debug.sh @@ -5,4 +5,3 @@ set -e python3.11 -m venv /debug_env source /debug_env/bin/activate pip3 install --upgrade --force-reinstall pip && pip3 install -r /conf/requirements.txt -deactivate \ No newline at end of file From b18856b418896c166ecf3191217389e0f42f8f9d Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 16 Oct 2024 18:26:49 +0200 Subject: [PATCH 53/56] It should work once antares-ci is good --- Dockerfile | 2 +- scripts/install-debug.sh | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 scripts/install-debug.sh diff --git a/Dockerfile b/Dockerfile index d42174b1d2..027847bff8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,6 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini -RUN chmod +x /scripts/install-debug.sh && ./scripts/install-debug.sh +RUN pip3 install --upgrade pip && pip3 install -r /conf/requirements.txt ENTRYPOINT ["./scripts/start.sh"] diff --git a/scripts/install-debug.sh b/scripts/install-debug.sh deleted file mode 100644 index 5f80b5873b..0000000000 --- a/scripts/install-debug.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -e - -python3.11 -m venv /debug_env -source /debug_env/bin/activate -pip3 install --upgrade --force-reinstall pip && pip3 install -r /conf/requirements.txt From cf44d5858a980fabac8f91d63d4a6cc547d903b3 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Thu, 17 Oct 2024 09:50:27 +0200 Subject: [PATCH 54/56] use no cache for pip --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 027847bff8..a0ab4f4061 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,6 @@ COPY ./scripts /scripts COPY ./alembic /alembic COPY ./alembic.ini /alembic.ini -RUN pip3 install --upgrade pip && pip3 install -r /conf/requirements.txt +RUN pip3 install --upgrade pip && pip3 install -r /conf/requirements.txt --no-cache-dir ENTRYPOINT ["./scripts/start.sh"] From 9b8584cc0e052fe55257d2c480e88a6bdf07b742 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Thu, 24 Oct 2024 14:29:34 +0200 Subject: [PATCH 55/56] add doc inside gui.py --- antarest/gui.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/antarest/gui.py b/antarest/gui.py index 888ae6d979..86ddd5efd1 100644 --- a/antarest/gui.py +++ b/antarest/gui.py @@ -13,6 +13,9 @@ import os import sys +# The Pyinstaller version we use has a known issue on windows and to fix it we need to implement this workaround. +# See issue description and workaround on pyinstaller website: +# https://pyinstaller.org/en/stable/common-issues-and-pitfalls.html#sys-stdin-sys-stdout-and-sys-stderr-in-noconsole-windowed-applications-windows-only if sys.stdout is None: sys.stdout = open(os.devnull, "w") if sys.stderr is None: From 87f7c815ffd9bf72dabe7d690ff7c31be900ce35 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Fri, 25 Oct 2024 11:04:56 +0200 Subject: [PATCH 56/56] use strEnum instead of str, Enum --- antarest/core/utils/archives.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/antarest/core/utils/archives.py b/antarest/core/utils/archives.py index a128cd4438..2356653b78 100644 --- a/antarest/core/utils/archives.py +++ b/antarest/core/utils/archives.py @@ -15,7 +15,7 @@ import tempfile import typing as t import zipfile -from enum import Enum +from enum import StrEnum from pathlib import Path import py7zr @@ -25,7 +25,7 @@ logger = logging.getLogger(__name__) -class ArchiveFormat(str, Enum): +class ArchiveFormat(StrEnum): ZIP = ".zip" SEVEN_ZIP = ".7z"