diff --git a/.github/actions/build-docs/action.yml b/.github/actions/build-docs/action.yml index 32166afcb..e9d2f4607 100644 --- a/.github/actions/build-docs/action.yml +++ b/.github/actions/build-docs/action.yml @@ -15,6 +15,8 @@ runs: - name: Setup Poetry uses: ./.github/actions/setup-poetry + with: + include_grpc: 'true' - name: Build html documentation shell: bash diff --git a/.github/actions/setup-poetry/action.yml b/.github/actions/setup-poetry/action.yml index dae526e65..1b8f6e1b9 100644 --- a/.github/actions/setup-poetry/action.yml +++ b/.github/actions/setup-poetry/action.yml @@ -1,5 +1,10 @@ name: 'Setup Poetry' description: 'Installs Poetry and dependencies' +inputs: + include_grpc: + description: 'Install gRPC dependencies' + required: true + default: 'false' runs: using: 'composite' steps: @@ -7,6 +12,7 @@ runs: uses: snok/install-poetry@v1 - name: Install dependencies + if: ${{ inputs.include_grpc == 'false' }} shell: bash run: | poetry install @@ -16,6 +22,7 @@ runs: # The dependencies that are specific to gRPC are defined in pyproject.toml # under tool.poetry.extras - name: Install gRPC dependencies + if: ${{ inputs.include_grpc == 'true' }} shell: bash run: | poetry install --extras "grpc" diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 61b7ec05d..bf3c599c4 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -4,8 +4,8 @@ on: workflow_call: {} jobs: - run-tests: - name: Run tests + units-no-grpc: + name: Run tests (REST) runs-on: ubuntu-latest strategy: matrix: @@ -22,11 +22,49 @@ jobs: - name: Setup Poetry uses: ./.github/actions/setup-poetry - - name: Run tests - run: make tests + - name: Run unit tests + run: poetry run pytest --cov=pinecone --timeout=120 tests/unit - - name: Build Python client - run: make package + units-grpc: + name: Run tests (GRPC) + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.8, 3.9, '3.10', 3.11] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup Poetry + uses: ./.github/actions/setup-poetry + with: + include_grpc: true + + - name: Run unit tests (GRPC) + run: poetry run pytest --cov=pinecone --timeout=120 tests/unit_grpc + + package: + name: Check packaging + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.8, 3.9, '3.10', 3.11] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup Poetry + uses: ./.github/actions/setup-poetry - - name: Build docs - run: make docs + - name: Package + run: poetry build diff --git a/Makefile b/Makefile index 62df52dd3..3f36bbf5a 100644 --- a/Makefile +++ b/Makefile @@ -9,12 +9,14 @@ image: develop: poetry install -E grpc -tests: - @echo "Installing dependencies..." - poetry install +test-unit: @echo "Running tests..." poetry run pytest --cov=pinecone --timeout=120 tests/unit +test-grpc-unit: + @echo "Running tests..." + poetry run pytest --cov=pinecone --timeout=120 tests/unit_grpc + version: poetry version diff --git a/pinecone/__init__.py b/pinecone/__init__.py index a614ff283..fbacdaddd 100644 --- a/pinecone/__init__.py +++ b/pinecone/__init__.py @@ -4,9 +4,4 @@ from .config import * from .exceptions import * from .control.pinecone import Pinecone -from .data.index import * - -try: - from .data.grpc.index_grpc import * -except ImportError: - pass # ignore for non-[grpc] installations +from .data.index import * \ No newline at end of file diff --git a/pinecone/control/pinecone.py b/pinecone/control/pinecone.py index 535b087e8..5b6557b09 100644 --- a/pinecone/control/pinecone.py +++ b/pinecone/control/pinecone.py @@ -14,8 +14,6 @@ from pinecone.utils import get_user_agent from pinecone.data import Index -from pinecone.data import GRPCIndex - class Pinecone: def __init__( @@ -270,6 +268,3 @@ def _get_status(self, name: str): def Index(self, name: str): index_host = self.index_host_store.get_host(self.index_api, self.config, name) return Index(api_key=self.config.API_KEY, host=index_host) - - def GRPCIndex(self, name: str): - return GRPCIndex(self.config, name) diff --git a/pinecone/data/__init__.py b/pinecone/data/__init__.py index 7d4f066ef..a43d33ac4 100644 --- a/pinecone/data/__init__.py +++ b/pinecone/data/__init__.py @@ -1,2 +1 @@ -from .index import Index -from .grpc.index_grpc import GRPCIndex \ No newline at end of file +from .index import Index \ No newline at end of file diff --git a/pinecone/data/grpc/__init__.py b/pinecone/data/grpc/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/pinecone/deprecated/__init__.py b/pinecone/deprecated/__init__.py deleted file mode 100644 index f67d72268..000000000 --- a/pinecone/deprecated/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .legacy_utils import * \ No newline at end of file diff --git a/pinecone/deprecated/legacy_utils.py b/pinecone/deprecated/legacy_utils.py deleted file mode 100644 index f614f80d6..000000000 --- a/pinecone/deprecated/legacy_utils.py +++ /dev/null @@ -1,21 +0,0 @@ -import re - -try: - from google.protobuf.struct_pb2 import Struct - from google.protobuf import json_format -except Exception: - pass # ignore for non-[grpc] installations - -DNS_COMPATIBLE_REGEX = re.compile("^[a-z0-9]([a-z0-9]|[-])+[a-z0-9]$") - -def validate_dns_name(name): - if not DNS_COMPATIBLE_REGEX.match(name): - raise ValueError( - "{} is invalid - service names and node names must consist of lower case " - "alphanumeric characters or '-', start with an alphabetic character, and end with an " - "alphanumeric character (e.g. 'my-name', or 'abc-123')".format(name) - ) - - -def proto_struct_to_dict(s: "Struct") -> dict: - return json_format.MessageToDict(s) diff --git a/pinecone/grpc/__init__.py b/pinecone/grpc/__init__.py new file mode 100644 index 000000000..77920733d --- /dev/null +++ b/pinecone/grpc/__init__.py @@ -0,0 +1,2 @@ +from .index_grpc import GRPCIndex +from .pinecone import Pinecone \ No newline at end of file diff --git a/pinecone/data/grpc/base.py b/pinecone/grpc/base.py similarity index 99% rename from pinecone/data/grpc/base.py rename to pinecone/grpc/base.py index 3452f5962..9dad1bbc4 100644 --- a/pinecone/data/grpc/base.py +++ b/pinecone/grpc/base.py @@ -1,7 +1,7 @@ import logging from abc import ABC, abstractmethod from functools import wraps -from typing import NamedTuple, Optional, Dict +from typing import Dict import certifi import grpc diff --git a/pinecone/data/grpc/config.py b/pinecone/grpc/config.py similarity index 100% rename from pinecone/data/grpc/config.py rename to pinecone/grpc/config.py diff --git a/pinecone/data/grpc/future.py b/pinecone/grpc/future.py similarity index 100% rename from pinecone/data/grpc/future.py rename to pinecone/grpc/future.py diff --git a/pinecone/data/grpc/index_grpc.py b/pinecone/grpc/index_grpc.py similarity index 99% rename from pinecone/data/grpc/index_grpc.py rename to pinecone/grpc/index_grpc.py index ef6e23db0..3b4344dec 100644 --- a/pinecone/data/grpc/index_grpc.py +++ b/pinecone/grpc/index_grpc.py @@ -34,8 +34,8 @@ REQUIRED_VECTOR_FIELDS, OPTIONAL_VECTOR_FIELDS, ) -from pinecone.data.grpc.base import GRPCIndexBase -from pinecone.data.grpc.future import PineconeGrpcFuture +from .base import GRPCIndexBase +from .future import PineconeGrpcFuture __all__ = ["GRPCIndex", "GRPCVector", "GRPCQueryVector", "GRPCSparseValues"] diff --git a/pinecone/grpc/pinecone.py b/pinecone/grpc/pinecone.py new file mode 100644 index 000000000..be7654259 --- /dev/null +++ b/pinecone/grpc/pinecone.py @@ -0,0 +1,7 @@ +from ..control.pinecone import Pinecone +from .index_grpc import GRPCIndex + +class Pinecone(Pinecone): + def Index(self, name: str): + index_host = self.index_host_store.get_host(self.index_api, self.config, name) + return GRPCIndex(api_key=self.config.API_KEY, host=index_host) diff --git a/pinecone/data/grpc/retry.py b/pinecone/grpc/retry.py similarity index 100% rename from pinecone/data/grpc/retry.py rename to pinecone/grpc/retry.py diff --git a/pinecone/data/grpc/utils.py b/pinecone/grpc/utils.py similarity index 100% rename from pinecone/data/grpc/utils.py rename to pinecone/grpc/utils.py diff --git a/poetry.lock b/poetry.lock index 90b7fb33a..7c344445c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -236,7 +236,7 @@ wmi = ["wmi (>=1.5.1,<2.0.0)"] name = "googleapis-common-protos" version = "1.60.0" description = "Common protobufs used in Google APIs" -optional = false +optional = true python-versions = ">=3.7" files = [ {file = "googleapis-common-protos-1.60.0.tar.gz", hash = "sha256:e73ebb404098db405ba95d1e1ae0aa91c3e15a71da031a2eeb6b2e23e7bc3708"}, @@ -253,7 +253,7 @@ grpc = ["grpcio (>=1.44.0,<2.0.0.dev0)"] name = "grpc-gateway-protoc-gen-openapiv2" version = "0.1.0" description = "Provides the missing pieces for gRPC Gateway." -optional = false +optional = true python-versions = ">=3.6" files = [ {file = "grpc-gateway-protoc-gen-openapiv2-0.1.0.tar.gz", hash = "sha256:03b8934080ae81f709af041e4f89694db586a95ff35abba05d033d499811d4f6"}, @@ -267,7 +267,7 @@ googleapis-common-protos = "*" name = "grpcio" version = "1.59.0" description = "HTTP/2-based RPC framework" -optional = false +optional = true python-versions = ">=3.7" files = [ {file = "grpcio-1.59.0-cp310-cp310-linux_armv7l.whl", hash = "sha256:225e5fa61c35eeaebb4e7491cd2d768cd8eb6ed00f2664fa83a58f29418b39fd"}, @@ -390,7 +390,7 @@ dev = ["Sphinx (>=2.2.1)", "black (>=19.10b0)", "codecov (>=2.0.15)", "colorama name = "lz4" version = "4.3.2" description = "LZ4 Bindings for Python" -optional = false +optional = true python-versions = ">=3.7" files = [ {file = "lz4-4.3.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:1c4c100d99eed7c08d4e8852dd11e7d1ec47a3340f49e3a96f8dfbba17ffb300"}, @@ -657,7 +657,7 @@ dev = ["pre-commit", "tox"] name = "protobuf" version = "3.20.3" description = "Protocol Buffers" -optional = false +optional = true python-versions = ">=3.7" files = [ {file = "protobuf-3.20.3-cp310-cp310-manylinux2014_aarch64.whl", hash = "sha256:f4bd856d702e5b0d96a00ec6b307b0f51c1982c2bf9c0052cf9019e9a544ba99"}, @@ -1050,4 +1050,4 @@ grpc = ["googleapis-common-protos", "grpc-gateway-protoc-gen-openapiv2", "grpcio [metadata] lock-version = "2.0" python-versions = ">=3.8,<4.0" -content-hash = "eb925f93e12e47feb53591724acc3a48b1f33d913798f610ce6506bda52aa38c" +content-hash = "de52f73dfd853e443fe764680dd9953775276f842470786873c3449457089cf9" diff --git a/pyproject.toml b/pyproject.toml index 24bf7617a..47d791ba2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,11 +63,11 @@ dnspython = ">=2.0.0" python-dateutil = ">=2.5.3" urllib3 = "1.25.3" tqdm = ">=4.64.1" -grpcio = ">=1.44.0" -grpc-gateway-protoc-gen-openapiv2 = "0.1.0" -googleapis-common-protos = ">=1.53.0" -lz4 = ">=3.1.3" -protobuf = "~=3.20.0" +grpcio = { version = ">=1.44.0", optional = true } +grpc-gateway-protoc-gen-openapiv2 = { version = "0.1.0", optional = true } +googleapis-common-protos = { version = ">=1.53.0", optional = true } +lz4 = { version = ">=3.1.3", optional = true } +protobuf = { version = "~=3.20.0", optional = true } [tool.poetry.group.dev.dependencies] numpy = ">=1.22" diff --git a/tests/unit/test_grpc_index.py b/tests/unit_grpc/test_grpc_index.py similarity index 99% rename from tests/unit/test_grpc_index.py rename to tests/unit_grpc/test_grpc_index.py index b98ce7687..b797fd26b 100644 --- a/tests/unit/test_grpc_index.py +++ b/tests/unit_grpc/test_grpc_index.py @@ -4,7 +4,8 @@ import pandas as pd import pytest -from pinecone import Config, GRPCIndex +from pinecone import Config +from pinecone.grpc import GRPCIndex from pinecone import DescribeIndexStatsRequest from pinecone.core.grpc.protos.vector_service_pb2 import ( Vector, @@ -18,7 +19,7 @@ UpsertResponse, SparseValues, ) -from pinecone.data.grpc.utils import dict_to_proto_struct +from pinecone.grpc.utils import dict_to_proto_struct class TestGrpcIndex: def setup_method(self):