Skip to content

Commit

Permalink
Run black to reformat (#203)
Browse files Browse the repository at this point in the history
Black is the formatter we specify but we haven't run it in some time

## Type of Change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Infrastructure change (CI configs, etc)
- [x] Non-code change (docs, etc)
- [ ] None of the above: (explain here)
  • Loading branch information
gdj0nes authored Sep 27, 2023
1 parent 341a941 commit 2e9bd80
Show file tree
Hide file tree
Showing 58 changed files with 7,713 additions and 6,147 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
1 change: 1 addition & 0 deletions pinecone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .info import *
from .manage import *
from .index import *

try:
from .core.grpc.index_grpc import *
except ImportError:
Expand Down
94 changes: 57 additions & 37 deletions pinecone/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
from pinecone.core.client.exceptions import ApiKeyError
from pinecone.core.api_action import ActionAPI, WhoAmIResponse
from pinecone.core.utils import warn_deprecated, check_kwargs
from pinecone.core.utils.constants import CLIENT_VERSION, PARENT_LOGGER_NAME, DEFAULT_PARENT_LOGGER_LEVEL, \
TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT
from pinecone.core.utils.constants import (
CLIENT_VERSION,
PARENT_LOGGER_NAME,
DEFAULT_PARENT_LOGGER_LEVEL,
TCP_KEEPIDLE,
TCP_KEEPINTVL,
TCP_KEEPCNT,
)
from pinecone.core.client.configuration import Configuration as OpenApiConfiguration

__all__ = [
"Config", "init"
]
__all__ = ["Config", "init"]

_logger = logging.getLogger(__name__)
_parent_logger = logging.getLogger(PARENT_LOGGER_NAME)
Expand Down Expand Up @@ -63,10 +67,10 @@ def reset(self, config_file=None, **kwargs):

# Get the environment first. Make sure that it is not overwritten in subsequent config objects.
environment = (
kwargs.pop("environment", None)
or os.getenv("PINECONE_ENVIRONMENT")
or file_config.pop("environment", None)
or "us-west1-gcp"
kwargs.pop("environment", None)
or os.getenv("PINECONE_ENVIRONMENT")
or file_config.pop("environment", None)
or "us-west1-gcp"
)
config = config._replace(environment=environment)

Expand Down Expand Up @@ -102,24 +106,21 @@ def reset(self, config_file=None, **kwargs):

if not self._config.project_name:
config = config._replace(
**self._preprocess_and_validate_config({'project_name': whoami_response.projectname}))
**self._preprocess_and_validate_config({"project_name": whoami_response.projectname})
)

self._config = config

# Set OpenAPI client config
default_openapi_config = OpenApiConfiguration.get_default_copy()
default_openapi_config.ssl_ca_cert = certifi.where()
openapi_config = (
kwargs.pop("openapi_config", None)
or default_openapi_config
)
openapi_config = kwargs.pop("openapi_config", None) or default_openapi_config

openapi_config.socket_options = self._get_socket_options()

config = config._replace(openapi_config=openapi_config)
self._config = config


def _preprocess_and_validate_config(self, config: dict) -> dict:
"""Normalize, filter, and validate config keys/values.
Expand All @@ -128,9 +129,9 @@ def _preprocess_and_validate_config(self, config: dict) -> dict:
"""
# general preprocessing and filtering
result = {k: v for k, v in config.items() if k in ConfigBase._fields if v is not None}
result.pop('environment', None)
result.pop("environment", None)
# validate api key
api_key = result.get('api_key')
api_key = result.get("api_key")
# if api_key:
# try:
# uuid.UUID(api_key)
Expand All @@ -152,11 +153,12 @@ def _load_config_file(self, config_file: str) -> dict:
return config_obj

