Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump ruff to 0.6.1 #285

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions clients/python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clients/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion clients/python/src/model_registry/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from dataclasses import dataclass
from typing import TypeVar, cast

from typing_extensions import overload

from mr_openapi import (
ApiClient,
Configuration,
Expand All @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion clients/python/src/model_registry/types/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -29,7 +31,6 @@
from mr_openapi import (
ModelArtifact as ModelArtifactBaseModel,
)
from typing_extensions import override

from .base import BaseResourceModel

Expand Down
3 changes: 2 additions & 1 deletion clients/python/src/model_registry/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down
3 changes: 2 additions & 1 deletion clients/python/src/model_registry/types/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from __future__ import annotations

from typing_extensions import override

from mr_openapi import (
ModelVersion as ModelVersionBaseModel,
)
Expand All @@ -25,7 +27,6 @@
from mr_openapi import (
RegisteredModel as RegisteredModelBaseModel,
)
from typing_extensions import override

from .base import BaseResourceModel

Expand Down
25 changes: 12 additions & 13 deletions clients/python/src/mr_openapi/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions clients/python/src/mr_openapi/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 7 additions & 11 deletions clients/python/src/mr_openapi/models/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand All @@ -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."""
Expand Down
18 changes: 7 additions & 11 deletions clients/python/src/mr_openapi/models/metadata_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand All @@ -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,
Expand All @@ -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."""
Expand Down
9 changes: 5 additions & 4 deletions clients/python/tests/basic_test.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -14,7 +15,7 @@
from .conftest import REGISTRY_URL, cleanup


@pytest.fixture()
@pytest.fixture
@cleanup
async def client():
config = mr_openapi.Configuration(REGISTRY_URL)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion clients/python/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions clients/python/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading