diff --git a/bot.py b/bot.py index eea6dac..698989a 100755 --- a/bot.py +++ b/bot.py @@ -11,6 +11,7 @@ import pytz import sentry_sdk +import tornado from client_wrapper import ClientWrapper from constants import ( @@ -131,7 +132,6 @@ def __init__( npm_token, timezone, repos_info, - loop, ): """ Create the slack bot @@ -143,7 +143,6 @@ def __init__( npm_token (str): The NPM token to publish npm packages timezone (tzinfo): The time zone of the team interacting with the bot repos_info (list of RepoInfo): Information about the repositories connected to channels - loop (asyncio.events.AbstractEventLoop): The asyncio event loop """ self.doof_id = doof_id self.slack_access_token = slack_access_token @@ -151,7 +150,6 @@ def __init__( self.npm_token = npm_token self.timezone = timezone self.repos_info = repos_info - self.loop = loop # Keep track of long running or scheduled tasks self.tasks = set() self.doof_boot = now_in_utc() @@ -1038,7 +1036,7 @@ async def start_new_releases(self, command_args): # pylint: disable=too-many-lo title=f"Starting release {version} with these commits", text=release_notes, ) - self.loop.create_task( + asyncio.create_task( self._new_release( repo_info=repo_info, version=version, @@ -1549,7 +1547,7 @@ async def startup(self): if not release_pr: continue - self.loop.create_task( + asyncio.create_task( self.run_release_lifecycle( repo_info=repo_info, manager=None, release_pr=release_pr ) @@ -1640,7 +1638,6 @@ async def async_main(): npm_token=envs["NPM_TOKEN"], timezone=pytz.timezone(envs["TIMEZONE"]), repos_info=repos_info, - loop=asyncio.get_event_loop(), doof_id=doof_id, ) app = make_app(secret=envs["SLACK_SECRET"], bot=bot) @@ -1651,9 +1648,7 @@ async def async_main(): def main(): """main function for bot command""" - loop = asyncio.get_event_loop() - loop.run_until_complete(async_main()) - loop.run_forever() + tornado.ioloop.IOLoop.current().run_sync(async_main) if __name__ == "__main__": diff --git a/bot_local.py b/bot_local.py index 9c1874f..1027fcd 100755 --- a/bot_local.py +++ b/bot_local.py @@ -49,7 +49,6 @@ async def async_main(): timezone=envs["TIMEZONE"], npm_token=envs["NPM_TOKEN"], repos_info=repos_info, - loop=asyncio.get_event_loop(), ) await bot.startup() @@ -63,8 +62,7 @@ async def async_main(): def main(): """Main function""" - loop = asyncio.get_event_loop() - loop.run_until_complete(async_main()) + asyncio.run(async_main()) if __name__ == "__main__": diff --git a/bot_test.py b/bot_test.py index ad4215a..45c542e 100644 --- a/bot_test.py +++ b/bot_test.py @@ -50,7 +50,7 @@ class DoofSpoof(Bot): """Testing bot""" - def __init__(self, *, loop): + def __init__(self): """Since the testing bot isn't contacting slack or github we don't need these tokens here""" super().__init__( doof_id="Doofenshmirtz", @@ -59,7 +59,6 @@ def __init__(self, *, loop): npm_token=NPM_TOKEN, timezone=pytz.timezone("America/New_York"), repos_info=[WEB_TEST_REPO_INFO, LIBRARY_TEST_REPO_INFO], - loop=loop, ) self.slack_users = [] @@ -130,9 +129,9 @@ def sleep_sync_mock(mocker): @pytest.fixture -def doof(event_loop, sleep_sync_mock): # pylint: disable=unused-argument +def doof(sleep_sync_mock): # pylint: disable=unused-argument """Create a Doof""" - yield DoofSpoof(loop=event_loop) + yield DoofSpoof() @pytest.fixture diff --git a/requirements.txt b/requirements.txt index 414cc24..201bd4b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -python-dateutil -pytz -requests -sentry-sdk -tornado -virtualenv -packaging +packaging==25.0 +python-dateutil==2.9.0.post0 +pytz==2025.2 +requests==2.32.5 +sentry-sdk==2.35.1 +tornado==6.5.2 +virtualenv==20.34.0 diff --git a/test_requirements.txt b/test_requirements.txt index 1807841..c059714 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,8 +1,8 @@ black==25.1.0 -codecov -pdbpp -pylint -pytest -pytest-asyncio -pytest-cov -pytest-mock +codecov==2.1.13 +pdbpp==0.11.7 +pylint==3.3.8 +pytest==8.4.1 +pytest-asyncio==1.1.0 +pytest-cov==6.2.1 +pytest-mock==3.14.1 diff --git a/web.py b/web.py index 44fcf91..30b4ab2 100644 --- a/web.py +++ b/web.py @@ -2,6 +2,7 @@ Web server for handling slack webhooks """ +import asyncio import hmac import json @@ -54,7 +55,7 @@ async def post(self, *args, **kwargs): # pylint: disable=unused-argument arguments = json.loads( self.get_argument("payload") ) # pylint: disable=no-value-for-parameter - self.bot.loop.create_task(self.bot.handle_webhook(webhook_dict=arguments)) + asyncio.create_task(self.bot.handle_webhook(webhook_dict=arguments)) await self.finish("") @@ -87,7 +88,7 @@ async def post(self, *args, **kwargs): # pylint: disable=unused-argument await self.finish(challenge) return - self.bot.loop.create_task(self.bot.handle_event(webhook_dict=arguments)) + asyncio.create_task(self.bot.handle_event(webhook_dict=arguments)) await self.finish("") diff --git a/web_test.py b/web_test.py index e425184..c02c480 100644 --- a/web_test.py +++ b/web_test.py @@ -1,6 +1,5 @@ """Tests for the web server""" -import asyncio import json from unittest.mock import patch import urllib.parse @@ -21,8 +20,7 @@ class FinishReleaseTests(AsyncHTTPTestCase): def setUp(self): self.secret = uuid.uuid4().hex - self.loop = asyncio.get_event_loop() - self.doof = DoofSpoof(loop=self.loop) + self.doof = DoofSpoof() self.app = make_app(secret=self.secret, bot=self.doof) super().setUp()