Skip to content

Commit 320afc1

Browse files
author
Gareth
authored
Add Black Formatting and Linting (#355)
## Problem PRs often include formatting changes that makes it difficult to identify changes in functionality ## Solution - Format all code with `black` - Introduce linting `black` linting workflow ## 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) - [ ] Non-code change (docs, etc) - [x] None of the above: (explain here)
1 parent 701f6b6 commit 320afc1

File tree

152 files changed

+6608
-5880
lines changed

Some content is hidden

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

152 files changed

+6608
-5880
lines changed

.github/workflows/lint.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "Lint"
2+
on: [push, pull_request]
3+
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
- uses: psf/black@stable

.pre-commit-config.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v3.2.0
44
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
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-pre-commit-mirror
10+
rev: 24.4.2
1111
hooks:
12-
- id: black
12+
- id: black
13+
language_version: python3.12

pinecone/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
.. include:: ../README.md
33
"""
4+
45
import warnings
56
from tqdm import TqdmExperimentalWarning
67

@@ -17,4 +18,4 @@
1718
IndexModel,
1819
)
1920

20-
from .utils import __version__
21+
from .utils import __version__

pinecone/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
from .config import ConfigBuilder, Config
55
from .pinecone_config import PineconeConfig
66

7-
if (os.getenv('PINECONE_DEBUG') != None):
8-
logging.basicConfig(level=logging.DEBUG)
7+
if os.getenv("PINECONE_DEBUG") != None:
8+
logging.basicConfig(level=logging.DEBUG)

pinecone/config/config.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pinecone.utils import normalize_host
88
from pinecone.utils.constants import SOURCE_TAG
99

10+
1011
class Config(NamedTuple):
1112
api_key: str = ""
1213
host: str = ""
@@ -17,6 +18,7 @@ class Config(NamedTuple):
1718
additional_headers: Optional[Dict[str, str]] = {}
1819
source_tag: Optional[str] = None
1920

21+
2022
class ConfigBuilder:
2123
"""
2224
@@ -56,27 +58,29 @@ def build(
5658
raise PineconeConfigurationError("You haven't specified a host.")
5759

5860
return Config(api_key, host, proxy_url, proxy_headers, ssl_ca_certs, ssl_verify, additional_headers, source_tag)
59-
61+
6062
@staticmethod
6163
def build_openapi_config(
6264
config: Config, openapi_config: Optional[OpenApiConfiguration] = None, **kwargs
6365
) -> OpenApiConfiguration:
6466
if openapi_config:
65-
openapi_config = OpenApiConfigFactory.copy(openapi_config=openapi_config, api_key=config.api_key, host=config.host)
67+
openapi_config = OpenApiConfigFactory.copy(
68+
openapi_config=openapi_config, api_key=config.api_key, host=config.host
69+
)
6670
elif openapi_config is None:
6771
openapi_config = OpenApiConfigFactory.build(api_key=config.api_key, host=config.host)
6872

6973
# Check if value passed before overriding any values present
70-
# in the openapi_config. This means if the user has passed
74+
# in the openapi_config. This means if the user has passed
7175
# an openapi_config object and a kwarg for the same setting,
7276
# the kwarg will take precedence.
73-
if (config.proxy_url):
77+
if config.proxy_url:
7478
openapi_config.proxy = config.proxy_url
75-
if (config.proxy_headers):
79+
if config.proxy_headers:
7680
openapi_config.proxy_headers = config.proxy_headers
77-
if (config.ssl_ca_certs):
81+
if config.ssl_ca_certs:
7882
openapi_config.ssl_ca_cert = config.ssl_ca_certs
79-
if (config.ssl_verify != None):
83+
if config.ssl_verify != None:
8084
openapi_config.verify_ssl = config.ssl_verify
81-
82-
return openapi_config
85+
86+
return openapi_config

pinecone/config/openapi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ def build(cls, api_key: str, host: Optional[str] = None, **kwargs):
2323
openapi_config.ssl_ca_cert = certifi.where()
2424
openapi_config.socket_options = cls._get_socket_options()
2525
return openapi_config
26-
26+
2727
@classmethod
2828
def copy(cls, openapi_config: OpenApiConfiguration, api_key: str, host: str) -> OpenApiConfiguration:
29-
'''
30-
Copy a user-supplied openapi configuration and update it with the user's api key and host.
29+
"""
30+
Copy a user-supplied openapi configuration and update it with the user's api key and host.
3131
If they have not specified other socket configuration, we will use the default values.
32-
We expect these objects are being passed mainly a vehicle for proxy configuration, so
32+
We expect these objects are being passed mainly a vehicle for proxy configuration, so
3333
we don't modify those settings.
34-
'''
34+
"""
3535
copied = copy.deepcopy(openapi_config)
3636

3737
copied.api_key = {"ApiKeyAuth": api_key}

pinecone/config/pinecone_config.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99
DEFAULT_CONTROLLER_HOST = "https://api.pinecone.io"
1010

1111

12-
class PineconeConfig():
12+
class PineconeConfig:
1313
@staticmethod
14-
def build(api_key: Optional[str] = None, host: Optional[str] = None, additional_headers: Optional[Dict[str, str]] = {}, **kwargs) -> Config:
14+
def build(
15+
api_key: Optional[str] = None,
16+
host: Optional[str] = None,
17+
additional_headers: Optional[Dict[str, str]] = {},
18+
**kwargs,
19+
) -> Config:
1520
host = host or kwargs.get("host") or os.getenv("PINECONE_CONTROLLER_HOST") or DEFAULT_CONTROLLER_HOST
1621
headers_json = os.getenv("PINECONE_ADDITIONAL_HEADERS")
1722
if headers_json:
18-
try:
19-
headers = json.loads(headers_json)
20-
additional_headers = additional_headers or headers
21-
except Exception as e:
22-
logger.warn(f'Ignoring PINECONE_ADDITIONAL_HEADERS: {e}')
23+
try:
24+
headers = json.loads(headers_json)
25+
additional_headers = additional_headers or headers
26+
except Exception as e:
27+
logger.warn(f"Ignoring PINECONE_ADDITIONAL_HEADERS: {e}")
2328

2429
return ConfigBuilder.build(api_key=api_key, host=host, additional_headers=additional_headers, **kwargs)

pinecone/control/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .pinecone import Pinecone
1+
from .pinecone import Pinecone

pinecone/control/index_host_store.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pinecone.core.client.exceptions import PineconeException
55
from pinecone.utils import normalize_host
66

7+
78
class SingletonMeta(type):
89
_instances: Dict[str, str] = {}
910

@@ -42,5 +43,7 @@ def get_host(self, api: IndexOperationsApi, config: Config, index_name: str) ->
4243
description = api.describe_index(index_name)
4344
self.set_host(config, index_name, description.host)
4445
if not self.key_exists(key):
45-
raise PineconeException(f"Could not get host for index: {index_name}. Call describe_index('{index_name}') to check the current status.")
46+
raise PineconeException(
47+
f"Could not get host for index: {index_name}. Call describe_index('{index_name}') to check the current status."
48+
)
4649
return self._indexHosts[key]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from pinecone.utils import docslinks
22

3-
KB_ARTICLE = docslinks['LANGCHAIN_IMPORT_KB_ARTICLE']
4-
GITHUB_REPO = docslinks['GITHUB_REPO']
3+
KB_ARTICLE = docslinks["LANGCHAIN_IMPORT_KB_ARTICLE"]
4+
GITHUB_REPO = docslinks["GITHUB_REPO"]
5+
56

67
def _build_langchain_attribute_error_message(method_name: str):
78
return f"""{method_name} is not a top-level attribute of the Pinecone class provided by pinecone's official python package developed at {GITHUB_REPO}. You may have a name collision with an export from another dependency in your project that wraps Pinecone functionality and exports a similarly named class. Please refer to the following knowledge base article for more information: {KB_ARTICLE}
89
"""
9-

0 commit comments

Comments
 (0)