Skip to content

Commit 93bf06e

Browse files
eavanvalkenburgmoonbox3
andauthoredNov 19, 2024··
Python: updated pre-commits (#9739)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> Put some of the pre-commit steps to their latest versions. Improve the setup of the uv lock hook. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Evan Mattson <[email protected]>

File tree

17 files changed

+26
-20
lines changed

17 files changed

+26
-20
lines changed
 

‎python/.pre-commit-config.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ repos:
3232
- id: pyupgrade
3333
args: [--py310-plus]
3434
- repo: https://github.com/astral-sh/ruff-pre-commit
35-
rev: v0.7.1
35+
rev: v0.7.4
3636
hooks:
3737
- id: ruff
3838
args: [ --fix, --exit-non-zero-on-fix ]
3939
- id: ruff-format
4040
- repo: https://github.com/astral-sh/uv-pre-commit
4141
# uv version.
42-
rev: 0.4.30
42+
rev: 0.5.2
4343
hooks:
4444
# Update the uv lockfile
4545
- id: uv-lock
46+
files: python/pyproject.toml
47+
args: [--project, python]
4648
- repo: https://github.com/PyCQA/bandit
47-
rev: 1.7.8
49+
rev: 1.7.10
4850
hooks:
4951
- id: bandit
5052
args: ["-c", "python/pyproject.toml"]

‎python/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ dev-dependencies = [
136136
"snoop ~= 0.4",
137137
"mypy >= 1.10",
138138
"types-PyYAML ~= 6.0.12.20240311",
139-
"ruff ~= 0.5"
139+
"ruff ~= 0.7"
140140
]
141141
environments = [
142142
"sys_platform == 'darwin'",

‎python/samples/concepts/plugins/openai_plugin_azure_key_vault.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ async def main() -> None:
241241

242242
openai_spec = load_and_update_openai_spec()
243243

244-
http_client = httpx.AsyncClient()
244+
http_client = httpx.AsyncClient(timeout=5)
245245

246246
await kernel.add_plugin_from_openai(
247247
plugin_name="AzureKeyVaultPlugin",

‎python/samples/learn_resources/plugins/GithubPlugin/github.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def create_client(self) -> httpx.AsyncClient:
102102
"Authorization": f"Bearer {self.settings.token}",
103103
"X-GitHub-Api-Version": "2022-11-28",
104104
}
105-
return httpx.AsyncClient(base_url=self.settings.base_url, headers=headers)
105+
return httpx.AsyncClient(base_url=self.settings.base_url, headers=headers, timeout=5)
106106

107107
@staticmethod
108108
def build_query(path: str, key: str, value: str) -> str:

‎python/semantic_kernel/connectors/openapi_plugin/openapi_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async def make_request(client: httpx.AsyncClient):
178178

179179
if hasattr(self, "http_client") and self.http_client is not None:
180180
return await make_request(self.http_client)
181-
async with httpx.AsyncClient() as client:
181+
async with httpx.AsyncClient(timeout=5) as client:
182182
return await make_request(client)
183183

184184
return await fetch()

‎python/semantic_kernel/connectors/search/__init__.py

Whitespace-only changes.

‎python/semantic_kernel/connectors/search/bing/bing_search.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ async def _inner_search(self, query: str, options: TextSearchOptions) -> BingSea
168168
"user_agent": SEMANTIC_KERNEL_USER_AGENT,
169169
}
170170
try:
171-
async with AsyncClient() as client:
171+
async with AsyncClient(timeout=5) as client:
172172
response = await client.get(url, headers=headers, params=params)
173173
response.raise_for_status()
174174
return BingSearchResponse.model_validate_json(response.text)

‎python/semantic_kernel/connectors/search/google/google_search.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ async def _inner_search(self, query: str, options: TextSearchOptions) -> GoogleS
159159
full_url = f"{CUSTOM_SEARCH_URL}{self._build_query(query, options)}"
160160
headers = {"user_agent": SEMANTIC_KERNEL_USER_AGENT}
161161
try:
162-
async with AsyncClient() as client:
162+
async with AsyncClient(timeout=5) as client:
163163
response = await client.get(full_url, headers=headers)
164164
response.raise_for_status()
165165
return GoogleSearchResponse.model_validate_json(response.text)

‎python/semantic_kernel/connectors/search_engine/bing_connector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async def search(self, query: str, num_results: int = 1, offset: int = 0) -> lis
7979
headers = {"Ocp-Apim-Subscription-Key": self._settings.api_key.get_secret_value()}
8080

8181
try:
82-
async with AsyncClient() as client:
82+
async with AsyncClient(timeout=5) as client:
8383
response = await client.get(request_url, headers=headers)
8484
response.raise_for_status()
8585
data = response.json()

‎python/semantic_kernel/connectors/search_engine/google_connector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def search(self, query: str, num_results: int = 1, offset: int = 0) -> lis
8888
logger.info("Sending GET request to Google Search API.")
8989

9090
try:
91-
async with AsyncClient() as client:
91+
async with AsyncClient(timeout=5) as client:
9292
response = await client.get(request_url)
9393
response.raise_for_status()
9494
data = response.json()

‎python/semantic_kernel/connectors/utils/document_loader.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DocumentLoader:
1919
async def from_uri(
2020
url: str,
2121
http_client: AsyncClient,
22-
auth_callback: Callable[..., None | Awaitable[dict[str, str]]] | None,
22+
auth_callback: Callable[..., Awaitable[dict[str, str]] | None] | None,
2323
user_agent: str | None = HTTP_USER_AGENT,
2424
):
2525
"""Load the manifest from the given URL."""

‎python/semantic_kernel/core_plugins/sessions_python_tool/sessions_python_plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363
settings = SessionsPythonSettings()
6464

6565
if not http_client:
66-
http_client = AsyncClient()
66+
http_client = AsyncClient(timeout=5)
6767

6868
if auth_callback is None:
6969
auth_callback = self._default_auth_callback(aca_settings)

‎python/semantic_kernel/functions/kernel_function_from_prompt.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ def __init__(
6363
template_format: TEMPLATE_FORMAT_TYPES = KERNEL_TEMPLATE_FORMAT_NAME,
6464
prompt_template: PromptTemplateBase | None = None,
6565
prompt_template_config: PromptTemplateConfig | None = None,
66-
prompt_execution_settings: None
67-
| (PromptExecutionSettings | list[PromptExecutionSettings] | dict[str, PromptExecutionSettings]) = None,
66+
prompt_execution_settings: PromptExecutionSettings
67+
| list[PromptExecutionSettings]
68+
| dict[str, PromptExecutionSettings]
69+
| None = None,
6870
) -> None:
6971
"""Initializes a new instance of the KernelFunctionFromPrompt class.
7072

‎python/semantic_kernel/functions/kernel_plugin.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ async def from_openai(
420420
openai_manifest = plugin_str
421421
elif plugin_url is not None:
422422
# Load plugin from the URL
423-
http_client = execution_parameters.http_client if execution_parameters.http_client else httpx.AsyncClient()
423+
http_client = (
424+
execution_parameters.http_client if execution_parameters.http_client else httpx.AsyncClient(timeout=5)
425+
)
424426
openai_manifest = await DocumentLoader.from_uri(
425427
url=plugin_url, http_client=http_client, auth_callback=None, user_agent=execution_parameters.user_agent
426428
)

‎python/semantic_kernel/kernel_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
T = TypeVar("T")
1111

1212
OneOrMany = Union[T, Sequence[T]]
13-
OptionalOneOrMany = Union[None, T, Sequence[T]]
13+
OptionalOneOrMany = Union[T, Sequence[T], None]
1414

1515
__all__ = ["AI_SERVICE_CLIENT_TYPE", "OneOrMany", "OptionalOneOrMany"]

‎python/semantic_kernel/prompt_template/prompt_template_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def check_input_variables(self):
5252
@classmethod
5353
def rewrite_execution_settings(
5454
cls,
55-
settings: None | (PromptExecutionSettings | list[PromptExecutionSettings] | dict[str, PromptExecutionSettings]),
55+
settings: PromptExecutionSettings | list[PromptExecutionSettings] | dict[str, PromptExecutionSettings] | None,
5656
) -> dict[str, PromptExecutionSettings]:
5757
"""Rewrite execution settings to a dictionary."""
5858
if not settings:

‎python/uv.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.