@staticmethod
def _get_socket_options(do_keep_alive: bool = True,
keep_alive_idle_sec: int = TCP_KEEPIDLE,
keep_alive_interval_sec: int = TCP_KEEPINTVL,
keep_alive_tries: int = TCP_KEEPCNT
) -> List[tuple]:
def _get_socket_options(
do_keep_alive: bool = True,
keep_alive_idle_sec: int = TCP_KEEPIDLE,
keep_alive_interval_sec: int = TCP_KEEPINTVL,
keep_alive_tries: int = TCP_KEEPCNT,
) -> List[tuple]:
"""
Returns the socket options to pass to OpenAPI's Rest client
Args:
Expand All @@ -179,8 +181,12 @@ def _get_socket_options(do_keep_alive: bool = True,
# TCP Keep Alive Probes for different platforms
platform = sys.platform
# TCP Keep Alive Probes for Linux
if platform == 'linux' and hasattr(socket, "TCP_KEEPIDLE") and hasattr(socket, "TCP_KEEPINTVL") \
and hasattr(socket, "TCP_KEEPCNT"):
if (
platform == "linux"
and hasattr(socket, "TCP_KEEPIDLE")
and hasattr(socket, "TCP_KEEPINTVL")
and hasattr(socket, "TCP_KEEPCNT")
):
socket_params += [(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, keep_alive_idle_sec)]
socket_params += [(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, keep_alive_interval_sec)]
socket_params += [(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, keep_alive_tries)]
Expand All @@ -193,7 +199,7 @@ def _get_socket_options(do_keep_alive: bool = True,
# socket.ioctl((socket.SIO_KEEPALIVE_VALS, (1, keep_alive_idle_sec * 1000, keep_alive_interval_sec * 1000)))

# TCP Keep Alive Probes for Mac OS
elif platform == 'darwin':
elif platform == "darwin":
TCP_KEEPALIVE = 0x10
socket_params += [(socket.IPPROTO_TCP, TCP_KEEPALIVE, keep_alive_interval_sec)]

Expand Down Expand Up @@ -226,15 +232,22 @@ def LOG_LEVEL(self):
"""
warn_deprecated(
description='LOG_LEVEL is deprecated. Use the standard logging module logger "pinecone" instead.',
deprecated_in='2.0.2',
removal_in='3.0.0'
deprecated_in="2.0.2",
removal_in="3.0.0",
)
return logging.getLevelName(logging.getLogger('pinecone').level)


def init(api_key: str = None, host: str = None, environment: str = None, project_name: str = None,
log_level: str = None, openapi_config: OpenApiConfiguration = None,
config: str = "~/.pinecone", **kwargs):
return logging.getLevelName(logging.getLogger("pinecone").level)


def init(
api_key: str = None,
host: str = None,
environment: str = None,
project_name: str = None,
log_level: str = None,
openapi_config: OpenApiConfiguration = None,
config: str = "~/.pinecone",
**kwargs
):
"""Initializes the Pinecone client.
:param api_key: Required if not set in config file or by environment variable ``PINECONE_API_KEY``.
Expand All @@ -246,13 +259,20 @@ def init(api_key: str = None, host: str = None, environment: str = None, project
:param log_level: Deprecated since v2.0.2 [Will be removed in v3.0.0]; use the standard logging module to manage logger "pinecone" instead.
"""
check_kwargs(init, kwargs)
Config.reset(project_name=project_name, api_key=api_key, controller_host=host, environment=environment,
openapi_config=openapi_config, config_file=config, **kwargs)
Config.reset(
project_name=project_name,
api_key=api_key,
controller_host=host,
environment=environment,
openapi_config=openapi_config,
config_file=config,
**kwargs
)
if log_level:
warn_deprecated(
description='log_level is deprecated. Use the standard logging module to manage logger "pinecone" instead.',
deprecated_in='2.0.2',
removal_in='3.0.0'
deprecated_in="2.0.2",
removal_in="3.0.0",
)


Expand Down
1 change: 0 additions & 1 deletion pinecone/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#
# Copyright (c) 2020-2021 Pinecone Systems Inc. All right reserved.
#

10 changes: 5 additions & 5 deletions pinecone/core/api_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@


class WhoAmIResponse(NamedTuple):
username: str = 'UNKNOWN'
user_label: str = 'UNKNOWN'
projectname: str = 'UNKNOWN'
username: str = "UNKNOWN"
user_label: str = "UNKNOWN"
projectname: str = "UNKNOWN"


class VersionResponse(NamedTuple):
Expand All @@ -23,6 +23,7 @@ class VersionResponse(NamedTuple):

class ActionAPI(BaseAPI):
"""User related API calls."""

client_version = get_version()

def whoami(self) -> WhoAmIResponse:
Expand All @@ -37,5 +38,4 @@ def whoami(self) -> WhoAmIResponse:
def version(self) -> VersionResponse:
"""Returns version information."""
response = self.get("/actions/version")
return VersionResponse(server=response.get("version", "UNKNOWN"),
client=self.client_version)
return VersionResponse(server=response.get("version", "UNKNOWN"), client=self.client_version)
3 changes: 1 addition & 2 deletions pinecone/core/api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def headers(self):
return {"api-key": self.api_key}

def _send_request(self, request_handler, url, **kwargs):
response = request_handler('{0}{1}'.format(self.host, url), headers=self.headers, **kwargs)
response = request_handler("{0}{1}".format(self.host, url), headers=self.headers, **kwargs)
try:
response.raise_for_status()
except HTTPError as e:
Expand All @@ -37,4 +37,3 @@ def patch(self, url: str, json: dict = None):

def delete(self, url: str):
return self._send_request(requests.delete, url)

Loading

0 comments on commit 2e9bd80

Please sign in to comment.