From d05956a7f9dc391bcf35f2303e4d469c56ef8d3b Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Thu, 6 Feb 2025 09:44:39 +0100 Subject: [PATCH 1/4] feat(all): upgrade pydantic, black, mypy and isort --- antarest/core/filetransfer/service.py | 32 ++++++++++++------- antarest/service_creator.py | 12 +++++-- antarest/study/business/general_management.py | 8 +++-- requirements-dev.txt | 6 ++-- requirements.txt | 2 +- .../studies_blueprint/test_get_studies.py | 8 +++-- .../model/command/test_remove_st_storage.py | 7 ++-- 7 files changed, 48 insertions(+), 27 deletions(-) diff --git a/antarest/core/filetransfer/service.py b/antarest/core/filetransfer/service.py index a82f7af814..92b43e16d9 100644 --- a/antarest/core/filetransfer/service.py +++ b/antarest/core/filetransfer/service.py @@ -79,9 +79,11 @@ def request_download( Event( type=EventType.DOWNLOAD_CREATED, payload=download.to_dto(), - permissions=PermissionInfo(owner=owner.impersonator) - if owner - else PermissionInfo(public_mode=PublicMode.READ), + permissions=( + PermissionInfo(owner=owner.impersonator) + if owner + else PermissionInfo(public_mode=PublicMode.READ) + ), ) ) return download @@ -98,9 +100,11 @@ def set_ready(self, download_id: str, use_notification: bool = True) -> None: Event( type=EventType.DOWNLOAD_READY, payload=download.to_dto(), - permissions=PermissionInfo(owner=download.owner) - if download.owner - else PermissionInfo(public_mode=PublicMode.READ), + permissions=( + PermissionInfo(owner=download.owner) + if download.owner + else PermissionInfo(public_mode=PublicMode.READ) + ), ) ) @@ -116,9 +120,11 @@ def fail(self, download_id: str, reason: str = "") -> None: Event( type=EventType.DOWNLOAD_FAILED, payload=download.to_dto(), - permissions=PermissionInfo(owner=download.owner) - if download.owner - else PermissionInfo(public_mode=PublicMode.READ), + permissions=( + PermissionInfo(owner=download.owner) + if download.owner + else PermissionInfo(public_mode=PublicMode.READ) + ), ) ) @@ -185,9 +191,11 @@ def _clean_up_expired_downloads(self, file_downloads: List[FileDownload]) -> Non Event( type=EventType.DOWNLOAD_EXPIRED, payload=download_id, - permissions=PermissionInfo(owner=download_owner) - if download_owner - else PermissionInfo(public_mode=PublicMode.READ), + permissions=( + PermissionInfo(owner=download_owner) + if download_owner + else PermissionInfo(public_mode=PublicMode.READ) + ), ) ) diff --git a/antarest/service_creator.py b/antarest/service_creator.py index a9b0351671..5a538beb69 100644 --- a/antarest/service_creator.py +++ b/antarest/service_creator.py @@ -127,9 +127,15 @@ def create_event_bus(app_ctxt: t.Optional[AppBuildContext], config: Config) -> t ) -def create_core_services( - app_ctxt: t.Optional[AppBuildContext], config: Config -) -> t.Tuple[ICache, IEventBus, ITaskService, FileTransferManager, LoginService, MatrixService, StudyService,]: +def create_core_services(app_ctxt: t.Optional[AppBuildContext], config: Config) -> t.Tuple[ + ICache, + IEventBus, + ITaskService, + FileTransferManager, + LoginService, + MatrixService, + StudyService, +]: event_bus, redis_client = create_event_bus(app_ctxt, config) cache = build_cache(config=config, redis_client=redis_client) filetransfer_service = build_filetransfer_service(app_ctxt, event_bus, config) diff --git a/antarest/study/business/general_management.py b/antarest/study/business/general_management.py index 7270c63dc2..e8e74822c1 100644 --- a/antarest/study/business/general_management.py +++ b/antarest/study/business/general_management.py @@ -307,9 +307,11 @@ def __get_building_mode_update_cmds( return [ UpdateConfig( - target=f"{GENERAL_PATH}/custom-scenario" - if study_version >= STUDY_VERSION_8 - else f"{GENERAL_PATH}/custom-ts-numbers", + target=( + f"{GENERAL_PATH}/custom-scenario" + if study_version >= STUDY_VERSION_8 + else f"{GENERAL_PATH}/custom-ts-numbers" + ), data=new_value == BuildingMode.CUSTOM, command_context=cmd_context, study_version=study_version, diff --git a/requirements-dev.txt b/requirements-dev.txt index 14c06c1ed6..f3ec4b5a88 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,9 +1,9 @@ -r requirements-test.txt -r requirements-desktop.txt # Version of Black should match the versions set in `.github/workflows/main.yml` -black~=23.7.0 -isort~=5.12.0 -mypy~=1.11.1 +black~=25.1.0 +isort~=6.0.0 +mypy~=1.15.0 pyinstaller==6.10.0 pyinstaller-hooks-contrib==2024.8 diff --git a/requirements.txt b/requirements.txt index 60c782d945..01abfca3a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,7 @@ antares-timeseries-generation==0.1.7 # and **manage their versions** for better control and to avoid unnecessary dependencies. fastapi~=0.110.3 uvicorn[standard]~=0.30.6 -pydantic~=2.8.2 +pydantic~=2.10.0 httpx~=0.27.0 python-multipart~=0.0.9 diff --git a/tests/integration/studies_blueprint/test_get_studies.py b/tests/integration/studies_blueprint/test_get_studies.py index 7049f82369..e2432464d0 100644 --- a/tests/integration/studies_blueprint/test_get_studies.py +++ b/tests/integration/studies_blueprint/test_get_studies.py @@ -1404,9 +1404,11 @@ def test_get_studies__access_permissions(self, client: TestClient, admin_access_ res = client.get( STUDIES_URL, headers={"Authorization": f"Bearer {users_tokens['user_1']}"}, - params={"groups": ",".join(request_groups_ids), "pageNb": 1, "pageSize": 2} - if request_groups_ids - else {"pageNb": 1, "pageSize": 2}, + params=( + {"groups": ",".join(request_groups_ids), "pageNb": 1, "pageSize": 2} + if request_groups_ids + else {"pageNb": 1, "pageSize": 2} + ), ) assert res.status_code == LIST_STATUS_CODE, res.json() assert len(res.json()) == max(0, min(2, len(expected_studies) - 2)) diff --git a/tests/variantstudy/model/command/test_remove_st_storage.py b/tests/variantstudy/model/command/test_remove_st_storage.py index d416391464..d1b4b79f7d 100644 --- a/tests/variantstudy/model/command/test_remove_st_storage.py +++ b/tests/variantstudy/model/command/test_remove_st_storage.py @@ -81,16 +81,19 @@ def test_init__invalid_storage_id(self, recent_study: FileStudy, command_context storage_id="?%$$", # bad name study_version=STUDY_VERSION_8_8, ) - assert ctx.value.errors() == [ + expected_error = [ { "ctx": {"pattern": "[a-z0-9_(),& -]+"}, "input": "?%$$", "loc": ("storage_id",), "msg": "String should match pattern '[a-z0-9_(),& -]+'", "type": "string_pattern_mismatch", - "url": "https://errors.pydantic.dev/2.8/v/string_pattern_mismatch", } ] + actual_errors = ctx.value.errors() + for error in actual_errors: + error.pop("url") + assert actual_errors == expected_error def test_apply_config__invalid_version(self, empty_study: FileStudy, command_context: CommandContext): # Given an old study in version 720 From 696af4bd9d19f3b4d98f4a0f7e372990e3b214a6 Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Thu, 6 Feb 2025 09:50:20 +0100 Subject: [PATCH 2/4] feat(all): upgrade pydantic, black, mypy and isort --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 01abfca3a5..cf483d9d7e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,8 +28,7 @@ click~=8.0.3 contextvars~=2.4 filelock~=3.4.2 gunicorn~=20.1.0 -humanize~=4.10.0; python_version <= '3.8' -humanize~=4.11.0; python_version > '3.8' +humanize~=4.11.0 jsonref~=0.2 PyJWT~=2.9.0 MarkupSafe~=2.0.1 From 5664bba41735be37b40ad6a556edb4541769383d Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Thu, 6 Feb 2025 09:52:40 +0100 Subject: [PATCH 3/4] feat(all): upgrade pydantic, black, mypy and isort --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a5207a3d20..30db6c0d4f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,7 +26,7 @@ jobs: uses: psf/black@stable with: # Version of Black should match the versions set in `requirements-dev.txt` - version: "~=23.7.0" + version: "~=25.1.0" options: --check --diff - name: Check Typing (mypy) #continue-on-error: true From a2b24c01df06b81e0daac47455c1464ba1eb442a Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Thu, 6 Feb 2025 10:10:16 +0100 Subject: [PATCH 4/4] build(all): bump pydantic and linting packages --- tests/variantstudy/model/command/test_remove_st_storage.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/variantstudy/model/command/test_remove_st_storage.py b/tests/variantstudy/model/command/test_remove_st_storage.py index d1b4b79f7d..62d911f2bb 100644 --- a/tests/variantstudy/model/command/test_remove_st_storage.py +++ b/tests/variantstudy/model/command/test_remove_st_storage.py @@ -81,19 +81,16 @@ def test_init__invalid_storage_id(self, recent_study: FileStudy, command_context storage_id="?%$$", # bad name study_version=STUDY_VERSION_8_8, ) - expected_error = [ + assert ctx.value.errors() == [ { "ctx": {"pattern": "[a-z0-9_(),& -]+"}, "input": "?%$$", "loc": ("storage_id",), "msg": "String should match pattern '[a-z0-9_(),& -]+'", "type": "string_pattern_mismatch", + "url": "https://errors.pydantic.dev/2.10/v/string_pattern_mismatch", } ] - actual_errors = ctx.value.errors() - for error in actual_errors: - error.pop("url") - assert actual_errors == expected_error def test_apply_config__invalid_version(self, empty_study: FileStudy, command_context: CommandContext): # Given an old study in version 720