Skip to content

Commit

Permalink
Remove pkg_resources and replaced with packaging, updated requirement…
Browse files Browse the repository at this point in the history
…s.txt

(cherry picked from commit 5482e94)
Signed-off-by: Khakers <22665282+khakers@users.noreply.github.com>
  • Loading branch information
Taaku18 authored and khakers committed Jun 18, 2024
1 parent cc436b7 commit 3ee6041
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from discord.ext.commands import MemberConverter
from discord.ext.commands.view import StringView
from emoji import UNICODE_EMOJI
from pkg_resources import parse_version
from packaging.version import Version

from core.blocklist import Blocklist, BlockReason

Expand Down Expand Up @@ -190,7 +190,7 @@ async def load_extensions(self):

@property
def version(self):
return parse_version(__version__)
return Version(__version__)

@property
def api(self) -> ApiClient:
Expand Down Expand Up @@ -1588,7 +1588,7 @@ async def autoupdate(self):
changelog = await Changelog.from_url(self)
latest = changelog.latest_version

if self.version < parse_version(latest.version):
if self.version < Version(latest.version):
error = None
data = {}
try:
Expand Down
6 changes: 3 additions & 3 deletions cogs/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import discord
from discord.ext import commands
from pkg_resources import parse_version
from packaging.version import Version

from core import checks
from core.models import PermissionLevel, getLogger
Expand Down Expand Up @@ -299,7 +299,7 @@ async def parse_user_input(self, ctx, plugin_name, check_version=False):
if check_version:
required_version = details.get("bot_version", False)

if required_version and self.bot.version < parse_version(required_version):
if required_version and self.bot.version < Version(required_version):
embed = discord.Embed(
description="Your bot's version is too low. "
f"This plugin requires version `{required_version}`.",
Expand Down Expand Up @@ -687,7 +687,7 @@ async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = N
embed.set_footer(text="This plugin is currently loaded.")
else:
required_version = details.get("bot_version", False)
if required_version and self.bot.version < parse_version(required_version):
if required_version and self.bot.version < Version(required_version):
embed.set_footer(
text="Your bot is unable to install this plugin, "
f"minimum required version is v{required_version}."
Expand Down
11 changes: 6 additions & 5 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
from typing import Union

import discord
from aiohttp import ClientResponseError
from discord.enums import ActivityType, Status
from discord.ext import commands, tasks
from discord.ext.commands.view import StringView
from pkg_resources import parse_version

from aiohttp import ClientResponseError
from packaging.version import Version

from core import checks, migrations, utils
from core.changelog import Changelog
Expand Down Expand Up @@ -351,9 +352,9 @@ async def about(self, ctx: commands.Context):
latest = changelog.latest_version

if self.bot.version.is_prerelease:
stable = next(filter(lambda v: not parse_version(v.version).is_prerelease, changelog.versions))
stable = next(filter(lambda v: not Version(v.version).is_prerelease, changelog.versions))
footer = f"You are on the prerelease version • the latest version is v{stable.version}."
elif self.bot.version < parse_version(latest.version):
elif self.bot.version < Version(latest.version):
footer = f"A newer version is available v{latest.version}."
else:
footer = "You are up to date with the latest version."
Expand Down Expand Up @@ -1953,7 +1954,7 @@ async def update(self, ctx, *, flag: str = ""):
"(https://github.com/raidensakura/modmail/blob/stable/bot.py#L1)"
)

if self.bot.version >= parse_version(latest.version) and flag.lower() != "force":
if self.bot.version >= Version(latest.version) and flag.lower() != "force":
embed = discord.Embed(title="Already up to date", description=desc, color=self.bot.main_color)

data = await self.bot.api.get_user_info()
Expand Down
10 changes: 5 additions & 5 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ dependencies = [
"strenum",
"discord-py~=2.3.0",
"setuptools>=69.0.3",
"packaging>=24.1",
]
requires-python = ">=3.10"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ multidict==6.0.4
mypy-extensions==1.0.0
natural==0.2.0
nodeenv==1.8.0
packaging==23.2
packaging==24.1
parsedatetime==2.6
pathspec==0.11.2
platformdirs==3.11.0
Expand Down

0 comments on commit 3ee6041

Please sign in to comment.