Skip to content

Commit

Permalink
[Tournaments] Check for aiodns presence on load
Browse files Browse the repository at this point in the history
  • Loading branch information
laggron42 committed May 17, 2021
1 parent 25e612c commit 5c6a386
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions tournaments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import aiohttp
import importlib.util

from redbot.core.errors import CogLoadError
Expand Down Expand Up @@ -126,9 +127,38 @@ async def restore_tournaments(bot, cog):
await cog.restore_tournaments()


def check_for_aiodns():
"""
The achallonge library has special behaviour with resolvers
It checks on load if aiodns is available, to determine which resolver to use.
However, aiohttp will return instances of AsyncResolver only if the "aiodns" lib is
available on load, else it will fail.
Basically there's a problem if aiodns is installed with downloader, since aiohttp was
initialized without aiodns, and achallonge believes it was, as long as the lib is importable.
"""
try:
import aiodns

aiohttp.AsyncResolver()
except ImportError:
pass
except RuntimeError as e:
raise CogLoadError(
"There is a problem with the `aiodns` library which cannot properly load. "
"Please do one of the following:\n"
"- Properly install `aiodns` in your environment (use `python3.8 -m pip install "
"aiodns`, __the `[p]pipinstall` command will not work__), then restart the bot\n"
"- Fully uninstall the `aiodns` library (it can be hidden in "
"`redbot/cogs/Downloader/lib/`)"
) from e


async def setup(bot):
init_logger(log, "Tournaments")
n = Tournaments(bot)
check_for_aiodns()
try:
n.data.settings
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion tournaments/tournaments.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(self, bot: Red):
except Exception as e:
log.error("Couldn't load dev env values.", exc_info=e)

__version__ = "1.1.3"
__version__ = "1.1.4"
__author__ = ["retke (El Laggron)", "Wonderfall", "Xyleff"]

@commands.command(hidden=True)
Expand Down

0 comments on commit 5c6a386

Please sign in to comment.