From 42b26cb662eed33b982f069f5d0f95327e82241d Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Fri, 3 Nov 2023 20:45:46 -0700 Subject: [PATCH 1/8] Move grpc code under pinecone/grpc --- pinecone/__init__.py | 7 +------ pinecone/control/pinecone.py | 5 ----- pinecone/data/__init__.py | 3 +-- pinecone/data/grpc/__init__.py | 0 pinecone/grpc/__init__.py | 2 ++ pinecone/{data => }/grpc/base.py | 2 +- pinecone/{data => }/grpc/config.py | 0 pinecone/{data => }/grpc/future.py | 0 pinecone/{data => }/grpc/index_grpc.py | 4 ++-- pinecone/grpc/pinecone.py | 7 +++++++ pinecone/{data => }/grpc/retry.py | 0 pinecone/{data => }/grpc/utils.py | 0 tests/{unit => unit_grpc}/test_grpc_index.py | 5 +++-- 13 files changed, 17 insertions(+), 18 deletions(-) delete mode 100644 pinecone/data/grpc/__init__.py create mode 100644 pinecone/grpc/__init__.py rename pinecone/{data => }/grpc/base.py (99%) rename pinecone/{data => }/grpc/config.py (100%) rename pinecone/{data => }/grpc/future.py (100%) rename pinecone/{data => }/grpc/index_grpc.py (99%) create mode 100644 pinecone/grpc/pinecone.py rename pinecone/{data => }/grpc/retry.py (100%) rename pinecone/{data => }/grpc/utils.py (100%) rename tests/{unit => unit_grpc}/test_grpc_index.py (99%) 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/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/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): From b61f3f072c7da336b6c4e733b8719b54888aceb4 Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Fri, 3 Nov 2023 20:59:14 -0700 Subject: [PATCH 2/8] Refactor CI test setup --- .github/actions/setup-poetry/action.yml | 6 +++ .github/workflows/testing.yaml | 54 +++++++++++++++++++++---- Makefile | 8 ++-- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/.github/actions/setup-poetry/action.yml b/.github/actions/setup-poetry/action.yml index dae526e65..eb1c08aec 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: 'true' runs: using: 'composite' steps: @@ -16,6 +21,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..23d5f8375 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -4,7 +4,7 @@ on: workflow_call: {} jobs: - run-tests: + units-no-grpc: name: Run tests runs-on: ubuntu-latest strategy: @@ -21,12 +21,52 @@ jobs: - name: Setup Poetry uses: ./.github/actions/setup-poetry + with: + include_grpc: false + + - name: Run unit tests + run: poetry run pytest --cov=pinecone --timeout=120 tests/unit + + 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 tests - run: make tests + - name: Run unit tests (GRPC) + run: poetry run pytest --cov=pinecone --timeout=120 tests/unit_grpc - - name: Build Python client - run: make package + 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 From b6957974837c31656f8914fcdfdaa4acc6b07523 Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Fri, 3 Nov 2023 21:27:32 -0700 Subject: [PATCH 3/8] Test experiment --- .github/workflows/testing.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 23d5f8375..8f49f02e3 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -5,7 +5,7 @@ on: jobs: units-no-grpc: - name: Run tests + name: Run tests (REST) runs-on: ubuntu-latest strategy: matrix: @@ -45,7 +45,7 @@ jobs: - name: Setup Poetry uses: ./.github/actions/setup-poetry with: - include_grpc: true + include_grpc: false - name: Run unit tests (GRPC) run: poetry run pytest --cov=pinecone --timeout=120 tests/unit_grpc From ac852bb480447d90b23a347b5c92e9dd8879a20d Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Fri, 3 Nov 2023 21:54:26 -0700 Subject: [PATCH 4/8] Fix poetry extras --- poetry.lock | 12 ++++++------ pyproject.toml | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) 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" From cc46fe5bf77befe101d259f67b5feff7130b97d2 Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Fri, 3 Nov 2023 22:25:55 -0700 Subject: [PATCH 5/8] By default, do not install grpc extras in ci --- .github/actions/setup-poetry/action.yml | 2 +- .github/workflows/testing.yaml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/actions/setup-poetry/action.yml b/.github/actions/setup-poetry/action.yml index eb1c08aec..64eaf90a0 100644 --- a/.github/actions/setup-poetry/action.yml +++ b/.github/actions/setup-poetry/action.yml @@ -4,7 +4,7 @@ inputs: include_grpc: description: 'Install gRPC dependencies' required: true - default: 'true' + default: 'false' runs: using: 'composite' steps: diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 8f49f02e3..bf3c599c4 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -21,8 +21,6 @@ jobs: - name: Setup Poetry uses: ./.github/actions/setup-poetry - with: - include_grpc: false - name: Run unit tests run: poetry run pytest --cov=pinecone --timeout=120 tests/unit @@ -45,7 +43,7 @@ jobs: - name: Setup Poetry uses: ./.github/actions/setup-poetry with: - include_grpc: false + include_grpc: true - name: Run unit tests (GRPC) run: poetry run pytest --cov=pinecone --timeout=120 tests/unit_grpc From f7770634371f48fd0dd65ae64195b82436fd1e4d Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Fri, 3 Nov 2023 22:43:15 -0700 Subject: [PATCH 6/8] Install GRPC deps for pdoc build --- .github/actions/build-docs/action.yml | 2 ++ 1 file changed, 2 insertions(+) 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 From 797564c0bb72e3f386f4a97b7ce75a44083527ae Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Fri, 3 Nov 2023 22:52:24 -0700 Subject: [PATCH 7/8] Remove duplicate poetry install step --- .github/actions/setup-poetry/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/setup-poetry/action.yml b/.github/actions/setup-poetry/action.yml index 64eaf90a0..1b8f6e1b9 100644 --- a/.github/actions/setup-poetry/action.yml +++ b/.github/actions/setup-poetry/action.yml @@ -12,6 +12,7 @@ runs: uses: snok/install-poetry@v1 - name: Install dependencies + if: ${{ inputs.include_grpc == 'false' }} shell: bash run: | poetry install From 3a1e9cf4cb1232f3ca8d0021ac2d2174ea684f69 Mon Sep 17 00:00:00 2001 From: Jen Hamon Date: Fri, 3 Nov 2023 22:56:51 -0700 Subject: [PATCH 8/8] Remove unused utils with grpc deps --- pinecone/deprecated/__init__.py | 1 - pinecone/deprecated/legacy_utils.py | 21 --------------------- 2 files changed, 22 deletions(-) delete mode 100644 pinecone/deprecated/__init__.py delete mode 100644 pinecone/deprecated/legacy_utils.py 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)