From 6cd48f5eb0ac3b1dcd2838431410e90f9a41e560 Mon Sep 17 00:00:00 2001 From: Nathaniel Landau Date: Mon, 2 Oct 2023 13:57:29 -0400 Subject: [PATCH] ci: automate tests with python 3.12 (#77) * ci: automate tests with python 3.12 * build: remove depreciated update script * build(deps): update ruff --- .github/workflows/automated-tests.yml | 2 +- .pre-commit-config.yaml | 2 +- poetry.lock | 52 ++++---- pyproject.toml | 6 +- scripts/update_dependencies.py | 150 ------------------------ src/valentina/cogs/admin.py | 6 +- src/valentina/models/statistics.py | 6 +- src/valentina/utils/changelog_parser.py | 2 +- src/valentina/views/roll_display.py | 4 +- 9 files changed, 40 insertions(+), 190 deletions(-) delete mode 100755 scripts/update_dependencies.py diff --git a/.github/workflows/automated-tests.yml b/.github/workflows/automated-tests.yml index d156bfdf..7650971e 100644 --- a/.github/workflows/automated-tests.yml +++ b/.github/workflows/automated-tests.yml @@ -38,7 +38,7 @@ jobs: strategy: fail-fast: true matrix: - python-version: ["3.11"] + python-version: ["3.11", "3.12"] steps: - name: Harden Security Runner uses: step-security/harden-runner@v2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 596f7f24..8a6b7d6a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -59,7 +59,7 @@ repos: entry: yamllint --strict --config-file .yamllint.yml - repo: "https://github.com/charliermarsh/ruff-pre-commit" - rev: "v0.0.291" + rev: "v0.0.292" hooks: - id: ruff args: ["--extend-ignore", "I001,D301,D401", "--preview"] diff --git a/poetry.lock b/poetry.lock index fa622744..6b066213 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1115,13 +1115,13 @@ files = [ [[package]] name = "platformdirs" -version = "3.10.0" +version = "3.11.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." optional = false python-versions = ">=3.7" files = [ - {file = "platformdirs-3.10.0-py3-none-any.whl", hash = "sha256:d7c24979f292f916dc9cbf8648319032f551ea8c49a4c9bf2fb556a02070ec1d"}, - {file = "platformdirs-3.10.0.tar.gz", hash = "sha256:b45696dab2d7cc691a3226759c0d3b00c47c8b6e293d96f6436f733303f77f6d"}, + {file = "platformdirs-3.11.0-py3-none-any.whl", hash = "sha256:e9d171d00af68be50e9202731309c4e658fd8bc76f55c11c7dd760d023bda68e"}, + {file = "platformdirs-3.11.0.tar.gz", hash = "sha256:cf8ee52a3afdb965072dcc652433e0c7e3e40cf5ea1477cd4b3b1d2eb75495b3"}, ] [package.extras] @@ -1603,28 +1603,28 @@ jupyter = ["ipywidgets (>=7.5.1,<9)"] [[package]] name = "ruff" -version = "0.0.291" +version = "0.0.292" description = "An extremely fast Python linter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.0.291-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:b97d0d7c136a85badbc7fd8397fdbb336e9409b01c07027622f28dcd7db366f2"}, - {file = "ruff-0.0.291-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:6ab44ea607967171e18aa5c80335237be12f3a1523375fa0cede83c5cf77feb4"}, - {file = "ruff-0.0.291-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a04b384f2d36f00d5fb55313d52a7d66236531195ef08157a09c4728090f2ef0"}, - {file = "ruff-0.0.291-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:b727c219b43f903875b7503a76c86237a00d1a39579bb3e21ce027eec9534051"}, - {file = "ruff-0.0.291-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:87671e33175ae949702774071b35ed4937da06f11851af75cd087e1b5a488ac4"}, - {file = "ruff-0.0.291-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:b75f5801547f79b7541d72a211949754c21dc0705c70eddf7f21c88a64de8b97"}, - {file = "ruff-0.0.291-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b09b94efdcd162fe32b472b2dd5bf1c969fcc15b8ff52f478b048f41d4590e09"}, - {file = "ruff-0.0.291-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8d5b56bc3a2f83a7a1d7f4447c54d8d3db52021f726fdd55d549ca87bca5d747"}, - {file = "ruff-0.0.291-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:13f0d88e5f367b2dc8c7d90a8afdcfff9dd7d174e324fd3ed8e0b5cb5dc9b7f6"}, - {file = "ruff-0.0.291-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:b3eeee1b1a45a247758ecdc3ab26c307336d157aafc61edb98b825cadb153df3"}, - {file = "ruff-0.0.291-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:6c06006350c3bb689765d71f810128c9cdf4a1121fd01afc655c87bab4fb4f83"}, - {file = "ruff-0.0.291-py3-none-musllinux_1_2_i686.whl", hash = "sha256:fd17220611047de247b635596e3174f3d7f2becf63bd56301fc758778df9b629"}, - {file = "ruff-0.0.291-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5383ba67ad360caf6060d09012f1fb2ab8bd605ab766d10ca4427a28ab106e0b"}, - {file = "ruff-0.0.291-py3-none-win32.whl", hash = "sha256:1d5f0616ae4cdc7a938b493b6a1a71c8a47d0300c0d65f6e41c281c2f7490ad3"}, - {file = "ruff-0.0.291-py3-none-win_amd64.whl", hash = "sha256:8a69bfbde72db8ca1c43ee3570f59daad155196c3fbe357047cd9b77de65f15b"}, - {file = "ruff-0.0.291-py3-none-win_arm64.whl", hash = "sha256:d867384a4615b7f30b223a849b52104214442b5ba79b473d7edd18da3cde22d6"}, - {file = "ruff-0.0.291.tar.gz", hash = "sha256:c61109661dde9db73469d14a82b42a88c7164f731e6a3b0042e71394c1c7ceed"}, + {file = "ruff-0.0.292-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:02f29db018c9d474270c704e6c6b13b18ed0ecac82761e4fcf0faa3728430c96"}, + {file = "ruff-0.0.292-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:69654e564342f507edfa09ee6897883ca76e331d4bbc3676d8a8403838e9fade"}, + {file = "ruff-0.0.292-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6c3c91859a9b845c33778f11902e7b26440d64b9d5110edd4e4fa1726c41e0a4"}, + {file = "ruff-0.0.292-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f4476f1243af2d8c29da5f235c13dca52177117935e1f9393f9d90f9833f69e4"}, + {file = "ruff-0.0.292-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:be8eb50eaf8648070b8e58ece8e69c9322d34afe367eec4210fdee9a555e4ca7"}, + {file = "ruff-0.0.292-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:9889bac18a0c07018aac75ef6c1e6511d8411724d67cb879103b01758e110a81"}, + {file = "ruff-0.0.292-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6bdfabd4334684a4418b99b3118793f2c13bb67bf1540a769d7816410402a205"}, + {file = "ruff-0.0.292-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:aa7c77c53bfcd75dbcd4d1f42d6cabf2485d2e1ee0678da850f08e1ab13081a8"}, + {file = "ruff-0.0.292-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8e087b24d0d849c5c81516ec740bf4fd48bf363cfb104545464e0fca749b6af9"}, + {file = "ruff-0.0.292-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:f160b5ec26be32362d0774964e218f3fcf0a7da299f7e220ef45ae9e3e67101a"}, + {file = "ruff-0.0.292-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:ac153eee6dd4444501c4bb92bff866491d4bfb01ce26dd2fff7ca472c8df9ad0"}, + {file = "ruff-0.0.292-py3-none-musllinux_1_2_i686.whl", hash = "sha256:87616771e72820800b8faea82edd858324b29bb99a920d6aa3d3949dd3f88fb0"}, + {file = "ruff-0.0.292-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:b76deb3bdbea2ef97db286cf953488745dd6424c122d275f05836c53f62d4016"}, + {file = "ruff-0.0.292-py3-none-win32.whl", hash = "sha256:e854b05408f7a8033a027e4b1c7f9889563dd2aca545d13d06711e5c39c3d003"}, + {file = "ruff-0.0.292-py3-none-win_amd64.whl", hash = "sha256:f27282bedfd04d4c3492e5c3398360c9d86a295be00eccc63914438b4ac8a83c"}, + {file = "ruff-0.0.292-py3-none-win_arm64.whl", hash = "sha256:7f67a69c8f12fbc8daf6ae6d36705037bde315abf8b82b6e1f4c9e74eb750f68"}, + {file = "ruff-0.0.292.tar.gz", hash = "sha256:1093449e37dd1e9b813798f6ad70932b57cf614e5c2b5c51005bf67d55db33ac"}, ] [[package]] @@ -1831,17 +1831,17 @@ files = [ [[package]] name = "urllib3" -version = "1.26.16" +version = "1.26.17" description = "HTTP library with thread-safe connection pooling, file post, and more." optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" files = [ - {file = "urllib3-1.26.16-py2.py3-none-any.whl", hash = "sha256:8d36afa7616d8ab714608411b4a3b13e58f463aee519024578e062e141dce20f"}, - {file = "urllib3-1.26.16.tar.gz", hash = "sha256:8f135f6502756bde6b2a9b28989df5fbe87c9970cecaa69041edcce7f0589b14"}, + {file = "urllib3-1.26.17-py2.py3-none-any.whl", hash = "sha256:94a757d178c9be92ef5539b8840d48dc9cf1b2709c9d6b588232a055c524458b"}, + {file = "urllib3-1.26.17.tar.gz", hash = "sha256:24d6a242c28d29af46c3fae832c36db3bbebcc533dd1bb549172cd739c82df21"}, ] [package.extras] -brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] +brotli = ["brotli (==1.0.9)", "brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] @@ -2009,4 +2009,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "c63cb7fc8bcb4d71802db13537ba99d4c2f3cc07d5c5360ffef2651276defec3" +content-hash = "d6750c2d87a289ce2996797857b1b58e57c74b703020ac3853149bead83435b4" diff --git a/pyproject.toml b/pyproject.toml index c5be1dab..ca06e6c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,9 +27,9 @@ py-cord = "^2.4.1" python = "^3.11" python-dotenv = "^1.0.0" + rich = "^13.6.0" semver = "^3.0.1" typer = { extras = ["all"], version = "^0.9.0" } - rich = "^13.6.0" [tool.poetry.group.test.dependencies] dirty-equals = "^0.6.0" @@ -48,7 +48,7 @@ pdoc = "^14.0.0" poethepoet = "^0.22.1" pre-commit = "^3.4.0" - ruff = "^0.0.291" + ruff = "^0.0.292" shellcheck-py = "^0.9.0.5" types-aiofiles = "^23.2.0.0" typos = "^1.16.11" @@ -297,7 +297,7 @@ help = "Lint this package" [[tool.poe.tasks.lint.sequence]] - shell = "ruff --no-fix src/" + shell = "ruff --preview --no-fix src/" [[tool.poe.tasks.lint.sequence]] shell = "black --check src/ tests/" diff --git a/scripts/update_dependencies.py b/scripts/update_dependencies.py deleted file mode 100755 index 479ab902..00000000 --- a/scripts/update_dependencies.py +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/env python -"""Script to update the pyproject.toml file with the latest versions of the dependencies.""" -from pathlib import Path -from textwrap import wrap - -try: - import tomllib -except ModuleNotFoundError: # pragma: no cover - import tomli as tomllib # type: ignore [no-redef] - -import sh -from rich.console import Console - -console = Console() - - -def dryrun(msg: str) -> None: - """Print a message if the dry run flag is set. - - Args: - msg: Message to print - """ - console.print(f"[cyan]DRYRUN | {msg}[/cyan]") - - -def success(msg: str) -> None: - """Print a success message without using logging. - - Args: - msg: Message to print - """ - console.print(f"[green]SUCCESS | {msg}[/green]") - - -def warning(msg: str) -> None: - """Print a warning message without using logging. - - Args: - msg: Message to print - """ - console.print(f"[yellow]WARNING | {msg}[/yellow]") - - -def error(msg: str) -> None: - """Print an error message without using logging. - - Args: - msg: Message to print - """ - console.print(f"[red]ERROR | {msg}[/red]") - - -def notice(msg: str) -> None: - """Print a notice message without using logging. - - Args: - msg: Message to print - """ - console.print(f"[bold]NOTICE | {msg}[/bold]") - - -def info(msg: str) -> None: - """Print a notice message without using logging. - - Args: - msg: Message to print - """ - console.print(f"INFO | {msg}") - - -def usage(msg: str, width: int = 80) -> None: - """Print a usage message without using logging. - - Args: - msg: Message to print - width (optional): Width of the message - """ - for _n, line in enumerate(wrap(msg, width=width)): - if _n == 0: - console.print(f"[dim]USAGE | {line}") - else: - console.print(f"[dim] | {line}") - - -def debug(msg: str) -> None: - """Print a debug message without using logging. - - Args: - msg: Message to print - """ - console.print(f"[blue]DEBUG | {msg}[/blue]") - - -def dim(msg: str) -> None: - """Print a message in dimmed color. - - Args: - msg: Message to print - """ - console.print(f"[dim]{msg}[/dim]") - - -# Load the pyproject.toml file -pyproject = Path(__file__).parents[1] / "pyproject.toml" - -if not pyproject.exists(): - console.print("pyproject.toml file not found") - raise SystemExit(1) - -with pyproject.open("rb") as f: - try: - data = tomllib.load(f) - except tomllib.TOMLDecodeError as e: - raise SystemExit(1) from e - - -# Get the latest versions of all dependencies -info("Getting latest versions of dependencies...") -packages: dict = {} -for line in sh.poetry("--no-ansi", "show", "--outdated").splitlines(): - package, current, latest = line.split()[:3] - packages[package] = {"current_version": current, "new_version": latest} - -if not packages: - success("All dependencies are up to date") - raise SystemExit(0) - - -dependencies = data["tool"]["poetry"]["dependencies"] -groups = data["tool"]["poetry"]["group"] - -for p in dependencies: - if p in packages: - notice( - f"Updating {p} from {packages[p]['current_version']} to {packages[p]['new_version']}" - ) - sh.poetry("add", f"{p}@latest", _fg=True) - - -for group in groups: - for p in groups[group]["dependencies"]: - if p in packages: - notice( - f"Updating {p} from {packages[p]['current_version']} to {packages[p]['new_version']}" - ) - sh.poetry("add", f"{p}@latest", "--group", group, _fg=True) - -sh.poetry("update", _fg=True) -success("All dependencies are up to date") -raise SystemExit(0) diff --git a/src/valentina/cogs/admin.py b/src/valentina/cogs/admin.py index b6c6ce5f..8cf6939d 100644 --- a/src/valentina/cogs/admin.py +++ b/src/valentina/cogs/admin.py @@ -228,7 +228,7 @@ async def massban( return # Confirm the action - title = f"Mass ban {count} {p.plural_noun('member',count)} from this guild" + title = f"Mass ban {count} {p.plural_noun('member', count)} from this guild" is_confirmed, confirmation_response_msg = await confirm_action( ctx, title, description=reason, hidden=hidden ) @@ -604,7 +604,7 @@ async def purge_bot_messages( count = len(await purge(limit=limit, reason=reason, check=lambda m: m.author.bot)) await present_embed( ctx, - title=f"Purged `{count}` bot {p.plural_noun('message',count)} in this channel", + title=f"Purged `{count}` bot {p.plural_noun('message', count)} in this channel", level="warning", ephemeral=True, ) @@ -646,7 +646,7 @@ async def purge_containing( ) await present_embed( ctx, - title=f"Purged `{count}` {p.plural_noun('message',count)} containing `{phrase}` in this channel", + title=f"Purged `{count}` {p.plural_noun('message', count)} containing `{phrase}` in this channel", level="warning", ephemeral=True, ) diff --git a/src/valentina/models/statistics.py b/src/valentina/models/statistics.py index 5523f220..f1c9f94c 100644 --- a/src/valentina/models/statistics.py +++ b/src/valentina/models/statistics.py @@ -120,12 +120,12 @@ def get_text(self, with_title: bool = True, with_help: bool = True) -> str: msg += f"""\ ```python Total Rolls: {'.':.<{25 - 12}} {self.total_rolls} -Critical Success Rolls: {'.':.<{25 -23}} {self.criticals:<3} ({self.criticals / self.total_rolls * 100:.2f}%) +Critical Success Rolls: {'.':.<{25 - 23}} {self.criticals:<3} ({self.criticals / self.total_rolls * 100:.2f}%) Successful Rolls: {'.':.<{25 - 17}} {self.successes:<3} ({self.successes / self.total_rolls * 100:.2f}%) Failed Rolls: {'.':.<{25 - 13}} {self.failures:<3} ({self.failures / self.total_rolls * 100:.2f}%) Botched Rolls: {'.':.<{25 - 14}} {self.botches:<3} ({self.botches / self.total_rolls * 100:.2f}%) -Average Difficulty: {'.':.<{25 -19}} {self.average_difficulty} -Average Pool Size: {'.':.<{25 -18}} {self.average_pool} +Average Difficulty: {'.':.<{25 - 19}} {self.average_difficulty} +Average Pool Size: {'.':.<{25 - 18}} {self.average_pool} ``` """ diff --git a/src/valentina/utils/changelog_parser.py b/src/valentina/utils/changelog_parser.py index bf4f2add..3e0b8f23 100644 --- a/src/valentina/utils/changelog_parser.py +++ b/src/valentina/utils/changelog_parser.py @@ -214,7 +214,7 @@ def get_embed_personality(self) -> discord.Embed: discord.Embed: The changelog embed. """ # Create and populate the embed description - description = f"Valentina, your {random.choice(['honored','admired','distinguished','celebrated','hallowed','prestigious','acclaimed','favorite','friendly neighborhood','prized', 'treasured', 'number one','esteemed','venerated','revered','feared'])} {random.choice(BOT_DESCRIPTIONS)}, has {random.choice(['been granted new powers', 'leveled up','spent experience points','gained new abilities','been bitten by a radioactive spider', 'spent willpower points', 'been updated','squashed bugs and gained new features',])}!\n" + description = f"Valentina, your {random.choice(['honored', 'admired', 'distinguished', 'celebrated', 'hallowed', 'prestigious', 'acclaimed', 'favorite', 'friendly neighborhood', 'prized', 'treasured', 'number one', 'esteemed', 'venerated', 'revered', 'feared'])} {random.choice(BOT_DESCRIPTIONS)}, has {random.choice(['been granted new powers', 'leveled up', 'spent experience points', 'gained new abilities', 'been bitten by a radioactive spider', 'spent willpower points', 'been updated', 'squashed bugs and gained new features',])}!\n" # Loop through each version in the changelog for version, data in self.changelog_dict.items(): diff --git a/src/valentina/views/roll_display.py b/src/valentina/views/roll_display.py index 616d25cb..0cdb2508 100644 --- a/src/valentina/views/roll_display.py +++ b/src/valentina/views/roll_display.py @@ -64,13 +64,13 @@ def _add_trait_fields(self, embed: discord.Embed) -> discord.Embed: if self.trait_one and self.trait_two: embed.add_field( name="**Rolled Traits**", - value=f"{self.trait_one.name}: `{self.trait_one_value} {p.plural_noun('die',self.trait_one_value)}`\n{self.trait_two.name}: `{self.trait_two_value} {p.plural_noun('die',self.trait_two_value)}`", + value=f"{self.trait_one.name}: `{self.trait_one_value} {p.plural_noun('die', self.trait_one_value)}`\n{self.trait_two.name}: `{self.trait_two_value} {p.plural_noun('die', self.trait_two_value)}`", inline=False, ) elif self.trait_one: embed.add_field( name="**Rolled Traits**", - value=f"{self.trait_one.name}: `{self.trait_one_value} {p.plural_noun('die',self.trait_one_value)}`", + value=f"{self.trait_one.name}: `{self.trait_one_value} {p.plural_noun('die', self.trait_one_value)}`", inline=False, )