Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@ dmypy.json
# Datasets
*.hdf5
*~

# Code generation files
gen/
downloads/
70 changes: 28 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
.PHONY: image develop tests tag-and-push docs version package upload upload-spruce license
SHELL = /bin/bash
mkfile_path := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

PYPI_USERNAME ?= __token__
gcloud-auth:
gcloud auth login
gcloud config set project development-pinecone

image:
MODULE=pinecone ../scripts/build.sh ./
clean:
rm -rf downloads
rm -rf gen

develop:
poetry install -E grpc
regenerate: clean
mkdir downloads
gcloud storage cp gs://api-codegen/_latest downloads --recursive

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

make type-check:
poetry run mypy pinecone --exclude pinecone/core

version:
poetry version

package:
poetry build

upload:
poetry publish --verbose --username ${PYPI_USERNAME} --password ${PYPI_PASSWORD}

upload-spruce:
# Configure Poetry for publishing to testpypi
poetry config repositories.test-pypi https://test.pypi.org/legacy/
poetry publish --verbose -r test-pypi --username ${PYPI_USERNAME} --password ${PYPI_PASSWORD}
# Remove problematic query param
jq 'walk(if type == "array" then map(if type == "object" then select(.name != "filter") else . end) else . end)' downloads/_latest/openapi/pinecone_api.json > tmp.json
mv tmp.json downloads/_latest/openapi/pinecone_api.json

