Skip to content

Commit 2e9bd80

Browse files
authored
Run black to reformat (pinecone-io#203)
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)
1 parent 341a941 commit 2e9bd80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+7713
-6147
lines changed

.pre-commit-config.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- repo: https://github.com/psf/black
10+
rev: 23.9.1
11+
hooks:
12+
- id: black

pinecone/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .info import *
88
from .manage import *
99
from .index import *
10+
1011
try:
1112
from .core.grpc.index_grpc import *
1213
except ImportError:

pinecone/config.py

+57-37
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
from pinecone.core.client.exceptions import ApiKeyError
1717
from pinecone.core.api_action import ActionAPI, WhoAmIResponse
1818
from pinecone.core.utils import warn_deprecated, check_kwargs
19-
from pinecone.core.utils.constants import CLIENT_VERSION, PARENT_LOGGER_NAME, DEFAULT_PARENT_LOGGER_LEVEL, \
20-
TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT
19+
from pinecone.core.utils.constants import (
20+
CLIENT_VERSION,
21+
PARENT_LOGGER_NAME,
22+
DEFAULT_PARENT_LOGGER_LEVEL,
23+
TCP_KEEPIDLE,
24+
TCP_KEEPINTVL,
25+
TCP_KEEPCNT,
26+
)
2127
from pinecone.core.client.configuration import Configuration as OpenApiConfiguration
2228

23-
__all__ = [
24-
"Config", "init"
25-
]
29+
__all__ = ["Config", "init"]
2630

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

6468
# Get the environment first. Make sure that it is not overwritten in subsequent config objects.
6569
environment = (
66-
kwargs.pop("environment", None)
67-
or os.getenv("PINECONE_ENVIRONMENT")
68-
or file_config.pop("environment", None)
69-
or "us-west1-gcp"
70+
kwargs.pop("environment", None)
71+
or os.getenv("PINECONE_ENVIRONMENT")
72+
or file_config.pop("environment", None)
73+
or "us-west1-gcp"
7074
)
7175
config = config._replace(environment=environment)
7276

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

103107
if not self._config.project_name:
104108
config = config._replace(
105-
**self._preprocess_and_validate_config({'project_name': whoami_response.projectname}))
109+
**self._preprocess_and_validate_config({"project_name": whoami_response.projectname})
110+
)
106111

107112
self._config = config
108113

109114
# Set OpenAPI client config
110115
default_openapi_config = OpenApiConfiguration.get_default_copy()
111116
default_openapi_config.ssl_ca_cert = certifi.where()
112-
openapi_config = (
113-
kwargs.pop("openapi_config", None)
114-
or default_openapi_config
115-
)
117+
openapi_config = kwargs.pop("openapi_config", None) or default_openapi_config
116118

117119
openapi_config.socket_options = self._get_socket_options()
118120

119121
config = config._replace(openapi_config=openapi_config)
120122
self._config = config
121123

122-
123124
def _preprocess_and_validate_config(self, config: dict) -> dict:
124125
"""Normalize, filter, and validate config keys/values.
125126
@@ -128,9 +129,9 @@ def _preprocess_and_validate_config(self, config: dict) -> dict:
128129
"""
129130
# general preprocessing and filtering
130131
result = {k: v for k, v in config.items() if k in ConfigBase._fields if v is not None}
131-
result.pop('environment', None)
132+
result.pop("environment", None)
132133
# validate api key
133-
api_key = result.get('api_key')
134+
api_key = result.get("api_key")
134135
# if api_key:
135136
# try:
136137
# uuid.UUID(api_key)
@@ -152,11 +153,12 @@ def _load_config_file(self, config_file: str) -> dict:
152153
return config_obj
153154

