From b81eeebe9e578f03a2b1b2975409a79a479979ee Mon Sep 17 00:00:00 2001 From: Alex Ott <66271487+AlexanderHOtt@users.noreply.github.com> Date: Fri, 30 Dec 2022 04:35:45 -0800 Subject: [PATCH] switch to using pre-commit --- backend/oasst_backend/prompt_repository.py | 9 +--- discord-bot/CONTRIBUTING.md | 10 ++-- discord-bot/bot/bot.py | 1 - .../extensions/{_example.py => EXAMPLES.md} | 12 ++--- discord-bot/bot/extensions/guild_settings.py | 1 - discord-bot/bot/extensions/tasks.py | 3 +- discord-bot/bot/extensions/text_labels.py | 1 - discord-bot/bot/extensions/work.py | 5 +- discord-bot/dev-requirements.txt | 8 ---- discord-bot/flake8-requirements.txt | 26 ---------- discord-bot/noxfile.py | 34 -------------- discord-bot/pyproject.toml | 47 ------------------- 12 files changed, 14 insertions(+), 143 deletions(-) rename discord-bot/bot/extensions/{_example.py => EXAMPLES.md} (98%) delete mode 100644 discord-bot/dev-requirements.txt delete mode 100644 discord-bot/flake8-requirements.txt delete mode 100644 discord-bot/noxfile.py delete mode 100644 discord-bot/pyproject.toml diff --git a/backend/oasst_backend/prompt_repository.py b/backend/oasst_backend/prompt_repository.py index 0a6c193c..13c6cd23 100644 --- a/backend/oasst_backend/prompt_repository.py +++ b/backend/oasst_backend/prompt_repository.py @@ -7,14 +7,7 @@ import oasst_backend.models.db_payload as db_payload from loguru import logger from oasst_backend.exceptions import OasstError, OasstErrorCode from oasst_backend.journal_writer import JournalWriter -from oasst_backend.models import ( - ApiClient, - Person, - Post, - PostReaction, - TextLabels, - WorkPackage, -) +from oasst_backend.models import ApiClient, Person, Post, PostReaction, TextLabels, WorkPackage from oasst_backend.models.payload_column_type import PayloadContainer from oasst_shared.schemas import protocol as protocol_schema from sqlmodel import Session, func diff --git a/discord-bot/CONTRIBUTING.md b/discord-bot/CONTRIBUTING.md index d4d8ad3b..44484354 100644 --- a/discord-bot/CONTRIBUTING.md +++ b/discord-bot/CONTRIBUTING.md @@ -13,12 +13,12 @@ pip install -r requirements.txt python -m bot ``` -To test the bot +Before you push, make sure the `pre-commit` hooks are installed and run successfully. ``` -python -m pip install -r dev-requirements.txt - -nox +pip install pre-commit +pre-commit install +pre-commit run --all-files ``` To test the bot on your own discord server you need to register a discord application at the [Discord Developer Portal](https://discord.com/developers/applications) and get at bot token. @@ -81,7 +81,7 @@ def unload(bot: lightbulb.BotApp): bot.remove_plugin(plugin) ``` -For example commands and listeners, see [here](/discord-bot/bot/extensions/_example.py) +For example commands and listeners, see [EXAMPLES.md](/discord-bot/EXAMPLES.md) ### Docs diff --git a/discord-bot/bot/bot.py b/discord-bot/bot/bot.py index 1f801413..a328300a 100644 --- a/discord-bot/bot/bot.py +++ b/discord-bot/bot/bot.py @@ -4,7 +4,6 @@ import aiosqlite import hikari import lightbulb import miru - from bot.api_client import OasstApiClient from bot.config import Config diff --git a/discord-bot/bot/extensions/_example.py b/discord-bot/bot/extensions/EXAMPLES.md similarity index 98% rename from discord-bot/bot/extensions/_example.py rename to discord-bot/bot/extensions/EXAMPLES.md index 76398881..f031cd72 100644 --- a/discord-bot/bot/extensions/_example.py +++ b/discord-bot/bot/extensions/EXAMPLES.md @@ -1,11 +1,8 @@ -# -*- coding: utf-8 -*- -# TODO: Convert file to markdown -# -*- coding: utf-8 -*- -"""Example plugin for reference. +# `hikari`, `lightbulb`, and `muri` examples -Because this file starts with an `_`, it cannot be loaded by the bot. -To see the example plugin in action, rename this file to `example.py`. -""" +Example plugin for reference. + +````py import asyncio import hikari @@ -411,3 +408,4 @@ def load(bot: lightbulb.BotApp): def unload(bot: lightbulb.BotApp): """Remove the plugin to the bot.""" bot.remove_plugin(plugin) +```` diff --git a/discord-bot/bot/extensions/guild_settings.py b/discord-bot/bot/extensions/guild_settings.py index 8c9cded4..5623cd5a 100644 --- a/discord-bot/bot/extensions/guild_settings.py +++ b/discord-bot/bot/extensions/guild_settings.py @@ -3,7 +3,6 @@ import hikari import lightbulb from aiosqlite import Connection - from bot.db.schemas import GuildSettings from bot.utils import mention diff --git a/discord-bot/bot/extensions/tasks.py b/discord-bot/bot/extensions/tasks.py index 71f47f52..70fa5257 100644 --- a/discord-bot/bot/extensions/tasks.py +++ b/discord-bot/bot/extensions/tasks.py @@ -9,9 +9,8 @@ import hikari import lightbulb import lightbulb.decorators import miru -from oasst_shared.schemas.protocol import TaskRequestType - from bot.utils import format_time +from oasst_shared.schemas.protocol import TaskRequestType plugin = lightbulb.Plugin("TaskPlugin") diff --git a/discord-bot/bot/extensions/text_labels.py b/discord-bot/bot/extensions/text_labels.py index 48e32763..1f278ca4 100644 --- a/discord-bot/bot/extensions/text_labels.py +++ b/discord-bot/bot/extensions/text_labels.py @@ -7,7 +7,6 @@ import hikari import lightbulb import miru from aiosqlite import Connection - from bot.db.schemas import GuildSettings from bot.utils import EMPTY diff --git a/discord-bot/bot/extensions/work.py b/discord-bot/bot/extensions/work.py index ecbe1710..ba71f41b 100644 --- a/discord-bot/bot/extensions/work.py +++ b/discord-bot/bot/extensions/work.py @@ -10,12 +10,11 @@ import lightbulb import lightbulb.decorators import miru from aiosqlite import Connection -from oasst_shared.schemas import protocol as protocol_schema -from oasst_shared.schemas.protocol import TaskRequestType - from bot.api_client import OasstApiClient, TaskType from bot.db.schemas import GuildSettings from bot.utils import EMPTY +from oasst_shared.schemas import protocol as protocol_schema +from oasst_shared.schemas.protocol import TaskRequestType plugin = lightbulb.Plugin("WorkPlugin") diff --git a/discord-bot/dev-requirements.txt b/discord-bot/dev-requirements.txt deleted file mode 100644 index 56393fdd..00000000 --- a/discord-bot/dev-requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ - -black - -codespell -flake8 -isort -nox -pyright diff --git a/discord-bot/flake8-requirements.txt b/discord-bot/flake8-requirements.txt deleted file mode 100644 index a022d8c5..00000000 --- a/discord-bot/flake8-requirements.txt +++ /dev/null @@ -1,26 +0,0 @@ -flake8==6.0.0 -flake8-bandit # runs bandit -flake8-black # runs black -# flake8-broken-line # forbey "\" linebreaks -flake8-builtins # builtin shadowing checks -flake8-coding # coding magic-comment detection -flake8-comprehensions # comprehension checks -flake8-deprecated # deprecated call checks -flake8-docstrings # pydocstyle support -flake8-executable # shebangs -flake8-fixme # "fix me" counter -flake8-functions # function linting -flake8-html # html output -flake8-if-statements # condition linting -flake8-isort # runs isort -flake8-mutable # mutable default argument detection -flake8-pep3101 # new-style format strings only -flake8-print # complain about print statements in code -flake8-printf-formatting # forbey printf-style python2 string formatting - -# Plugins - -Flake8-pyproject # use the pyproject.toml as the config file -flake8-pytest-style # pytest checks -flake8-raise # exception raising linting -flake8-use-fstring # format string checking diff --git a/discord-bot/noxfile.py b/discord-bot/noxfile.py deleted file mode 100644 index 891e87fb..00000000 --- a/discord-bot/noxfile.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -"""Automated linting, formatting, and typechecking.""" -import nox -from nox.sessions import Session - - -@nox.session(reuse_venv=True) -def format_code(session: Session): - """Format the codebase.""" - session.install("isort", "-U") - session.install("black", "-U") - - session.run("isort", "bot") - session.run("black", "bot") - - -@nox.session(reuse_venv=True) -def lint_code(session: Session): - """Lint the codebase.""" - session.install("codespell", "-U") - session.install("flake8", "-U") - session.install("-r", "flake8-requirements.txt", "-U") - - session.run("codespell", "bot") - session.run("flake8", "bot") - - -@nox.session(reuse_venv=True) -def typecheck_code(session: Session): - """Typecheck the codebase.""" - session.install("-r", "requirements.txt", "-U") - session.install("pyright", "-U") - - session.run("pyright", "bot") diff --git a/discord-bot/pyproject.toml b/discord-bot/pyproject.toml deleted file mode 100644 index 7a1e8d82..00000000 --- a/discord-bot/pyproject.toml +++ /dev/null @@ -1,47 +0,0 @@ -[project] -name = "Open-Assistant Discord Bot" -version = "0.0.1" - -[tool.black] -line-length = 120 -target-version = ["py310"] - -[tool.pyright] -include = ["ottbot", "noxfile.py"] -pythonVersion="3.10" -reportMissingImports=false -# reportInvalidTypeVarUse=false -# reportMissingModuleSource=false -reportUnknownVariableType=false -pythonPlatform="Linux" - -[tool.isort] -profile="black" -sections = ['FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER'] -skip_glob = "**/__init__.pyi" - -[tool.flake8] -max-function-length = 130 -max-line-length = 130 -# Technically this is 120, but black has a policy of "1 or 2 over is fine if it is tidier", so we have to raise this. -accept-encodings = "utf-8" -docstring-convention = "numpy" -ignore = [ - "A002", # Argument is shadowing a python builtin. - "A003", # Class attribute is shadowing a python builtin. - "CFQ002", # Function has too many arguments. - "CFQ004", # Function has too many returns. - "D001", # False positive for depreciated functions. - "D102", # Missing docstring in public method. - "D105", # Magic methods not having a docstring. - "D412", # No blank lines allowed between a section header and its content - "E203", # Whitespace after : (to match how black formats it) - "E402", # Module level import not at top of file (isn't compatible with our import style). - "T101", # TO-DO comment detection (T102 is FIX-ME and T103 is XXX). - "W503", # line break before binary operator. - "W504", # line break before binary operator (again, I guess). - "S101", # Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. - "S105", # Possible hardcoded password. - "EXE002", # Executable file with not shebang - "D401", # Imperative mood -]