license:
# Add license header using https://github.com/google/addlicense.
# If the license header already exists in a file, re-running this command has no effect.
pushd ${mkfile_path}/pinecone && \
docker run --rm -it -v ${mkfile_path}/pinecone:/src ghcr.io/google/addlicense:latest -f ./license_header.txt *.py */*.py */*/*.py */*/*/*.py */*/*/*/*.py */*/*/*/*/*.py */*/*/*/*/*/*.py; \
popd

set-production:
echo "production" > pinecone/__environment__

set-development:
echo "" > pinecone/__environment__
# Generate new openapi rest client
rm -rf pinecone/core
mkdir -p pinecone/core
docker run --rm -v ${mkfile_path}:/workspace openapitools/openapi-generator-cli:v5.2.0 generate \
--input-spec /workspace/downloads/_latest/openapi/pinecone_api.json \
--config /workspace/codegen/openapi/openapi-generator-args.python.json \
--generator-name python \
--template-dir /workspace/codegen/openapi/templates5.2.0 \
--output /workspace/gen/python
cp -r ${mkfile_path}gen/python/pinecone/core/* ${mkfile_path}pinecone/core/

# Update grpc client
mkdir -p pinecone/core/grpc/protos
cp -r ${mkfile_path}downloads/_latest/python/pinecone/data/v1/* ${mkfile_path}pinecone/core/grpc/protos
${mkfile_path}codegen/grpc.sh
8 changes: 8 additions & 0 deletions codegen/grpc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module="vector_service"
dest="pinecone/core/grpc/protos"
module_prefix="pinecone.core.grpc.protos"

head -n 4 "${dest}/${module}_pb2_grpc.py" > "${dest}/tmp.py"
echo "import ${module_prefix}.${module}_pb2 as $(echo "${module}_pb2" | sed 's/_/__/g')" >> "${dest}/tmp.py"
tail -n +7 "${dest}/${module}_pb2_grpc.py" >> "${dest}/tmp.py"
mv "${dest}/tmp.py" "${dest}/${module}_pb2_grpc.py"
4 changes: 4 additions & 0 deletions codegen/openapi/openapi-generator-args.python.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"packageName": "pinecone.core.client",
"pythonAttrNoneIfUnset": true
}
55 changes: 55 additions & 0 deletions codegen/openapi/templates5.2.0/README.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# {{{projectName}}}
{{#appDescriptionWithNewLines}}
{{{appDescriptionWithNewLines}}}
{{/appDescriptionWithNewLines}}

This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: {{appVersion}}
- Package version: {{packageVersion}}
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}
- Build package: {{generatorClass}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Requirements.

Python >= 3.6

## Installation & Usage
### pip install

If the python package is hosted on a repository, you can install directly using:

```sh
pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git
```
(you may need to run `pip` with root permission: `sudo pip install git+https://{{gitHost}}/{{{gitUserId}}}/{{{gitRepoId}}}.git`)

Then import the package:
```python
import {{{packageName}}}
```

### Setuptools

Install via [Setuptools](http://pypi.python.org/pypi/setuptools).

```sh
python setup.py install --user
```
(or `sudo python setup.py install` to install the package for all users)

Then import the package:
```python
import {{{packageName}}}
```

## Getting Started

Please follow the [installation procedure](#installation--usage) and then run the following:

{{> README_common }}
111 changes: 111 additions & 0 deletions codegen/openapi/templates5.2.0/README_common.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
```python
{{#apiInfo}}{{#apis}}{{#-last}}{{#hasHttpSignatureMethods}}import datetime{{/hasHttpSignatureMethods}}{{/-last}}{{/apis}}{{/apiInfo}}
import time
import {{{packageName}}}
from pprint import pprint
{{#apiInfo}}
{{#apis}}
{{#-first}}
from {{apiPackage}} import {{classVarName}}
{{#imports}}
{{{import}}}
{{/imports}}
{{#operations}}
{{#operation}}
{{#-first}}
{{> python_doc_auth_partial}}

# Enter a context with an instance of the API client
with {{{packageName}}}.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = {{classVarName}}.{{{classname}}}(api_client)
{{#allParams}}{{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{^required}} (optional){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
{{/allParams}}

try:
{{#summary}} # {{{.}}}
{{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}
pprint(api_response){{/returnType}}
except {{{packageName}}}.PineconeApiException as e:
print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
{{/-first}}
{{/operation}}
{{/operations}}
{{/-first}}
{{/apis}}
{{/apiInfo}}
```

## Documentation for API Endpoints

All URIs are relative to *{{basePath}}*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}

## Documentation For Models

{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md)
{{/model}}{{/models}}

## Documentation For Authorization

{{^authMethods}}
All endpoints do not require authorization.
{{/authMethods}}
{{#authMethods}}
{{#last}} Authentication schemes defined for the API:{{/last}}
## {{{name}}}

{{#isApiKey}}
- **Type**: API key
- **API key parameter name**: {{{keyParamName}}}
- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
{{/isApiKey}}
{{#isBasic}}
{{#isBasicBasic}}
- **Type**: HTTP basic authentication
{{/isBasicBasic}}
{{#isBasicBearer}}
- **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}
{{/isBasicBearer}}
{{#isHttpSignature}}
- **Type**: HTTP signature authentication
{{/isHttpSignature}}
{{/isBasic}}
{{#isOAuth}}
- **Type**: OAuth
- **Flow**: {{{flow}}}
- **Authorization URL**: {{{authorizationUrl}}}
- **Scopes**: {{^scopes}}N/A{{/scopes}}
{{#scopes}} - **{{{scope}}}**: {{{description}}}
{{/scopes}}
{{/isOAuth}}

{{/authMethods}}

## Author

{{#apiInfo}}{{#apis}}{{#-last}}{{infoEmail}}
{{/-last}}{{/apis}}{{/apiInfo}}

## Notes for Large OpenAPI documents
If the OpenAPI document is large, imports in {{{packageName}}}.apis and {{{packageName}}}.models may fail with a
RecursionError indicating the maximum recursion limit has been exceeded. In that case, there are a couple of solutions:

Solution 1:
Use specific imports for apis and models like:
- `from {{{packageName}}}.api.default_api import DefaultApi`
- `from {{{packageName}}}.model.pet import Pet`

Solution 2:
Before importing the package, adjust the maximum recursion limit as shown below:
```
import sys
sys.setrecursionlimit(1500)
import {{{packageName}}}
from {{{packageName}}}.apis import *
from {{{packageName}}}.models import *
```
42 changes: 42 additions & 0 deletions codegen/openapi/templates5.2.0/README_onlypackage.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# {{{projectName}}}
{{#appDescription}}
{{{appDescription}}}
{{/appDescription}}

The `{{packageName}}` package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: {{appVersion}}
- Package version: {{packageVersion}}
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}
- Build package: {{generatorClass}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

## Requirements.

Python >= 3.6

## Installation & Usage

This python library package is generated without supporting files like setup.py or requirements files

To be able to use it, you will need these dependencies in your own package that uses this library:

* urllib3 >= 1.25.3
* python-dateutil
{{#asyncio}}
* aiohttp
{{/asyncio}}
{{#tornado}}
* tornado>=4.2,<5
{{/tornado}}

## Getting Started

In your own code, to use this library to connect and interact with {{{projectName}}},
you can run the following:

{{> README_common }}
Empty file.
9 changes: 9 additions & 0 deletions codegen/openapi/templates5.2.0/__init__api.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{#apiInfo}}
{{#apis}}
{{#-first}}
# do not import all apis into this module because that uses a lot of memory and stack frames
# if you need the ability to import all apis from one package, import them with
# from {{packageName}}.apis import {{classname}}
{{/-first}}
{{/apis}}
{{/apiInfo}}
23 changes: 23 additions & 0 deletions codegen/openapi/templates5.2.0/__init__apis.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{#apiInfo}}
{{#apis}}
{{#-first}}

# flake8: noqa

# Import all APIs into this package.
# If you have many APIs here with many many models used in each API this may
# raise a `RecursionError`.
# In order to avoid this, import only the API that you directly need like:
#
# from {{packagename}}.api.{{classVarName}} import {{classname}}
#
# or import this package, but before doing it, use:
#
# import sys
# sys.setrecursionlimit(n)

# Import APIs into API package:
{{/-first}}
from {{apiPackage}}.{{classVarName}} import {{classname}}
{{/apis}}
{{/apiInfo}}
5 changes: 5 additions & 0 deletions codegen/openapi/templates5.2.0/__init__model.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# we can not import model classes here because that would create a circular
# reference which would not work in python2
# do not import all models into this module because that uses a lot of memory and stack frames
# if you need the ability to import all models from one package, import them with
# from {{packageName}.models import ModelA, ModelB
16 changes: 16 additions & 0 deletions codegen/openapi/templates5.2.0/__init__models.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# flake8: noqa

# import all models into this package
# if you have many models here with many references from one model to another this may
# raise a RecursionError
# to avoid this, import only the models that you directly need like:
# from from {{modelPackage}}.pet import Pet
# or import this package, but before doing it, use:
# import sys
# sys.setrecursionlimit(n)

{{#models}}
{{#model}}
from {{modelPackage}}.{{classFilename}} import {{classname}}
{{/model}}
{{/models}}
26 changes: 26 additions & 0 deletions codegen/openapi/templates5.2.0/__init__package.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# flake8: noqa

{{>partial_header}}

__version__ = "{{packageVersion}}"

# import ApiClient
from {{packageName}}.api_client import ApiClient

# import Configuration
from {{packageName}}.configuration import Configuration
{{#hasHttpSignatureMethods}}
from {{packageName}}.signing import HttpSigningConfiguration
{{/hasHttpSignatureMethods}}

# import exceptions
from {{packageName}}.exceptions import PineconeException
from {{packageName}}.exceptions import PineconeApiAttributeError
from {{packageName}}.exceptions import PineconeApiTypeError
from {{packageName}}.exceptions import PineconeApiValueError
from {{packageName}}.exceptions import PineconeApiKeyError
from {{packageName}}.exceptions import PineconeApiException
{{#recursionLimit}}

__import__('sys').setrecursionlimit({{{.}}})
{{/recursionLimit}}
Loading