From 7d53ea31e80e0e31a441899ef5cec94ed6fa07de Mon Sep 17 00:00:00 2001 From: Isabella Basso Date: Tue, 20 Aug 2024 05:55:55 -0300 Subject: [PATCH] Bump ruff to 0.6.1 (#285) * build(deps-dev): bump ruff from 0.5.7 to 0.6.1 in /clients/python Bumps [ruff](https://github.com/astral-sh/ruff) from 0.5.7 to 0.6.1. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ruff/compare/0.5.7...0.6.1) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Fix linter warnings Signed-off-by: Isabella do Amaral --------- Signed-off-by: dependabot[bot] Signed-off-by: Isabella do Amaral Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- clients/python/poetry.lock | 40 +++++++++---------- clients/python/pyproject.toml | 2 +- clients/python/src/model_registry/core.py | 3 +- .../src/model_registry/types/artifacts.py | 3 +- .../python/src/model_registry/types/base.py | 3 +- .../src/model_registry/types/contexts.py | 3 +- clients/python/src/mr_openapi/api_client.py | 25 ++++++------ .../python/src/mr_openapi/configuration.py | 3 +- .../python/src/mr_openapi/models/artifact.py | 18 ++++----- .../src/mr_openapi/models/metadata_value.py | 18 ++++----- clients/python/tests/basic_test.py | 9 +++-- clients/python/tests/test_client.py | 3 +- clients/python/tests/test_core.py | 9 +++-- clients/python/tests/test_utils.py | 1 + 14 files changed, 69 insertions(+), 71 deletions(-) diff --git a/clients/python/poetry.lock b/clients/python/poetry.lock index 717253211..2b5087af8 100644 --- a/clients/python/poetry.lock +++ b/clients/python/poetry.lock @@ -1502,29 +1502,29 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "ruff" -version = "0.5.7" +version = "0.6.1" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.5.7-py3-none-linux_armv6l.whl", hash = "sha256:548992d342fc404ee2e15a242cdbea4f8e39a52f2e7752d0e4cbe88d2d2f416a"}, - {file = "ruff-0.5.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:00cc8872331055ee017c4f1071a8a31ca0809ccc0657da1d154a1d2abac5c0be"}, - {file = "ruff-0.5.7-py3-none-macosx_11_0_arm64.whl", hash = "sha256:eaf3d86a1fdac1aec8a3417a63587d93f906c678bb9ed0b796da7b59c1114a1e"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a01c34400097b06cf8a6e61b35d6d456d5bd1ae6961542de18ec81eaf33b4cb8"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:fcc8054f1a717e2213500edaddcf1dbb0abad40d98e1bd9d0ad364f75c763eea"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7f70284e73f36558ef51602254451e50dd6cc479f8b6f8413a95fcb5db4a55fc"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:a78ad870ae3c460394fc95437d43deb5c04b5c29297815a2a1de028903f19692"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9ccd078c66a8e419475174bfe60a69adb36ce04f8d4e91b006f1329d5cd44bcf"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7e31c9bad4ebf8fdb77b59cae75814440731060a09a0e0077d559a556453acbb"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8d796327eed8e168164346b769dd9a27a70e0298d667b4ecee6877ce8095ec8e"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:4a09ea2c3f7778cc635e7f6edf57d566a8ee8f485f3c4454db7771efb692c499"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a36d8dcf55b3a3bc353270d544fb170d75d2dff41eba5df57b4e0b67a95bb64e"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:9369c218f789eefbd1b8d82a8cf25017b523ac47d96b2f531eba73770971c9e5"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:b88ca3db7eb377eb24fb7c82840546fb7acef75af4a74bd36e9ceb37a890257e"}, - {file = "ruff-0.5.7-py3-none-win32.whl", hash = "sha256:33d61fc0e902198a3e55719f4be6b375b28f860b09c281e4bdbf783c0566576a"}, - {file = "ruff-0.5.7-py3-none-win_amd64.whl", hash = "sha256:083bbcbe6fadb93cd86709037acc510f86eed5a314203079df174c40bbbca6b3"}, - {file = "ruff-0.5.7-py3-none-win_arm64.whl", hash = "sha256:2dca26154ff9571995107221d0aeaad0e75a77b5a682d6236cf89a58c70b76f4"}, - {file = "ruff-0.5.7.tar.gz", hash = "sha256:8dfc0a458797f5d9fb622dd0efc52d796f23f0a1493a9527f4e49a550ae9a7e5"}, + {file = "ruff-0.6.1-py3-none-linux_armv6l.whl", hash = "sha256:b4bb7de6a24169dc023f992718a9417380301b0c2da0fe85919f47264fb8add9"}, + {file = "ruff-0.6.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:45efaae53b360c81043e311cdec8a7696420b3d3e8935202c2846e7a97d4edae"}, + {file = "ruff-0.6.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:bc60c7d71b732c8fa73cf995efc0c836a2fd8b9810e115be8babb24ae87e0850"}, + {file = "ruff-0.6.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2c7477c3b9da822e2db0b4e0b59e61b8a23e87886e727b327e7dcaf06213c5cf"}, + {file = "ruff-0.6.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3a0af7ab3f86e3dc9f157a928e08e26c4b40707d0612b01cd577cc84b8905cc9"}, + {file = "ruff-0.6.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:392688dbb50fecf1bf7126731c90c11a9df1c3a4cdc3f481b53e851da5634fa5"}, + {file = "ruff-0.6.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:5278d3e095ccc8c30430bcc9bc550f778790acc211865520f3041910a28d0024"}, + {file = "ruff-0.6.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:fe6d5f65d6f276ee7a0fc50a0cecaccb362d30ef98a110f99cac1c7872df2f18"}, + {file = "ruff-0.6.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b2e0dd11e2ae553ee5c92a81731d88a9883af8db7408db47fc81887c1f8b672e"}, + {file = "ruff-0.6.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d812615525a34ecfc07fd93f906ef5b93656be01dfae9a819e31caa6cfe758a1"}, + {file = "ruff-0.6.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:faaa4060f4064c3b7aaaa27328080c932fa142786f8142aff095b42b6a2eb631"}, + {file = "ruff-0.6.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:99d7ae0df47c62729d58765c593ea54c2546d5de213f2af2a19442d50a10cec9"}, + {file = "ruff-0.6.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:9eb18dfd7b613eec000e3738b3f0e4398bf0153cb80bfa3e351b3c1c2f6d7b15"}, + {file = "ruff-0.6.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:c62bc04c6723a81e25e71715aa59489f15034d69bf641df88cb38bdc32fd1dbb"}, + {file = "ruff-0.6.1-py3-none-win32.whl", hash = "sha256:9fb4c4e8b83f19c9477a8745e56d2eeef07a7ff50b68a6998f7d9e2e3887bdc4"}, + {file = "ruff-0.6.1-py3-none-win_amd64.whl", hash = "sha256:c2ebfc8f51ef4aca05dad4552bbcf6fe8d1f75b2f6af546cc47cc1c1ca916b5b"}, + {file = "ruff-0.6.1-py3-none-win_arm64.whl", hash = "sha256:3bc81074971b0ffad1bd0c52284b22411f02a11a012082a76ac6da153536e014"}, + {file = "ruff-0.6.1.tar.gz", hash = "sha256:af3ffd8c6563acb8848d33cd19a69b9bfe943667f0419ca083f8ebe4224a3436"}, ] [[package]] @@ -2167,4 +2167,4 @@ hf = ["huggingface-hub"] [metadata] lock-version = "2.0" python-versions = ">= 3.9, < 4.0" -content-hash = "566213ea14004fd0c4a9af91b6304a68574a81fe582cd1b2847b41b720b78b7b" +content-hash = "09e750ae7033c706f00aa064dcf7c949e4bb235eaa95a666f2d5ca6e9da7bb6b" diff --git a/clients/python/pyproject.toml b/clients/python/pyproject.toml index 3e5ddaa36..a4d47df6e 100644 --- a/clients/python/pyproject.toml +++ b/clients/python/pyproject.toml @@ -44,7 +44,7 @@ sphinx-autobuild = ">=2021.3.14,<2025.0.0" pytest = ">=7.4.2,<9.0.0" coverage = { extras = ["toml"], version = "^7.3.2" } pytest-cov = ">=4.1,<6.0" -ruff = "^0.5.2" +ruff = ">=0.5.2,<0.7.0" mypy = "^1.7.0" pytest-asyncio = "^0.23.7" requests = "^2.32.2" diff --git a/clients/python/src/model_registry/core.py b/clients/python/src/model_registry/core.py index 4586668fa..750dc43cd 100644 --- a/clients/python/src/model_registry/core.py +++ b/clients/python/src/model_registry/core.py @@ -7,6 +7,8 @@ from dataclasses import dataclass from typing import TypeVar, cast +from typing_extensions import overload + from mr_openapi import ( ApiClient, Configuration, @@ -15,7 +17,6 @@ from mr_openapi import ( exceptions as mr_exceptions, ) -from typing_extensions import overload from ._utils import required_args from .types import ( diff --git a/clients/python/src/model_registry/types/artifacts.py b/clients/python/src/model_registry/types/artifacts.py index 4bb4af4e7..64f5a974c 100644 --- a/clients/python/src/model_registry/types/artifacts.py +++ b/clients/python/src/model_registry/types/artifacts.py @@ -15,6 +15,8 @@ from abc import ABC, abstractmethod from typing import Any, TypeVar +from typing_extensions import override + from mr_openapi import ( Artifact as ArtifactBaseModel, ) @@ -29,7 +31,6 @@ from mr_openapi import ( ModelArtifact as ModelArtifactBaseModel, ) -from typing_extensions import override from .base import BaseResourceModel diff --git a/clients/python/src/model_registry/types/base.py b/clients/python/src/model_registry/types/base.py index 5a69e18c8..bf1b8dd9b 100644 --- a/clients/python/src/model_registry/types/base.py +++ b/clients/python/src/model_registry/types/base.py @@ -6,9 +6,10 @@ from collections.abc import Sequence from typing import Any, Union, get_args -from mr_openapi.models.metadata_value import MetadataValue from pydantic import BaseModel, ConfigDict +from mr_openapi.models.metadata_value import MetadataValue + SupportedTypes = Union[bool, int, float, str] diff --git a/clients/python/src/model_registry/types/contexts.py b/clients/python/src/model_registry/types/contexts.py index 0d55114f8..2d50c4237 100644 --- a/clients/python/src/model_registry/types/contexts.py +++ b/clients/python/src/model_registry/types/contexts.py @@ -11,6 +11,8 @@ from __future__ import annotations +from typing_extensions import override + from mr_openapi import ( ModelVersion as ModelVersionBaseModel, ) @@ -25,7 +27,6 @@ from mr_openapi import ( RegisteredModel as RegisteredModelBaseModel, ) -from typing_extensions import override from .base import BaseResourceModel diff --git a/clients/python/src/mr_openapi/api_client.py b/clients/python/src/mr_openapi/api_client.py index 9ab240bb8..b10fb38e7 100644 --- a/clients/python/src/mr_openapi/api_client.py +++ b/clients/python/src/mr_openapi/api_client.py @@ -309,20 +309,20 @@ def sanitize_for_serialization(self, obj): """ if obj is None: return None - elif isinstance(obj, Enum): + if isinstance(obj, Enum): return obj.value - elif isinstance(obj, SecretStr): + if isinstance(obj, SecretStr): return obj.get_secret_value() - elif isinstance(obj, self.PRIMITIVE_TYPES): + if isinstance(obj, self.PRIMITIVE_TYPES): return obj - elif isinstance(obj, list): + if isinstance(obj, list): return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj] - elif isinstance(obj, tuple): + if isinstance(obj, tuple): return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj) - elif isinstance(obj, (datetime.datetime, datetime.date)): + if isinstance(obj, (datetime.datetime, datetime.date)): return obj.isoformat() - elif isinstance(obj, dict): + if isinstance(obj, dict): obj_dict = obj else: # Convert model obj to dict except @@ -386,16 +386,15 @@ def __deserialize(self, data, klass): if klass in self.PRIMITIVE_TYPES: return self.__deserialize_primitive(data, klass) - elif klass == object: + if klass == object: return self.__deserialize_object(data) - elif klass == datetime.date: + if klass == datetime.date: return self.__deserialize_date(data) - elif klass == datetime.datetime: + if klass == datetime.datetime: return self.__deserialize_datetime(data) - elif issubclass(klass, Enum): + if issubclass(klass, Enum): return self.__deserialize_enum(data, klass) - else: - return self.__deserialize_model(data, klass) + return self.__deserialize_model(data, klass) def parameters_to_tuples(self, params, collection_formats): """Get parameters as list of tuples, formatting collections. diff --git a/clients/python/src/mr_openapi/configuration.py b/clients/python/src/mr_openapi/configuration.py index f31a0730e..6b6a378a0 100644 --- a/clients/python/src/mr_openapi/configuration.py +++ b/clients/python/src/mr_openapi/configuration.py @@ -338,8 +338,7 @@ def get_api_key_with_prefix(self, identifier, alias=None): prefix = self.api_key_prefix.get(identifier) if prefix: return f"{prefix} {key}" - else: - return key + return key return None def auth_settings(self): diff --git a/clients/python/src/mr_openapi/models/artifact.py b/clients/python/src/mr_openapi/models/artifact.py index 6e2e79486..52feaf379 100644 --- a/clients/python/src/mr_openapi/models/artifact.py +++ b/clients/python/src/mr_openapi/models/artifact.py @@ -78,14 +78,13 @@ def actual_instance_must_validate_oneof(cls, v): "Multiple matches found when setting `actual_instance` in Artifact with oneOf schemas: DocArtifact, ModelArtifact. Details: " + ", ".join(error_messages) ) - elif match == 0: + if match == 0: # no match raise ValueError( "No match found when setting `actual_instance` in Artifact with oneOf schemas: DocArtifact, ModelArtifact. Details: " + ", ".join(error_messages) ) - else: - return v + return v @classmethod def from_dict(cls, obj: str | dict[str, Any]) -> Self: @@ -143,14 +142,13 @@ def from_json(cls, json_str: str) -> Self: "Multiple matches found when deserializing the JSON string into Artifact with oneOf schemas: DocArtifact, ModelArtifact. Details: " + ", ".join(error_messages) ) - elif match == 0: + if match == 0: # no match raise ValueError( "No match found when deserializing the JSON string into Artifact with oneOf schemas: DocArtifact, ModelArtifact. Details: " + ", ".join(error_messages) ) - else: - return instance + return instance def to_json(self) -> str: """Returns the JSON representation of the actual instance.""" @@ -159,8 +157,7 @@ def to_json(self) -> str: if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) + return json.dumps(self.actual_instance) def to_dict(self) -> dict[str, Any] | DocArtifact | ModelArtifact | None: """Returns the dict representation of the actual instance.""" @@ -169,9 +166,8 @@ def to_dict(self) -> dict[str, Any] | DocArtifact | ModelArtifact | None: if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance + # primitive type + return self.actual_instance def to_str(self) -> str: """Returns the string representation of the actual instance.""" diff --git a/clients/python/src/mr_openapi/models/metadata_value.py b/clients/python/src/mr_openapi/models/metadata_value.py index b5d13e208..a5f12684e 100644 --- a/clients/python/src/mr_openapi/models/metadata_value.py +++ b/clients/python/src/mr_openapi/models/metadata_value.py @@ -132,14 +132,13 @@ def actual_instance_must_validate_oneof(cls, v): "Multiple matches found when setting `actual_instance` in MetadataValue with oneOf schemas: MetadataBoolValue, MetadataDoubleValue, MetadataIntValue, MetadataProtoValue, MetadataStringValue, MetadataStructValue. Details: " + ", ".join(error_messages) ) - elif match == 0: + if match == 0: # no match raise ValueError( "No match found when setting `actual_instance` in MetadataValue with oneOf schemas: MetadataBoolValue, MetadataDoubleValue, MetadataIntValue, MetadataProtoValue, MetadataStringValue, MetadataStructValue. Details: " + ", ".join(error_messages) ) - else: - return v + return v @classmethod def from_dict(cls, obj: str | dict[str, Any]) -> Self: @@ -231,14 +230,13 @@ def from_json(cls, json_str: str) -> Self: "Multiple matches found when deserializing the JSON string into MetadataValue with oneOf schemas: MetadataBoolValue, MetadataDoubleValue, MetadataIntValue, MetadataProtoValue, MetadataStringValue, MetadataStructValue. Details: " + ", ".join(error_messages) ) - elif match == 0: + if match == 0: # no match raise ValueError( "No match found when deserializing the JSON string into MetadataValue with oneOf schemas: MetadataBoolValue, MetadataDoubleValue, MetadataIntValue, MetadataProtoValue, MetadataStringValue, MetadataStructValue. Details: " + ", ".join(error_messages) ) - else: - return instance + return instance def to_json(self) -> str: """Returns the JSON representation of the actual instance.""" @@ -247,8 +245,7 @@ def to_json(self) -> str: if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): return self.actual_instance.to_json() - else: - return json.dumps(self.actual_instance) + return json.dumps(self.actual_instance) def to_dict( self, @@ -268,9 +265,8 @@ def to_dict( if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): return self.actual_instance.to_dict() - else: - # primitive type - return self.actual_instance + # primitive type + return self.actual_instance def to_str(self) -> str: """Returns the string representation of the actual instance.""" diff --git a/clients/python/tests/basic_test.py b/clients/python/tests/basic_test.py index 8c0a87ec5..96f6639d7 100644 --- a/clients/python/tests/basic_test.py +++ b/clients/python/tests/basic_test.py @@ -1,7 +1,8 @@ """Tests creation and retrieval of base models.""" -import mr_openapi import pytest + +import mr_openapi from mr_openapi import ( Artifact, DocArtifact, @@ -14,7 +15,7 @@ from .conftest import REGISTRY_URL, cleanup -@pytest.fixture() +@pytest.fixture @cleanup async def client(): config = mr_openapi.Configuration(REGISTRY_URL) @@ -24,12 +25,12 @@ async def client(): await api_client.close() -@pytest.fixture() +@pytest.fixture def rm_create() -> RegisteredModelCreate: return RegisteredModelCreate(name="registered", description="a registered model") -@pytest.fixture() +@pytest.fixture async def mv_create(client, rm_create) -> ModelVersionCreate: # HACK: create an RM first because we need an ID for the instance rm = await client.create_registered_model(rm_create) diff --git a/clients/python/tests/test_client.py b/clients/python/tests/test_client.py index aa8ab39fb..8b459c091 100644 --- a/clients/python/tests/test_client.py +++ b/clients/python/tests/test_client.py @@ -2,13 +2,14 @@ from itertools import islice import pytest + from model_registry import ModelRegistry, utils from model_registry.exceptions import StoreError from .conftest import REGISTRY_HOST, REGISTRY_PORT, cleanup -@pytest.fixture() +@pytest.fixture @cleanup def client() -> ModelRegistry: return ModelRegistry(REGISTRY_HOST, REGISTRY_PORT, author="author", is_secure=False) diff --git a/clients/python/tests/test_core.py b/clients/python/tests/test_core.py index 274638383..784e94ec5 100644 --- a/clients/python/tests/test_core.py +++ b/clients/python/tests/test_core.py @@ -1,6 +1,7 @@ """Tests for user facing model registry APIs.""" import pytest + from model_registry.core import ModelRegistryAPIClient from model_registry.types import ( DocArtifact, @@ -13,7 +14,7 @@ from .conftest import REGISTRY_HOST, REGISTRY_PORT, cleanup -@pytest.fixture() +@pytest.fixture @cleanup def client(): return ModelRegistryAPIClient.insecure_connection(REGISTRY_HOST, REGISTRY_PORT) @@ -41,7 +42,7 @@ async def test_update_registered_model(client: ModelRegistryAPIClient): assert rm.last_update_time_since_epoch != last_update -@pytest.fixture() +@pytest.fixture async def registered_model(client: ModelRegistryAPIClient) -> RegisteredModel: return await client.upsert_registered_model( RegisteredModel(name="registered", external_id="mr id") @@ -126,7 +127,7 @@ async def test_update_model_version( assert mv.last_update_time_since_epoch != last_update -@pytest.fixture() +@pytest.fixture async def model_version( client: ModelRegistryAPIClient, registered_model: RegisteredModel ) -> ModelVersion: @@ -240,7 +241,7 @@ async def test_update_model_artifact( assert ma.last_update_time_since_epoch != last_update -@pytest.fixture() +@pytest.fixture async def model( client: ModelRegistryAPIClient, model_version: ModelVersion, diff --git a/clients/python/tests/test_utils.py b/clients/python/tests/test_utils.py index a29f04f3a..84ecefecf 100644 --- a/clients/python/tests/test_utils.py +++ b/clients/python/tests/test_utils.py @@ -1,6 +1,7 @@ import os import pytest + from model_registry.exceptions import MissingMetadata from model_registry.utils import s3_uri_from