From 8d6b880e93398cf780054c10ea93d940a78c139a Mon Sep 17 00:00:00 2001 From: Ganapathi Diddi Date: Mon, 26 Aug 2024 18:14:57 +0530 Subject: [PATCH 1/3] Fixing DeprecationWarnings in Python 3.13.0rc1 --- .../botbuilder-ai/botbuilder/ai/luis/activity_util.py | 4 ++-- libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py | 9 ++++++++- libraries/botbuilder-ai/setup.py | 2 +- libraries/botbuilder-ai/tests/qna/test_qna.py | 3 +-- .../processor/telemetry_processor.py | 2 +- libraries/botbuilder-applicationinsights/setup.py | 2 +- .../botbuilder/core/adapters/test_adapter.py | 4 ++-- .../botbuilder/core/inspection/trace_activity.py | 8 ++++---- .../botbuilder/core/transcript_logger.py | 6 +++--- .../botbuilder-core/botbuilder/core/turn_context.py | 4 ++-- .../botbuilder/dialogs/prompts/oauth_prompt.py | 2 +- libraries/botbuilder-integration-aiohttp/setup.py | 2 +- .../setup.py | 2 +- .../botbuilder-schema/botbuilder/schema/_models_py3.py | 6 +++--- .../botframework-connector/tests/requirements.txt | 5 +++-- .../botframework-connector/tests/test_attachments.py | 10 +++++++++- 16 files changed, 43 insertions(+), 28 deletions(-) diff --git a/libraries/botbuilder-ai/botbuilder/ai/luis/activity_util.py b/libraries/botbuilder-ai/botbuilder/ai/luis/activity_util.py index d2656a3ba..303917fbb 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/luis/activity_util.py +++ b/libraries/botbuilder-ai/botbuilder/ai/luis/activity_util.py @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -from datetime import datetime +from datetime import datetime, timezone from botbuilder.schema import ( Activity, @@ -51,7 +51,7 @@ def create_trace( reply = Activity( type=ActivityTypes.trace, - timestamp=datetime.utcnow(), + timestamp=datetime.now(timezone.utc), from_property=from_property, recipient=ChannelAccount( id=turn_activity.from_property.id, name=turn_activity.from_property.name diff --git a/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py b/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py index 825e08e8e..657a6e5ba 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py +++ b/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py @@ -1,6 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +import asyncio import json from typing import Dict, List, NamedTuple, Union from aiohttp import ClientSession, ClientTimeout @@ -52,8 +53,14 @@ def __init__( opt = options or QnAMakerOptions() self._validate_options(opt) + try: + loop = asyncio.get_running_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + instance_timeout = ClientTimeout(total=opt.timeout / 1000) - self._http_client = http_client or ClientSession(timeout=instance_timeout) + self._http_client = http_client or ClientSession(timeout=instance_timeout, loop=loop) self.telemetry_client: Union[BotTelemetryClient, NullTelemetryClient] = ( telemetry_client or NullTelemetryClient() diff --git a/libraries/botbuilder-ai/setup.py b/libraries/botbuilder-ai/setup.py index 105f1a4c9..2242efed9 100644 --- a/libraries/botbuilder-ai/setup.py +++ b/libraries/botbuilder-ai/setup.py @@ -8,7 +8,7 @@ "azure-cognitiveservices-language-luis==0.2.0", "botbuilder-schema==4.17.0", "botbuilder-core==4.17.0", - "aiohttp==3.9.5", + "aiohttp==3.10.2", ] TESTS_REQUIRES = ["aiounittest>=1.1.0"] diff --git a/libraries/botbuilder-ai/tests/qna/test_qna.py b/libraries/botbuilder-ai/tests/qna/test_qna.py index 236594ac0..65a9a178a 100644 --- a/libraries/botbuilder-ai/tests/qna/test_qna.py +++ b/libraries/botbuilder-ai/tests/qna/test_qna.py @@ -347,7 +347,6 @@ async def test_trace_test(self): self._knowledge_base_id, trace_activity.value.knowledge_base_id ) - return result async def test_returns_answer_with_timeout(self): question: str = "how do I clean the stove?" @@ -823,7 +822,7 @@ async def test_call_train(self): QnAMaker, "call_train", return_value=None ) as mocked_call_train: qna = QnAMaker(QnaApplicationTest.tests_endpoint) - qna.call_train(feedback_records) + await qna.call_train(feedback_records) mocked_call_train.assert_called_once_with(feedback_records) diff --git a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/processor/telemetry_processor.py b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/processor/telemetry_processor.py index dfe451e3f..0802f3cdf 100644 --- a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/processor/telemetry_processor.py +++ b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/processor/telemetry_processor.py @@ -3,7 +3,7 @@ import base64 import json from abc import ABC, abstractmethod -from _sha256 import sha256 +from hashlib import sha256 class TelemetryProcessor(ABC): diff --git a/libraries/botbuilder-applicationinsights/setup.py b/libraries/botbuilder-applicationinsights/setup.py index 0932ff98f..9573e27f2 100644 --- a/libraries/botbuilder-applicationinsights/setup.py +++ b/libraries/botbuilder-applicationinsights/setup.py @@ -12,7 +12,7 @@ ] TESTS_REQUIRES = [ "aiounittest==1.3.0", - "django==3.2.24", # For samples + "django==4.2.15", # For samples "djangorestframework==3.14.0", # For samples "flask==2.2.5", # For samples ] diff --git a/libraries/botbuilder-core/botbuilder/core/adapters/test_adapter.py b/libraries/botbuilder-core/botbuilder/core/adapters/test_adapter.py index 77f566625..ebfeb303a 100644 --- a/libraries/botbuilder-core/botbuilder/core/adapters/test_adapter.py +++ b/libraries/botbuilder-core/botbuilder/core/adapters/test_adapter.py @@ -8,7 +8,7 @@ import asyncio import inspect import uuid -from datetime import datetime +from datetime import datetime, timezone from uuid import uuid4 from typing import Awaitable, Coroutine, Dict, List, Callable, Union from copy import copy @@ -155,7 +155,7 @@ async def process_activity( finally: self._conversation_lock.release() - activity.timestamp = activity.timestamp or datetime.utcnow() + activity.timestamp = activity.timestamp or datetime.now(timezone.utc) await self.run_pipeline(self.create_turn_context(activity), logic) async def send_activities( diff --git a/libraries/botbuilder-core/botbuilder/core/inspection/trace_activity.py b/libraries/botbuilder-core/botbuilder/core/inspection/trace_activity.py index 307ef64cd..37cb33151 100644 --- a/libraries/botbuilder-core/botbuilder/core/inspection/trace_activity.py +++ b/libraries/botbuilder-core/botbuilder/core/inspection/trace_activity.py @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -from datetime import datetime +from datetime import datetime, timezone from typing import Dict, Union from botbuilder.core import BotState @@ -11,7 +11,7 @@ def make_command_activity(command: str) -> Activity: return Activity( type=ActivityTypes.trace, - timestamp=datetime.utcnow(), + timestamp=datetime.now(timezone.utc), name="Command", label="Command", value=command, @@ -22,7 +22,7 @@ def make_command_activity(command: str) -> Activity: def from_activity(activity: Activity, name: str, label: str) -> Activity: return Activity( type=ActivityTypes.trace, - timestamp=datetime.utcnow(), + timestamp=datetime.now(timezone.utc), name=name, label=label, value=activity, @@ -33,7 +33,7 @@ def from_activity(activity: Activity, name: str, label: str) -> Activity: def from_state(bot_state: Union[BotState, Dict]) -> Activity: return Activity( type=ActivityTypes.trace, - timestamp=datetime.utcnow(), + timestamp=datetime.now(timezone.utc), name="Bot State", label="BotState", value=bot_state, diff --git a/libraries/botbuilder-core/botbuilder/core/transcript_logger.py b/libraries/botbuilder-core/botbuilder/core/transcript_logger.py index e9536c1b6..5aa1ea726 100644 --- a/libraries/botbuilder-core/botbuilder/core/transcript_logger.py +++ b/libraries/botbuilder-core/botbuilder/core/transcript_logger.py @@ -2,7 +2,7 @@ # Licensed under the MIT License. """Logs incoming and outgoing activities to a TranscriptStore..""" -import datetime +from datetime import datetime, timezone import copy import random import string @@ -86,11 +86,11 @@ async def send_activities_handler( prefix = "g_" + "".join( random.choice(alphanumeric) for i in range(5) ) - epoch = datetime.datetime.utcfromtimestamp(0) + epoch = datetime.fromtimestamp(0, timezone.utc) if cloned_activity.timestamp: reference = cloned_activity.timestamp else: - reference = datetime.datetime.today() + reference = datetime.now(timezone.utc) delta = (reference - epoch).total_seconds() * 1000 cloned_activity.id = f"{prefix}{delta}" await self.log_activity(transcript, cloned_activity) diff --git a/libraries/botbuilder-core/botbuilder/core/turn_context.py b/libraries/botbuilder-core/botbuilder/core/turn_context.py index 90ab99bd0..6c4a4eef3 100644 --- a/libraries/botbuilder-core/botbuilder/core/turn_context.py +++ b/libraries/botbuilder-core/botbuilder/core/turn_context.py @@ -3,7 +3,7 @@ import re from copy import copy, deepcopy -from datetime import datetime +from datetime import datetime, timezone from typing import List, Callable, Union, Dict from botframework.connector import Channels from botbuilder.schema import ( @@ -308,7 +308,7 @@ async def send_trace_activity( ) -> ResourceResponse: trace_activity = Activity( type=ActivityTypes.trace, - timestamp=datetime.utcnow(), + timestamp=datetime.now(timezone.utc), name=name, value=value, value_type=value_type, diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py index c5b066913..eb8bf17dc 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py @@ -420,7 +420,7 @@ async def _recognize_token( ) elif OAuthPrompt._is_teams_verification_invoke(context): - code = context.activity.value["state"] + code = context.activity.value.get("state", None) if context.activity.value else None try: token = await _UserTokenAccess.get_user_token( context, self._settings, code diff --git a/libraries/botbuilder-integration-aiohttp/setup.py b/libraries/botbuilder-integration-aiohttp/setup.py index 891647bb7..a777d50c9 100644 --- a/libraries/botbuilder-integration-aiohttp/setup.py +++ b/libraries/botbuilder-integration-aiohttp/setup.py @@ -10,7 +10,7 @@ "botframework-connector==4.17.0", "botbuilder-core==4.17.0", "yarl>=1.8.1", - "aiohttp==3.9.5", + "aiohttp==3.10.2", ] root = os.path.abspath(os.path.dirname(__file__)) diff --git a/libraries/botbuilder-integration-applicationinsights-aiohttp/setup.py b/libraries/botbuilder-integration-applicationinsights-aiohttp/setup.py index d40487403..d8b0f09cf 100644 --- a/libraries/botbuilder-integration-applicationinsights-aiohttp/setup.py +++ b/libraries/botbuilder-integration-applicationinsights-aiohttp/setup.py @@ -6,7 +6,7 @@ REQUIRES = [ "applicationinsights>=0.11.9", - "aiohttp==3.9.5", + "aiohttp==3.10.2", "botbuilder-schema==4.17.0", "botframework-connector==4.17.0", "botbuilder-core==4.17.0", diff --git a/libraries/botbuilder-schema/botbuilder/schema/_models_py3.py b/libraries/botbuilder-schema/botbuilder/schema/_models_py3.py index b75cc9f82..713e07417 100644 --- a/libraries/botbuilder-schema/botbuilder/schema/_models_py3.py +++ b/libraries/botbuilder-schema/botbuilder/schema/_models_py3.py @@ -4,7 +4,7 @@ from typing import List from botbuilder.schema._connector_client_enums import ActivityTypes -from datetime import datetime +from datetime import datetime, timezone from enum import Enum from msrest.serialization import Model from msrest.exceptions import HttpOperationError @@ -630,7 +630,7 @@ def create_reply(self, text: str = None, locale: str = None): """ return Activity( type=ActivityTypes.message, - timestamp=datetime.utcnow(), + timestamp=datetime.now(timezone.utc), from_property=ChannelAccount( id=self.recipient.id if self.recipient else None, name=self.recipient.name if self.recipient else None, @@ -677,7 +677,7 @@ def create_trace( return Activity( type=ActivityTypes.trace, - timestamp=datetime.utcnow(), + timestamp=datetime.now(timezone.utc), from_property=ChannelAccount( id=self.recipient.id if self.recipient else None, name=self.recipient.name if self.recipient else None, diff --git a/libraries/botframework-connector/tests/requirements.txt b/libraries/botframework-connector/tests/requirements.txt index d6c057b7e..5f0d9558d 100644 --- a/libraries/botframework-connector/tests/requirements.txt +++ b/libraries/botframework-connector/tests/requirements.txt @@ -1,5 +1,6 @@ pytest-cov>=2.6.0 pytest~=7.3.1 pyyaml==6.0.1 -pytest-asyncio==0.15.1 -ddt==1.2.1 \ No newline at end of file +pytest-asyncio==0.23.8 +ddt==1.2.1 +setuptools==72.1.0 \ No newline at end of file diff --git a/libraries/botframework-connector/tests/test_attachments.py b/libraries/botframework-connector/tests/test_attachments.py index b6d171250..a4b8b36b8 100644 --- a/libraries/botframework-connector/tests/test_attachments.py +++ b/libraries/botframework-connector/tests/test_attachments.py @@ -46,7 +46,15 @@ def read_base64(path_to_file): return encoded_string -LOOP = asyncio.get_event_loop() +# Ensure there's an event loop and get the auth token +# LOOP = asyncio.get_event_loop() +try: + LOOP = asyncio.get_running_loop() +except RuntimeError: + LOOP = asyncio.new_event_loop() + asyncio.set_event_loop(LOOP) + +# Run the async function to get the auth token AUTH_TOKEN = LOOP.run_until_complete(get_auth_token()) From 2ed714b7521bbe85a5ec6b5d994366b987d69340 Mon Sep 17 00:00:00 2001 From: Ganapathi Diddi Date: Mon, 26 Aug 2024 22:20:23 +0530 Subject: [PATCH 2/3] Fix black issues --- libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py | 6 ++++-- libraries/botbuilder-ai/tests/qna/test_qna.py | 1 - .../botbuilder/dialogs/prompts/oauth_prompt.py | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py b/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py index 657a6e5ba..773c487e6 100644 --- a/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py +++ b/libraries/botbuilder-ai/botbuilder/ai/qna/qnamaker.py @@ -58,9 +58,11 @@ def __init__( except RuntimeError: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - + instance_timeout = ClientTimeout(total=opt.timeout / 1000) - self._http_client = http_client or ClientSession(timeout=instance_timeout, loop=loop) + self._http_client = http_client or ClientSession( + timeout=instance_timeout, loop=loop + ) self.telemetry_client: Union[BotTelemetryClient, NullTelemetryClient] = ( telemetry_client or NullTelemetryClient() diff --git a/libraries/botbuilder-ai/tests/qna/test_qna.py b/libraries/botbuilder-ai/tests/qna/test_qna.py index 65a9a178a..8a3f595ed 100644 --- a/libraries/botbuilder-ai/tests/qna/test_qna.py +++ b/libraries/botbuilder-ai/tests/qna/test_qna.py @@ -347,7 +347,6 @@ async def test_trace_test(self): self._knowledge_base_id, trace_activity.value.knowledge_base_id ) - async def test_returns_answer_with_timeout(self): question: str = "how do I clean the stove?" options = QnAMakerOptions(timeout=999999) diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py index eb8bf17dc..d31a0b56a 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/oauth_prompt.py @@ -420,7 +420,11 @@ async def _recognize_token( ) elif OAuthPrompt._is_teams_verification_invoke(context): - code = context.activity.value.get("state", None) if context.activity.value else None + code = ( + context.activity.value.get("state", None) + if context.activity.value + else None + ) try: token = await _UserTokenAccess.get_user_token( context, self._settings, code From 4df7c098f053c2cef83c55e5bb0cf6db6e5408e5 Mon Sep 17 00:00:00 2001 From: Ganapathi Diddi Date: Wed, 4 Sep 2024 16:28:01 +0530 Subject: [PATCH 3/3] Fixing pylint issue --- libraries/botframework-connector/azure_bdist_wheel.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/botframework-connector/azure_bdist_wheel.py b/libraries/botframework-connector/azure_bdist_wheel.py index d33af36bd..56a1b0b20 100644 --- a/libraries/botframework-connector/azure_bdist_wheel.py +++ b/libraries/botframework-connector/azure_bdist_wheel.py @@ -555,9 +555,7 @@ def write_record(self, bdist_dir, distinfo_dir): for azure_sub_package in folder_with_init: init_file = os.path.join(bdist_dir, azure_sub_package, "__init__.py") if os.path.isfile(init_file): - logger.info( - "manually remove {} while building the wheel".format(init_file) - ) + logger.info("manually remove %s while building the wheel", init_file) os.remove(init_file) else: raise ValueError(