154155
@staticmethod
155-
def _get_socket_options(do_keep_alive: bool = True,
156-
keep_alive_idle_sec: int = TCP_KEEPIDLE,
157-
keep_alive_interval_sec: int = TCP_KEEPINTVL,
158-
keep_alive_tries: int = TCP_KEEPCNT
159-
) -> List[tuple]:
156+
def _get_socket_options(
157+
do_keep_alive: bool = True,
158+
keep_alive_idle_sec: int = TCP_KEEPIDLE,
159+
keep_alive_interval_sec: int = TCP_KEEPINTVL,
160+
keep_alive_tries: int = TCP_KEEPCNT,
161+
) -> List[tuple]:
160162
"""
161163
Returns the socket options to pass to OpenAPI's Rest client
162164
Args:
@@ -179,8 +181,12 @@ def _get_socket_options(do_keep_alive: bool = True,
179181
# TCP Keep Alive Probes for different platforms
180182
platform = sys.platform
181183
# TCP Keep Alive Probes for Linux
182-
if platform == 'linux' and hasattr(socket, "TCP_KEEPIDLE") and hasattr(socket, "TCP_KEEPINTVL") \
183-
and hasattr(socket, "TCP_KEEPCNT"):
184+
if (
185+
platform == "linux"
186+
and hasattr(socket, "TCP_KEEPIDLE")
187+
and hasattr(socket, "TCP_KEEPINTVL")
188+
and hasattr(socket, "TCP_KEEPCNT")
189+
):
184190
socket_params += [(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, keep_alive_idle_sec)]
185191
socket_params += [(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, keep_alive_interval_sec)]
186192
socket_params += [(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, keep_alive_tries)]
@@ -193,7 +199,7 @@ def _get_socket_options(do_keep_alive: bool = True,
193199
# socket.ioctl((socket.SIO_KEEPALIVE_VALS, (1, keep_alive_idle_sec * 1000, keep_alive_interval_sec * 1000)))
194200

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

@@ -226,15 +232,22 @@ def LOG_LEVEL(self):
226232
"""
227233
warn_deprecated(
228234
description='LOG_LEVEL is deprecated. Use the standard logging module logger "pinecone" instead.',
229-
deprecated_in='2.0.2',
230-
removal_in='3.0.0'
235+
deprecated_in="2.0.2",
236+
removal_in="3.0.0",
231237
)
232-
return logging.getLevelName(logging.getLogger('pinecone').level)
233-
234-
235-
def init(api_key: str = None, host: str = None, environment: str = None, project_name: str = None,
236-
log_level: str = None, openapi_config: OpenApiConfiguration = None,
237-
config: str = "~/.pinecone", **kwargs):
238+
return logging.getLevelName(logging.getLogger("pinecone").level)
239+
240+
241+
def init(
242+
api_key: str = None,
243+
host: str = None,
244+
environment: str = None,
245+
project_name: str = None,
246+
log_level: str = None,
247+
openapi_config: OpenApiConfiguration = None,
248+
config: str = "~/.pinecone",
249+
**kwargs
250+
):
238251
"""Initializes the Pinecone client.
239252
240253
:param api_key: Required if not set in config file or by environment variable ``PINECONE_API_KEY``.
@@ -246,13 +259,20 @@ def init(api_key: str = None, host: str = None, environment: str = None, project
246259
: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.
247260
"""
248261
check_kwargs(init, kwargs)
249-
Config.reset(project_name=project_name, api_key=api_key, controller_host=host, environment=environment,
250-
openapi_config=openapi_config, config_file=config, **kwargs)
262+
Config.reset(
263+
project_name=project_name,
264+
api_key=api_key,
265+
controller_host=host,
266+
environment=environment,
267+
openapi_config=openapi_config,
268+
config_file=config,
269+
**kwargs
270+
)
251271
if log_level:
252272
warn_deprecated(
253273
description='log_level is deprecated. Use the standard logging module to manage logger "pinecone" instead.',
254-
deprecated_in='2.0.2',
255-
removal_in='3.0.0'
274+
deprecated_in="2.0.2",
275+
removal_in="3.0.0",
256276
)
257277

258278

pinecone/core/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#
22
# Copyright (c) 2020-2021 Pinecone Systems Inc. All right reserved.
33
#
4-

pinecone/core/api_action.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212

1313
class WhoAmIResponse(NamedTuple):
14-
username: str = 'UNKNOWN'
15-
user_label: str = 'UNKNOWN'
16-
projectname: str = 'UNKNOWN'
14+
username: str = "UNKNOWN"
15+
user_label: str = "UNKNOWN"
16+
projectname: str = "UNKNOWN"
1717

1818

1919
class VersionResponse(NamedTuple):
@@ -23,6 +23,7 @@ class VersionResponse(NamedTuple):
2323

2424
class ActionAPI(BaseAPI):
2525
"""User related API calls."""
26+
2627
client_version = get_version()
2728

2829
def whoami(self) -> WhoAmIResponse:
@@ -37,5 +38,4 @@ def whoami(self) -> WhoAmIResponse:
3738
def version(self) -> VersionResponse:
3839
"""Returns version information."""
3940
response = self.get("/actions/version")
40-
return VersionResponse(server=response.get("version", "UNKNOWN"),
41-
client=self.client_version)
41+
return VersionResponse(server=response.get("version", "UNKNOWN"), client=self.client_version)

pinecone/core/api_base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def headers(self):
1818
return {"api-key": self.api_key}
1919

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

3838
def delete(self, url: str):
3939
return self._send_request(requests.delete, url)
40-

0 commit comments

Comments
 (0)