From 6e7e27c9d7a1e5d3b88f0c58bb1b5e27ed3fe99b Mon Sep 17 00:00:00 2001 From: theodu Date: Mon, 28 Aug 2023 14:34:53 +0200 Subject: [PATCH] feat: fix circular import --- src/kili/client.py | 2 -- src/kili/gateways/kili_api_gateway/project/types.py | 2 +- src/kili/gateways/kili_api_gateway/queries.py | 2 +- src/kili/services/asset_import/base.py | 7 ++----- src/kili/services/copy_project/__init__.py | 3 +-- src/kili/services/data_connection/__init__.py | 3 +-- src/kili/services/helpers.py | 3 +-- src/kili/utils/bucket.py | 4 +--- tests/unit/services/asset_import/test_import_video.py | 4 ++-- 9 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/kili/client.py b/src/kili/client.py index e83acc443..baf9f1a6a 100644 --- a/src/kili/client.py +++ b/src/kili/client.py @@ -22,7 +22,6 @@ from kili.entrypoints.mutations.project import MutationsProject from kili.entrypoints.mutations.project_version import MutationsProjectVersion from kili.entrypoints.mutations.user import MutationsUser -from kili.entrypoints.queries.asset import QueriesAsset from kili.entrypoints.queries.data_connection import QueriesDataConnection from kili.entrypoints.queries.data_integration import QueriesDataIntegration from kili.entrypoints.queries.issue import QueriesIssue @@ -67,7 +66,6 @@ class Kili( # pylint: disable=too-many-ancestors,too-many-instance-attributes MutationsProject, MutationsProjectVersion, MutationsUser, - QueriesAsset, QueriesDataConnection, QueriesDataIntegration, QueriesIssue, diff --git a/src/kili/gateways/kili_api_gateway/project/types.py b/src/kili/gateways/kili_api_gateway/project/types.py index cdab74817..7b332507d 100644 --- a/src/kili/gateways/kili_api_gateway/project/types.py +++ b/src/kili/gateways/kili_api_gateway/project/types.py @@ -25,5 +25,5 @@ def build_gql_value(self): "updatedAtLte": self.updated_at_lte, } if self.archived is not None: - value["archived"] = self.archived + value["archived"] = self.archived # type: ignore return value diff --git a/src/kili/gateways/kili_api_gateway/queries.py b/src/kili/gateways/kili_api_gateway/queries.py index ebc54cc24..e148f18a7 100644 --- a/src/kili/gateways/kili_api_gateway/queries.py +++ b/src/kili/gateways/kili_api_gateway/queries.py @@ -22,7 +22,7 @@ class AbstractQueryWhere(ABC): """Abtsract class for defining the where payload to send in a graphQL query.""" @abstractmethod - def build_gql_value(self) -> Dict: + def build_gql_value(self): """Build the GraphQL where payload sent in the resolver from the arguments given to the where class.""" raise NotImplementedError diff --git a/src/kili/services/asset_import/base.py b/src/kili/services/asset_import/base.py index 77046c9ef..f3f8f2e06 100644 --- a/src/kili/services/asset_import/base.py +++ b/src/kili/services/asset_import/base.py @@ -15,7 +15,6 @@ from tenacity.retry import retry_if_exception_type from tenacity.wait import wait_exponential -from kili.client import Kili from kili.core.graphql.operations.asset.mutations import ( GQL_APPEND_MANY_ASSETS, GQL_APPEND_MANY_FRAMES_TO_DATASET, @@ -74,9 +73,7 @@ class LoggerParams(NamedTuple): class BaseBatchImporter: # pylint: disable=too-many-instance-attributes """Base class for BatchImporters.""" - def __init__( - self, kili: Kili, project_params: ProjectParams, batch_params: BatchParams, pbar: tqdm - ): + def __init__(self, kili, project_params: ProjectParams, batch_params: BatchParams, pbar: tqdm): self.kili = kili self.project_id = project_params.project_id self.input_type = project_params.input_type @@ -342,7 +339,7 @@ class BaseAbstractAssetImporter(abc.ABC): def __init__( self, - kili: Kili, + kili, project_params: ProjectParams, processing_params: ProcessingParams, logger_params: LoggerParams, diff --git a/src/kili/services/copy_project/__init__.py b/src/kili/services/copy_project/__init__.py index 66b47a78c..f8e21af60 100644 --- a/src/kili/services/copy_project/__init__.py +++ b/src/kili/services/copy_project/__init__.py @@ -4,7 +4,6 @@ from typing import Dict, Optional from kili import services -from kili.client import Kili from kili.core.graphql.operations.label.queries import LabelQuery, LabelWhere from kili.gateways.kili_api_gateway.asset.types import AssetWhere from kili.gateways.kili_api_gateway.queries import QueryOptions @@ -31,7 +30,7 @@ class ProjectCopier: # pylint: disable=too-few-public-methods "reviewCoverage", ] - def __init__(self, kili: Kili) -> None: + def __init__(self, kili) -> None: self.disable_tqdm = False self.kili = kili diff --git a/src/kili/services/data_connection/__init__.py b/src/kili/services/data_connection/__init__.py index 2d7d694f1..82fe3eea1 100644 --- a/src/kili/services/data_connection/__init__.py +++ b/src/kili/services/data_connection/__init__.py @@ -8,7 +8,6 @@ from tenacity.stop import stop_after_delay from tenacity.wait import wait_exponential -from kili.client import Kili from kili.core.graphql.operations.data_connection.queries import ( DataConnectionIdWhere, DataConnectionQuery, @@ -62,7 +61,7 @@ def trigger_validate_data_differences( def validate_data_differences( - kili: Kili, diff_type: Literal["ADD", "REMOVE"], data_connection: Dict + kili, diff_type: Literal["ADD", "REMOVE"], data_connection: Dict ) -> None: """Call the validateDataDifferences resolver and wait until the validation is done.""" diff = data_connection["dataDifferencesSummary"]["added" if diff_type == "ADD" else "removed"] diff --git a/src/kili/services/helpers.py b/src/kili/services/helpers.py index 1defdc57b..2221d866f 100644 --- a/src/kili/services/helpers.py +++ b/src/kili/services/helpers.py @@ -3,7 +3,6 @@ from pathlib import Path from typing import Any, Dict, Generator, Iterable, List, Optional, TypeVar -from kili.client import Kili from kili.core.utils import pagination from kili.exceptions import NotFound from kili.gateways.kili_api_gateway.asset.types import AssetWhere @@ -87,7 +86,7 @@ def infer_ids_from_external_ids( return id_map -def _build_id_map(kili: Kili, asset_external_ids, project_id): +def _build_id_map(kili, asset_external_ids, project_id): assets_generators: List[Generator[Dict, None, None]] = [] # query all assets by external ids batches when there are too many for external_ids_batch in pagination.BatchIteratorBuilder(asset_external_ids, 1000): diff --git a/src/kili/utils/bucket.py b/src/kili/utils/bucket.py index 351d60bb6..065638254 100644 --- a/src/kili/utils/bucket.py +++ b/src/kili/utils/bucket.py @@ -11,8 +11,6 @@ from tenacity.stop import stop_after_attempt from tenacity.wait import wait_random -from kili.client import Kili - AZURE_STRING = "blob.core.windows.net" GCP_STRING = "storage.googleapis.com" GCP_STRING_PUBLIC = "storage.cloud.google.com" @@ -25,7 +23,7 @@ def generate_unique_id(): return cuid.cuid() -def request_signed_urls(kili: Kili, file_urls: List[str]): +def request_signed_urls(kili, file_urls: List[str]): """Get upload signed URLs. Args: diff --git a/tests/unit/services/asset_import/test_import_video.py b/tests/unit/services/asset_import/test_import_video.py index 9dfc0f7ae..23070db82 100644 --- a/tests/unit/services/asset_import/test_import_video.py +++ b/tests/unit/services/asset_import/test_import_video.py @@ -312,8 +312,8 @@ def test_import_one_video_with_metadata(self, *_): @patch("kili.utils.bucket.generate_unique_id", mocked_unique_id) @patch.object(ProjectQuery, "__call__", side_effect=mocked_project_input_type("VIDEO_LEGACY")) @patch.object( - QueriesAsset, - "assets", + AssetOperationMixin, + "list_assets", MagicMock(return_value=[]), ) @patch.object(AssetOperationMixin, "count_assets", return_value=1)