From 7139745d9c99bac8fc6c50b543e696ee1fccc33d Mon Sep 17 00:00:00 2001 From: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com> Date: Tue, 16 Jan 2024 12:10:28 +0100 Subject: [PATCH] Move package under haystack_integrations (#214) * Move package under haystack_integrations * Fix linting * Fix linting again? --- integrations/weaviate/pyproject.toml | 18 ++++++++++-------- .../document_stores/weaviate}/__init__.py | 5 ++--- .../weaviate}/document_store.py | 3 ++- .../weaviate/tests/test_document_store.py | 11 +++++------ 4 files changed, 19 insertions(+), 18 deletions(-) rename integrations/weaviate/src/{weaviate_haystack => haystack_integrations/document_stores/weaviate}/__init__.py (51%) rename integrations/weaviate/src/{weaviate_haystack => haystack_integrations/document_stores/weaviate}/document_store.py (99%) diff --git a/integrations/weaviate/pyproject.toml b/integrations/weaviate/pyproject.toml index c90d70046..50f1c157c 100644 --- a/integrations/weaviate/pyproject.toml +++ b/integrations/weaviate/pyproject.toml @@ -34,6 +34,9 @@ Source = "https://github.com/deepset-ai/haystack-core-integrations" Documentation = "https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/weaviate/README.md" Issues = "https://github.com/deepset-ai/haystack-core-integrations/issues" +[tool.hatch.build.targets.wheel] +packages = ["src/haystack_integrations"] + [tool.hatch.version] source = "vcs" tag-pattern = 'integrations\/weaviate-v(?P.*)' @@ -71,7 +74,7 @@ dependencies = [ "ruff>=0.0.243", ] [tool.hatch.envs.lint.scripts] -typing = "mypy --install-types --non-interactive {args:src/weaviate_haystack tests}" +typing = "mypy --install-types --non-interactive --explicit-package-bases {args:src/ tests}" style = [ "ruff {args:.}", "black --check --diff {args:.}", @@ -137,25 +140,23 @@ unfixable = [ ] [tool.ruff.isort] -known-first-party = ["weaviate_haystack"] +known-first-party = ["src"] [tool.ruff.flake8-tidy-imports] -ban-relative-imports = "all" +ban-relative-imports = "parents" [tool.ruff.per-file-ignores] # Tests can use magic values, assertions, and relative imports "tests/**/*" = ["PLR2004", "S101", "TID252"] [tool.coverage.run] -source_pkgs = ["weaviate_haystack", "tests"] +source_pkgs = ["src", "tests"] branch = true parallel = true -omit = [ - "src/weaviate_haystack/__about__.py", -] + [tool.coverage.paths] -weaviate_haystack = ["src/weaviate_haystack", "*/weaviate-haystack/src/weaviate_haystack"] +weaviate_haystack = ["src/haystack_integrations", "*/weaviate-haystack/src"] tests = ["tests", "*/weaviate-haystack/tests"] [tool.coverage.report] @@ -168,6 +169,7 @@ exclude_lines = [ [[tool.mypy.overrides]] module = [ "haystack.*", + "haystack_integrations.*", "pytest.*", "weaviate.*", "numpy", diff --git a/integrations/weaviate/src/weaviate_haystack/__init__.py b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/__init__.py similarity index 51% rename from integrations/weaviate/src/weaviate_haystack/__init__.py rename to integrations/weaviate/src/haystack_integrations/document_stores/weaviate/__init__.py index 4c8377627..c6f9b8776 100644 --- a/integrations/weaviate/src/weaviate_haystack/__init__.py +++ b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/__init__.py @@ -1,7 +1,6 @@ # SPDX-FileCopyrightText: 2023-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 +from .document_store import WeaviateDocumentStore -from weaviate_haystack.document_store import WeaviateDocumentStore - -__all__ = ("WeaviateDocumentStore",) +__all__ = ["WeaviateDocumentStore"] diff --git a/integrations/weaviate/src/weaviate_haystack/document_store.py b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py similarity index 99% rename from integrations/weaviate/src/weaviate_haystack/document_store.py rename to integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py index 263d96aad..9317fb9de 100644 --- a/integrations/weaviate/src/weaviate_haystack/document_store.py +++ b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py @@ -4,10 +4,11 @@ from dataclasses import asdict from typing import Any, Dict, List, Optional, Tuple, Union -import weaviate from haystack.core.serialization import default_from_dict, default_to_dict from haystack.dataclasses.document import Document from haystack.document_stores.protocol import DuplicatePolicy + +import weaviate from weaviate.auth import AuthCredentials from weaviate.config import Config, ConnectionConfig from weaviate.embedded import EmbeddedOptions diff --git a/integrations/weaviate/tests/test_document_store.py b/integrations/weaviate/tests/test_document_store.py index 69e7c36b5..3c72934b1 100644 --- a/integrations/weaviate/tests/test_document_store.py +++ b/integrations/weaviate/tests/test_document_store.py @@ -1,5 +1,6 @@ from unittest.mock import patch +from haystack_integrations.document_stores.weaviate.document_store import WeaviateDocumentStore from weaviate.auth import AuthApiKey from weaviate.config import Config from weaviate.embedded import ( @@ -10,11 +11,9 @@ EmbeddedOptions, ) -from weaviate_haystack.document_store import WeaviateDocumentStore - class TestWeaviateDocumentStore: - @patch("weaviate_haystack.document_store.weaviate") + @patch("haystack_integrations.document_stores.weaviate.document_store.weaviate") def test_to_dict(self, _mock_weaviate): document_store = WeaviateDocumentStore( url="http://localhost:8080", @@ -30,7 +29,7 @@ def test_to_dict(self, _mock_weaviate): additional_config=Config(grpc_port_experimental=12345), ) assert document_store.to_dict() == { - "type": "weaviate_haystack.document_store.WeaviateDocumentStore", + "type": "haystack_integrations.document_stores.weaviate.document_store.WeaviateDocumentStore", "init_parameters": { "url": "http://localhost:8080", "auth_client_secret": { @@ -61,11 +60,11 @@ def test_to_dict(self, _mock_weaviate): }, } - @patch("weaviate_haystack.document_store.weaviate") + @patch("haystack_integrations.document_stores.weaviate.document_store.weaviate") def test_from_dict(self, _mock_weaviate): document_store = WeaviateDocumentStore.from_dict( { - "type": "weaviate_haystack.document_store.WeaviateDocumentStore", + "type": "haystack_integrations.document_stores.weaviate.document_store.WeaviateDocumentStore", "init_parameters": { "url": "http://localhost:8080", "auth_client_secret": {