Skip to content

Commit 95b01cb

Browse files
julian-rischclaude
andauthored
chore: enforce ruff docstring rules (D102/D103/D205/D209/D213/D417/D419) in first 10 integrations (#3008)
Enable ruff pydocstyle rules matching haystack-ai main repo config for: aimlapi, amazon_bedrock, anthropic, arcadedb, astra, azure_ai_search, azure_doc_intelligence, chroma, cohere, cometapi, and the pyproject.toml template. - Add D102, D103, D205, D209, D213, D417, D419 to ruff select in each pyproject.toml - Ignore D rules in tests/** per-file-ignores - Fix all resulting docstring violations (missing docstrings, blank line between summary and description) Closes #2947 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4d1adb4 commit 95b01cb

37 files changed

Lines changed: 169 additions & 56 deletions

File tree

integrations/aimlapi/pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ select = [
8585
"ARG",
8686
"B",
8787
"C",
88+
"D102", # Missing docstring in public method
89+
"D103", # Missing docstring in public function
90+
"D205", # 1 blank line required between summary line and description
91+
"D209", # Closing triple quotes go to new line
92+
"D213", # summary lines must be positioned on the second physical line of the docstring
93+
"D417", # Missing argument descriptions in the docstring
94+
"D419", # Docstring is empty
8895
"DTZ",
8996
"E",
9097
"EM",
@@ -132,7 +139,7 @@ ban-relative-imports = "parents"
132139

133140
[tool.ruff.lint.per-file-ignores]
134141
# Tests can use magic values, assertions, and relative imports
135-
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN"]
142+
"tests/**/*" = ["PLR2004", "S101", "TID252", "D", "ANN"]
136143

137144
[tool.coverage.run]
138145
source = ["haystack_integrations"]

integrations/aimlapi/src/haystack_integrations/components/generators/aimlapi/chat/chat_generator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
class AIMLAPIChatGenerator(OpenAIChatGenerator):
2121
"""
2222
Enables text generation using AIMLAPI generative models.
23+
2324
For supported models, see AIMLAPI documentation.
2425
2526
Users can pass any text generation parameters valid for the AIMLAPI chat completion API
@@ -73,8 +74,9 @@ def __init__(
7374
http_client_kwargs: dict[str, Any] | None = None,
7475
) -> None:
7576
"""
76-
Creates an instance of AIMLAPIChatGenerator. Unless specified otherwise,
77-
the default model is `openai/gpt-5-chat-latest`.
77+
Creates an instance of AIMLAPIChatGenerator.
78+
79+
Unless specified otherwise, the default model is `openai/gpt-5-chat-latest`.
7880
7981
:param api_key:
8082
The AIMLAPI API key.

integrations/amazon_bedrock/pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ select = [
101101
"ARG",
102102
"B",
103103
"C",
104+
"D102", # Missing docstring in public method
105+
"D103", # Missing docstring in public function
106+
"D205", # 1 blank line required between summary line and description
107+
"D209", # Closing triple quotes go to new line
108+
"D213", # summary lines must be positioned on the second physical line of the docstring
109+
"D417", # Missing argument descriptions in the docstring
110+
"D419", # Docstring is empty
104111
"DTZ",
105112
"E",
106113
"EM",
@@ -151,7 +158,7 @@ ban-relative-imports = "parents"
151158

152159
[tool.ruff.lint.per-file-ignores]
153160
# Tests can use magic values, assertions, and relative imports
154-
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN"]
161+
"tests/**/*" = ["PLR2004", "S101", "TID252", "D", "ANN"]
155162

156163
[tool.coverage.run]
157164
source = ["haystack_integrations"]

integrations/amazon_bedrock/src/haystack_integrations/common/amazon_bedrock/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def get_aws_session(
3030
) -> boto3.Session | aioboto3.Session:
3131
"""
3232
Creates an AWS Session with the given parameters.
33+
3334
Checks if the provided AWS credentials are valid and can be used to connect to AWS.
3435
3536
:param aws_access_key_id: AWS access key ID.
@@ -69,6 +70,7 @@ def get_aws_session(
6970
def aws_configured(**kwargs: Any) -> bool:
7071
"""
7172
Checks whether AWS configuration is provided.
73+
7274
:param kwargs: The kwargs passed down to the generator.
7375
:returns: True if AWS configuration is provided, False otherwise.
7476
"""

integrations/amazon_bedrock/src/haystack_integrations/common/s3/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def __init__(
5353
raise S3ConfigurationError(msg) from e
5454

5555
def download(self, key: str, local_file_path: Path) -> None:
56-
"""Download a file from S3.
56+
"""
57+
Download a file from S3.
5758
5859
:param key: The key of the file to download.
5960
:param local_file_path: The folder path to download the file to.

integrations/amazon_bedrock/src/haystack_integrations/components/downloaders/s3/s3_downloader.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
class S3Downloader:
2525
"""
2626
A component for downloading files from AWS S3 Buckets to local filesystem.
27+
2728
Supports filtering by file extensions.
2829
"""
2930

@@ -132,7 +133,8 @@ def run(
132133
self,
133134
documents: list[Document],
134135
) -> dict[str, list[Document]]:
135-
"""Download files from AWS S3 Buckets to local filesystem.
136+
"""
137+
Download files from AWS S3 Buckets to local filesystem.
136138
137139
Return enriched `Document`s with the path of the downloaded file.
138140
:param documents: Document containing the name of the file to download in the meta field.
@@ -250,6 +252,7 @@ def to_dict(self) -> dict[str, Any]:
250252
def from_dict(cls, data: dict[str, Any]) -> "S3Downloader":
251253
"""
252254
Deserializes the component from a dictionary.
255+
253256
:param data:
254257
Dictionary to deserialize from.
255258
:returns:

integrations/amazon_bedrock/src/haystack_integrations/components/embedders/amazon_bedrock/document_embedder.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
class AmazonBedrockDocumentEmbedder:
2323
"""
2424
A component for computing Document embeddings using Amazon Bedrock.
25+
2526
The embedding of each Document is stored in the `embedding` field of the Document.
2627
2728
Usage example:
@@ -66,8 +67,9 @@ def __init__(
6667
**kwargs: Any,
6768
) -> None:
6869
"""
69-
Initializes the AmazonBedrockDocumentEmbedder with the provided parameters. The parameters are passed to the
70-
Amazon Bedrock client.
70+
Initializes the AmazonBedrockDocumentEmbedder with the provided parameters.
71+
72+
The parameters are passed to the Amazon Bedrock client.
7173
7274
Note that the AWS credentials are not required if the AWS environment is configured correctly. These are loaded
7375
automatically from the environment or the AWS configuration file and do not need to be provided explicitly via
@@ -154,6 +156,7 @@ def _prepare_texts_to_embed(self, documents: list[Document]) -> list[str]:
154156
def _embed_cohere(self, documents: list[Document]) -> list[Document]:
155157
"""
156158
Internal method to embed Documents using Cohere models.
159+
157160
Batch inference is supported.
158161
"""
159162

@@ -196,6 +199,7 @@ def _embed_cohere(self, documents: list[Document]) -> list[Document]:
196199
def _embed_titan(self, documents: list[Document]) -> list[Document]:
197200
"""
198201
Internal method to embed Documents using Amazon Titan models.
202+
199203
NOTE: Batch inference is not supported, so embeddings are created one by one.
200204
"""
201205

@@ -224,7 +228,8 @@ def _embed_titan(self, documents: list[Document]) -> list[Document]:
224228

225229
@component.output_types(documents=list[Document])
226230
def run(self, documents: list[Document]) -> dict[str, list[Document]]:
227-
"""Embed the provided `Document`s using the specified model.
231+
"""
232+
Embed the provided `Document`s using the specified model.
228233
229234
:param documents: The `Document`s to embed.
230235
:returns: A dictionary with the following keys:

integrations/amazon_bedrock/src/haystack_integrations/components/embedders/amazon_bedrock/text_embedder.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ def __init__(
5454
**kwargs: Any,
5555
) -> None:
5656
"""
57-
Initializes the AmazonBedrockTextEmbedder with the provided parameters. The parameters are passed to the
58-
Amazon Bedrock client.
57+
Initializes the AmazonBedrockTextEmbedder with the provided parameters.
58+
59+
The parameters are passed to the Amazon Bedrock client.
5960
6061
Note that the AWS credentials are not required if the AWS environment is configured correctly. These are loaded
6162
automatically from the environment or the AWS configuration file and do not need to be provided explicitly via
@@ -118,7 +119,8 @@ def resolve_secret(secret: Secret | None) -> str | None:
118119

119120
@component.output_types(embedding=list[float])
120121
def run(self, text: str) -> dict[str, list[float]]:
121-
"""Embeds the input text using the Amazon Bedrock model.
122+
"""
123+
Embeds the input text using the Amazon Bedrock model.
122124
123125
:param text: The input text to embed.
124126
:returns: A dictionary with the following keys:

integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/adapters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self, model_kwargs: dict[str, Any], max_length: int | None) -> None
2727
def prepare_body(self, prompt: str, **inference_kwargs: Any) -> dict[str, Any]:
2828
"""
2929
Prepares the body for the Amazon Bedrock request.
30+
3031
Each subclass should implement this method to prepare the request body for the specific model.
3132
3233
:param prompt: The prompt to be sent to the model.
@@ -374,7 +375,8 @@ class AI21LabsJurassic2Adapter(BedrockModelAdapter):
374375
"""
375376

376377
def prepare_body(self, prompt: str, **inference_kwargs: Any) -> dict[str, Any]:
377-
"""Prepares the body for the Jurassic 2 model.
378+
"""
379+
Prepares the body for the Jurassic 2 model.
378380
379381
:param prompt: The prompt to be sent to the model.
380382
:param inference_kwargs: Additional keyword arguments passed to the handler.

integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ def __init__(
180180
tools_cachepoint_config: dict[str, str] | None = None,
181181
) -> None:
182182
"""
183-
Initializes the `AmazonBedrockChatGenerator` with the provided parameters. The parameters are passed to the
184-
Amazon Bedrock client.
183+
Initializes the `AmazonBedrockChatGenerator` with the provided parameters.
184+
185+
The parameters are passed to the Amazon Bedrock client.
185186
186187
Note that the AWS credentials are not required if the AWS environment is configured correctly. These are loaded
187188
automatically from the environment or the AWS configuration file and do not need to be provided explicitly via

0 commit comments

Comments
 (0)