From 3284767eabf176895a439a6ed548993404f6994f Mon Sep 17 00:00:00 2001 From: Albert Garde Date: Fri, 27 Sep 2024 10:16:04 +0200 Subject: [PATCH 1/7] :wrench: Add strict `mypy.ini` --- .pre-commit-config.yaml | 5 ++++- eadk_discord/bot_setup.py | 5 +---- eadk_discord/history.py | 4 ++-- mypy.ini | 7 +++++++ requirements_dev.txt | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 mypy.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c42dcf1..a3c5add 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,4 +43,7 @@ repos: rev: v1.11.2 hooks: - id: mypy - additional_dependencies: [types-python-dateutil~=2.9.0] + additional_dependencies: + - types-python-dateutil~=2.9.0 + - discord.py~=2.4.0 + - pydantic~=2.9.1 diff --git a/eadk_discord/bot_setup.py b/eadk_discord/bot_setup.py index 8d293f9..ec9ca98 100644 --- a/eadk_discord/bot_setup.py +++ b/eadk_discord/bot_setup.py @@ -54,9 +54,6 @@ async def handle_date( ) return None booking_day, _ = database.day(booking_date) - if booking_day is None: - await interaction.response.send_message(f"Date {format_date(booking_date)} is too far in the future.") - return None return booking_date, booking_day @@ -376,7 +373,7 @@ async def syncglobal(ctx: Context) -> None: logging.info(f"Synced {synced_commands} commands globally") @bot.event - async def on_ready(): + async def on_ready() -> None: logging.info(f"We have logged in as {bot.user}") @bot.tree.error diff --git a/eadk_discord/history.py b/eadk_discord/history.py index e86d259..5f88ba1 100644 --- a/eadk_discord/history.py +++ b/eadk_discord/history.py @@ -14,7 +14,7 @@ class History(BaseModel): def initialize(start_date: Date) -> "History": return History(start_date=start_date, history=[]) - def to_dict(self) -> dict[Any, Any]: + def to_dict(self) -> dict[str, Any]: return self.model_dump() def to_json(self) -> str: @@ -28,5 +28,5 @@ def from_json(data: str) -> "History": def from_dict(data: dict[Any, Any]) -> "History": return History.model_validate(data) - def append(self, event: Event): + def append(self, event: Event) -> None: self.history.append(event) diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..ba1fe38 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,7 @@ +[mypy] +warn_unused_configs = True +disallow_untyped_defs = True +warn_redundant_casts = True +warn_unused_ignores = True +warn_return_any = True +warn_unreachable = True diff --git a/requirements_dev.txt b/requirements_dev.txt index 37dd257..cc4bc06 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,3 +1,4 @@ ruff ~= 0.6.5 mypy ~= 1.11.2 pre-commit ~= 3.9.0 +types-python-dateutil~=2.9.0 From 2cda426ed5f4710d440042fc47c0f0a9db05f9e5 Mon Sep 17 00:00:00 2001 From: Albert Garde Date: Fri, 27 Sep 2024 10:36:23 +0200 Subject: [PATCH 2/7] :poop: Add ci-test branch to workflow --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1313540 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +--- +name: CI +on: + push: + branches: + - main + pull_request: + branches: + - main + - ci-test + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: CRLF endings + uses: erclu/check-crlf@v1 + + - name: Find trailing whitespace + uses: harupy/find-trailing-whitespace@v1.0 + + - name: Validate YAML files + run: yamllint . + + - name: Ruff + uses: chartboost/ruff-action@v1 + with: + src: mechint + + - name: Mypy + uses: jashparekh/mypy-action@v2 + with: + mypy_version: 1.11.2 + requirement_files: requirements.txt requirements_dev.txt + python_version: '3.12' From 4f4ef483df3c91644e26e2231c463188cbb90435 Mon Sep 17 00:00:00 2001 From: Albert Garde Date: Fri, 27 Sep 2024 10:52:29 +0200 Subject: [PATCH 3/7] :bug: Fix package name in workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1313540..f309de0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - name: Ruff uses: chartboost/ruff-action@v1 with: - src: mechint + src: eadk_discord - name: Mypy uses: jashparekh/mypy-action@v2 From 7912aeb792739007cf13a98909e3f28130c29dee Mon Sep 17 00:00:00 2001 From: Albert Garde Date: Fri, 27 Sep 2024 10:55:26 +0200 Subject: [PATCH 4/7] :bug: Fix dependencies --- requirements.txt | 1 - requirements_dev.txt | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index ab5ae74..d25fce8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ discord.py ~= 2.4.0 pydantic ~= 2.9.1 -aiocron == 1.8 beartype ~= 0.18.5 diff --git a/requirements_dev.txt b/requirements_dev.txt index cc4bc06..0127a35 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,3 @@ ruff ~= 0.6.5 mypy ~= 1.11.2 -pre-commit ~= 3.9.0 -types-python-dateutil~=2.9.0 +pre-commit ~= 3.8.0 From e3e4d4b11727702a2731d5180f07dc2ae746e1b4 Mon Sep 17 00:00:00 2001 From: Albert Garde Date: Fri, 27 Sep 2024 11:14:34 +0200 Subject: [PATCH 5/7] :construction_worker: Add yamllint to pre-commit --- .pre-commit-config.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a3c5add..ae6a809 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,6 +23,12 @@ repos: hooks: - id: yamlfmt + - repo: https://github.com/adrienverge/yamllint + rev: v1.35.1 + hooks: + - id: yamllint + args: [--strict] + - repo: https://github.com/codespell-project/codespell rev: v2.3.0 hooks: @@ -31,12 +37,12 @@ repos: - tomli - repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. + # Ruff version. rev: v0.1.13 hooks: - # Run the linter. + # Run the linter. - id: ruff - # Run the formatter. + # Run the formatter. - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy From cefa7d8552f7831d67625ddee6d96998fa3c8b2c Mon Sep 17 00:00:00 2001 From: Albert Garde Date: Fri, 27 Sep 2024 11:23:26 +0200 Subject: [PATCH 6/7] :rotating_light: Fix config formatting --- .github/workflows/ci.yml | 2 +- pyproject.toml | 33 ++++++++++++++++----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f309de0..684119d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ --- name: CI -on: +on: # yamllint disable-line rule:truthy push: branches: - main diff --git a/pyproject.toml b/pyproject.toml index 4b5cf72..0624c2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,34 +1,33 @@ [build-system] -requires = ["setuptools", "setuptools-scm"] build-backend = "setuptools.build_meta" +requires = ["setuptools", "setuptools-scm"] [project] -name = "eadk_discord" -version = "0.0.1" +authors = [{name = "albertsgarde", email = "albertsgarde@gmail.com"}] description = "A Discord bot the EADK discord server" -authors = [{ name = "albertsgarde", email = "albertsgarde@gmail.com" }] -license = { file = "LICENSE" } +dynamic = ["dependencies", "optional-dependencies"] +license = {file = "LICENSE"} +name = "eadk_discord" readme = "README.md" requires-python = ">=3.11" -dynamic = ["dependencies", "optional-dependencies"] - -[tool.setuptools] -packages = ["eadk_discord"] - -[tool.setuptools.dynamic] -dependencies = { file = ["requirements.txt"] } - -[tool.setuptools.dynamic.optional-dependencies] -dev = { file = ['requirements_dev.txt'] } +version = "0.0.1" [tool.pytest.ini_options] pythonpath = ["eadk_discord"] - [tool.ruff] line-length = 120 [tool.ruff.lint] -select = ["I", "E", "F", "W", "N", "B"] ignore = ["D203", "D213", "F722"] +select = ["I", "E", "F", "W", "N", "B"] isort.known-first-party = ["eadk_discord"] + +[tool.setuptools] +packages = ["eadk_discord"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} + +[tool.setuptools.dynamic.optional-dependencies] +dev = {file = ['requirements_dev.txt']} From 63278e3851374f178b8148658429f09f6e05f942 Mon Sep 17 00:00:00 2001 From: Albert Garde Date: Fri, 27 Sep 2024 11:24:08 +0200 Subject: [PATCH 7/7] :construction_worker: Make CI yamllint strict --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 684119d..3cb025c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: uses: harupy/find-trailing-whitespace@v1.0 - name: Validate YAML files - run: yamllint . + run: yamllint . --strict - name: Ruff uses: chartboost/ruff-action@v1