From d848b387f38340c7218a9b68cd5beffbbef45219 Mon Sep 17 00:00:00 2001 From: Gordon Hart Date: Fri, 26 Jan 2024 16:13:00 -0500 Subject: [PATCH 1/6] Simplify __init__ to not dance around lack of importlib.metadata in 3.7 --- kolena/__init__.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/kolena/__init__.py b/kolena/__init__.py index 3c32990dd..e7578bc3a 100644 --- a/kolena/__init__.py +++ b/kolena/__init__.py @@ -18,25 +18,10 @@ # mypy: ignore-errors # # (robots do not like this file) +from importlib.metadata import version __name__ = "kolena" -__version__: str - - -def __version_assign() -> None: - global __version__ - try: - from importlib.metadata import version - - __version__ = version(__name__) - except ModuleNotFoundError: - import importlib_metadata # importlib.metadata was introduced to the standard library in 3.8 - - __version__ = importlib_metadata.version(__name__) - - -__version_assign() -del __version_assign +__version__ = version(__name__) import kolena.errors From bb18a0c4e95782cd536a6a2e7336168eb7de2229 Mon Sep 17 00:00:00 2001 From: Gordon Hart Date: Fri, 26 Jan 2024 16:13:57 -0500 Subject: [PATCH 2/6] Remove robot ignores in __init__ --- kolena/__init__.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/kolena/__init__.py b/kolena/__init__.py index e7578bc3a..ae5989fd6 100644 --- a/kolena/__init__.py +++ b/kolena/__init__.py @@ -11,22 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# -# flake8: noqa -# autopep8: off -# noreorder -# mypy: ignore-errors -# -# (robots do not like this file) from importlib.metadata import version -__name__ = "kolena" -__version__ = version(__name__) - - import kolena.errors from .initialize import initialize +__name__ = "kolena" +__version__ = version(__name__) __all__ = [ "initialize", "errors", From 2ca931dd46a9a23fad2bfb0292a99a7a38c94bee Mon Sep 17 00:00:00 2001 From: Gordon Hart Date: Fri, 26 Jan 2024 16:17:34 -0500 Subject: [PATCH 3/6] Clean up __init__ --- kolena/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kolena/__init__.py b/kolena/__init__.py index ae5989fd6..eb1b3e3fe 100644 --- a/kolena/__init__.py +++ b/kolena/__init__.py @@ -13,13 +13,13 @@ # limitations under the License. from importlib.metadata import version +__name__ = "kolena" +__version__ = version(__name__) + import kolena.errors from .initialize import initialize -__name__ = "kolena" -__version__ = version(__name__) __all__ = [ "initialize", "errors", - "workflow", ] From d3a4c2301543d1323bbeac6009da2e676ad8ed00 Mon Sep 17 00:00:00 2001 From: Gordon Hart Date: Fri, 26 Jan 2024 16:19:47 -0500 Subject: [PATCH 4/6] Remove unused Uninstantiable definition --- kolena/_utils/uninstantiable.py | 61 --------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 kolena/_utils/uninstantiable.py diff --git a/kolena/_utils/uninstantiable.py b/kolena/_utils/uninstantiable.py deleted file mode 100644 index 601961eb4..000000000 --- a/kolena/_utils/uninstantiable.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright 2021-2024 Kolena Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import typing -from typing import Any -from typing import Generic -from typing import Type -from typing import TypeVar - -from kolena.errors import DirectInstantiationError -from kolena.errors import IncorrectUsageError - -T = TypeVar("T") -U = TypeVar("U", bound="Uninstantiable") - - -class Uninstantiable(Generic[T]): - __slots__ = ("data",) - __frozen__ = False - - data: T - - def __init__(self, *args: Any, **kwargs: Any) -> None: - raise DirectInstantiationError( - f"{type(self).__name__} is not directly instantiatable, " - "please use one of the available static constructors", - ) - - @typing.no_type_check - def __setattr__(self, key, value): - if self.__frozen__: - raise IncorrectUsageError("cannot modify frozen class") - object.__setattr__(self, key, value) - - def __repr__(self) -> str: - return f"{type(self).__name__}(data={repr(self.data)})" - - def __eq__(self, other: Any) -> bool: - return isinstance(other, type(self)) and other.data == self.data - - @classmethod - def __factory__(cls: Type[U], data: Any) -> U: - obj = cls.__new__(cls) - obj.data = data - obj.__frozen__ = True - return obj - - def __update__(self, data: T) -> None: - object.__setattr__(self, "__frozen__", False) - self.data = data - self.__frozen__ = True From bbd55e6fa542a53d447a956a0bc7ba5f4390f8e9 Mon Sep 17 00:00:00 2001 From: Gordon Hart Date: Fri, 26 Jan 2024 16:20:08 -0500 Subject: [PATCH 5/6] Remove unused Serializable definition --- kolena/_utils/serializable.py | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 kolena/_utils/serializable.py diff --git a/kolena/_utils/serializable.py b/kolena/_utils/serializable.py deleted file mode 100644 index c6429d716..000000000 --- a/kolena/_utils/serializable.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2021-2024 Kolena Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import json -from abc import ABCMeta -from abc import abstractmethod -from typing import Any -from typing import Dict - - -class Serializable(metaclass=ABCMeta): - @abstractmethod - def _to_dict(self) -> Dict[str, Any]: - ... - - def __hash__(self) -> int: - return hash(json.dumps(self._to_dict())) From 759220064192f80abe596c7960d1c79169fc541e Mon Sep 17 00:00:00 2001 From: Gordon Hart Date: Fri, 26 Jan 2024 16:20:44 -0500 Subject: [PATCH 6/6] Remove unused AssetPathMapper --- kolena/_utils/asset_path_mapper.py | 39 ------------------------------ 1 file changed, 39 deletions(-) delete mode 100644 kolena/_utils/asset_path_mapper.py diff --git a/kolena/_utils/asset_path_mapper.py b/kolena/_utils/asset_path_mapper.py deleted file mode 100644 index 3e9ba39d3..000000000 --- a/kolena/_utils/asset_path_mapper.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2021-2024 Kolena Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from kolena._api.v1.fr import Asset - - -class AssetPathMapper: - """ - Maps images associated with test run as PNG assets to the configured S3 bucket as: - s3:///////.png - """ - - def __init__(self, config: Asset.Config): - self.bucket = config.bucket - self.prefix = config.prefix - - def absolute_locator(self, test_run_id: int, load_uuid: str, image_id: int, key: str) -> str: - return self._absolute_locator(self.relative_locator(self.path_stub(test_run_id, load_uuid, image_id, key))) - - def relative_locator(self, path_stub: str) -> str: - return f"{self.prefix}/{path_stub}" - - @staticmethod - def path_stub(test_run_id: int, load_uuid: str, image_id: int, key: str) -> str: - return f"{test_run_id}/{image_id}/{key}-{load_uuid}.png" - - def _absolute_locator(self, relative_locator: str) -> str: - relative_locator_stripped = relative_locator.strip("/") - return f"s3://{self.bucket}/{relative_locator_stripped}"