16
16
from pinecone .core .client .exceptions import ApiKeyError
17
17
from pinecone .core .api_action import ActionAPI , WhoAmIResponse
18
18
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
+ )
21
27
from pinecone .core .client .configuration import Configuration as OpenApiConfiguration
22
28
23
- __all__ = [
24
- "Config" , "init"
25
- ]
29
+ __all__ = ["Config" , "init" ]
26
30
27
31
_logger = logging .getLogger (__name__ )
28
32
_parent_logger = logging .getLogger (PARENT_LOGGER_NAME )
@@ -63,10 +67,10 @@ def reset(self, config_file=None, **kwargs):
63
67
64
68
# Get the environment first. Make sure that it is not overwritten in subsequent config objects.
65
69
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"
70
74
)
71
75
config = config ._replace (environment = environment )
72
76
@@ -102,24 +106,21 @@ def reset(self, config_file=None, **kwargs):
102
106
103
107
if not self ._config .project_name :
104
108
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
+ )
106
111
107
112
self ._config = config
108
113
109
114
# Set OpenAPI client config
110
115
default_openapi_config = OpenApiConfiguration .get_default_copy ()
111
116
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
116
118
117
119
openapi_config .socket_options = self ._get_socket_options ()
118
120
119
121
config = config ._replace (openapi_config = openapi_config )
120
122
self ._config = config
121
123
122
-
123
124
def _preprocess_and_validate_config (self , config : dict ) -> dict :
124
125
"""Normalize, filter, and validate config keys/values.
125
126
@@ -128,9 +129,9 @@ def _preprocess_and_validate_config(self, config: dict) -> dict:
128
129
"""
129
130
# general preprocessing and filtering
130
131
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 )
132
133
# validate api key
133
- api_key = result .get (' api_key' )
134
+ api_key = result .get (" api_key" )
134
135
# if api_key:
135
136
# try:
136
137
# uuid.UUID(api_key)
@@ -152,11 +153,12 @@ def _load_config_file(self, config_file: str) -> dict:
152
153
return config_obj
153
154
154
155
@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 ]:
160
162
"""
161
163
Returns the socket options to pass to OpenAPI's Rest client
162
164
Args:
@@ -179,8 +181,12 @@ def _get_socket_options(do_keep_alive: bool = True,
179
181
# TCP Keep Alive Probes for different platforms
180
182
platform = sys .platform
181
183
# 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
+ ):
184
190
socket_params += [(socket .IPPROTO_TCP , socket .TCP_KEEPIDLE , keep_alive_idle_sec )]
185
191
socket_params += [(socket .IPPROTO_TCP , socket .TCP_KEEPINTVL , keep_alive_interval_sec )]
186
192
socket_params += [(socket .IPPROTO_TCP , socket .TCP_KEEPCNT , keep_alive_tries )]
@@ -193,7 +199,7 @@ def _get_socket_options(do_keep_alive: bool = True,
193
199
# socket.ioctl((socket.SIO_KEEPALIVE_VALS, (1, keep_alive_idle_sec * 1000, keep_alive_interval_sec * 1000)))
194
200
195
201
# TCP Keep Alive Probes for Mac OS
196
- elif platform == ' darwin' :
202
+ elif platform == " darwin" :
197
203
TCP_KEEPALIVE = 0x10
198
204
socket_params += [(socket .IPPROTO_TCP , TCP_KEEPALIVE , keep_alive_interval_sec )]
199
205
@@ -226,15 +232,22 @@ def LOG_LEVEL(self):
226
232
"""
227
233
warn_deprecated (
228
234
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" ,
231
237
)
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
+ ):
238
251
"""Initializes the Pinecone client.
239
252
240
253
: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
246
259
: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.
247
260
"""
248
261
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
+ )
251
271
if log_level :
252
272
warn_deprecated (
253
273
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" ,
256
276
)
257
277
258
278
0 commit comments