diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ed1f96e8..65f4f748a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,12 +16,6 @@ repos: - id: trailing-whitespace - id: check-symlinks exclude: ^charts/ -- repo: https://github.com/sondrelg/pep585-upgrade - rev: v1.0 - hooks: - - id: upgrade-type-hints - args: - - --futures=true - repo: https://github.com/Zac-HD/shed rev: 2024.10.1 hooks: @@ -34,7 +28,7 @@ repos: - markdown - rst - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.11.2 hooks: - id: ruff-format - id: ruff @@ -47,7 +41,7 @@ repos: docs/spelling_wordlist.txt| .gitignore - repo: https://github.com/sirosen/check-jsonschema - rev: 0.30.0 + rev: 0.32.1 hooks: - id: check-github-actions - id: check-github-workflows diff --git a/platform_api/handlers/jobs_handler.py b/platform_api/handlers/jobs_handler.py index f13194ced..a46a617b9 100644 --- a/platform_api/handlers/jobs_handler.py +++ b/platform_api/handlers/jobs_handler.py @@ -462,9 +462,7 @@ def convert_disk_volume_to_json(volume: DiskContainerVolume) -> dict[str, Any]: def convert_job_to_job_response(job: Job) -> dict[str, Any]: - assert ( - job.cluster_name - ), "empty cluster name must be already replaced with `default`" + assert job.cluster_name history = job.status_history current_status = history.current response_payload: dict[str, Any] = { diff --git a/platform_api/orchestrator/jobs_service.py b/platform_api/orchestrator/jobs_service.py index 60f2155d1..0389966c2 100644 --- a/platform_api/orchestrator/jobs_service.py +++ b/platform_api/orchestrator/jobs_service.py @@ -191,7 +191,7 @@ async def _setup_pass_config( ) -> JobRequest: if NEURO_PASSED_CONFIG in job_request.container.env: raise JobsServiceException( - f"Cannot pass config: ENV '{NEURO_PASSED_CONFIG}' " "already specified" + f"Cannot pass config: ENV '{NEURO_PASSED_CONFIG}' already specified" ) token = await self._make_pass_config_token( user.name, cluster_name, job_request.job_id diff --git a/platform_api/orchestrator/kube_client.py b/platform_api/orchestrator/kube_client.py index b31db8b08..affa5ad23 100644 --- a/platform_api/orchestrator/kube_client.py +++ b/platform_api/orchestrator/kube_client.py @@ -1975,8 +1975,7 @@ def _networking_v1beta1_namespace_url(self) -> str: @property def _networking_v1_namespace_url(self) -> str: return ( - f"{self._base_url}/apis/networking.k8s.io/v1" - f"/namespaces/{self._namespace}" + f"{self._base_url}/apis/networking.k8s.io/v1/namespaces/{self._namespace}" ) @property diff --git a/tests/integration/api.py b/tests/integration/api.py index d12b5a8b0..1b4dbae7f 100644 --- a/tests/integration/api.py +++ b/tests/integration/api.py @@ -304,13 +304,9 @@ async def delete_job( headers: dict[str, str] | None = None, ) -> None: url = self._api_config.generate_job_url(job_id) - async with self._client.delete( - url, headers=headers or self._headers - ) as response: + async with self._client.delete(url, headers=headers or self._headers) as resp: if assert_success: - assert ( - response.status == HTTPNoContent.status_code - ), await response.text() + assert resp.status == HTTPNoContent.status_code, await resp.text() async def drop_job( self, @@ -319,11 +315,9 @@ async def drop_job( headers: dict[str, str] | None = None, ) -> None: url = self._api_config.generate_job_url(job_id) + "/drop" - async with self._client.post(url, headers=headers or self._headers) as response: + async with self._client.post(url, headers=headers or self._headers) as resp: if assert_success: - assert ( - response.status == HTTPNoContent.status_code - ), await response.text() + assert resp.status == HTTPNoContent.status_code, await resp.text() async def drop_progress( self, @@ -338,11 +332,9 @@ async def drop_progress( payload["logs_removed"] = logs_removed async with self._client.post( url, json=payload, headers=headers or self._headers - ) as response: + ) as resp: if assert_success: - assert ( - response.status == HTTPNoContent.status_code - ), await response.text() + assert resp.status == HTTPNoContent.status_code, await resp.text() @pytest.fixture diff --git a/tests/integration/test_api.py b/tests/integration/test_api.py index 908137cb9..47d8b85f0 100644 --- a/tests/integration/test_api.py +++ b/tests/integration/test_api.py @@ -4634,11 +4634,9 @@ async def test_get_jobs_return_corrects_id( url = api.jobs_base_url async with client.post( url, headers=regular_user.headers, json=job_submit - ) as response: - assert ( - response.status == HTTPAccepted.status_code - ), await response.text() - result = await response.json() + ) as resp: + assert resp.status == HTTPAccepted.status_code, await resp.text() + result = await resp.json() assert result["status"] in ["pending"] job_id = result["id"] await jobs_client.long_polling_by_job_id( @@ -4952,15 +4950,13 @@ async def test_set_job_status_no_reason( url = api.generate_job_url(job_id) + "/status" headers = compute_user.headers payload = {"status": "failed"} - async with client.put(url, headers=headers, json=payload) as response: - if response.status == HTTPConflict.status_code: - result = await response.json() + async with client.put(url, headers=headers, json=payload) as resp: + if resp.status == HTTPConflict.status_code: + result = await resp.json() assert result["error"] == f"Job {{id={job_id}}} has changed" ok = False else: - assert ( - response.status == HTTPNoContent.status_code - ), await response.text() + assert resp.status == HTTPNoContent.status_code, await resp.text() ok = True if ok: @@ -4991,15 +4987,13 @@ async def test_set_job_status_with_details( "description": "test_set_job_status", "exit_code": 42, } - async with client.put(url, headers=headers, json=payload) as response: - if response.status == HTTPConflict.status_code: - result = await response.json() + async with client.put(url, headers=headers, json=payload) as resp: + if resp.status == HTTPConflict.status_code: + result = await resp.json() assert result["error"] == f"Job {{id={job_id}}} has changed" ok = False else: - assert ( - response.status == HTTPNoContent.status_code - ), await response.text() + assert resp.status == HTTPNoContent.status_code, await resp.text() ok = True if ok: diff --git a/tests/unit/test_job_service.py b/tests/unit/test_job_service.py index 6c518a054..90fadcdd3 100644 --- a/tests/unit/test_job_service.py +++ b/tests/unit/test_job_service.py @@ -509,8 +509,7 @@ async def test_create_job_pass_config_env_present( mock_job_request.container.env[NEURO_PASSED_CONFIG] = "anything" with pytest.raises( JobsServiceException, - match=f"Cannot pass config: ENV '{NEURO_PASSED_CONFIG}' " - "already specified", + match=f"Cannot pass config: ENV '{NEURO_PASSED_CONFIG}' already specified", ): await jobs_service.create_job( job_request=mock_job_request, diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index 09de2b8ff..6687d866d 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -2057,7 +2057,7 @@ async def test_job_to_job_response_assert_non_empty_cluster_name( cluster_name="", ), ) - with pytest.raises(AssertionError, match="must be already replaced"): + with pytest.raises(AssertionError): convert_job_to_job_response(job)