mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-19 11:20:04 +08:00
switch to using pre-commit
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import aiosqlite
|
||||
import hikari
|
||||
import lightbulb
|
||||
import miru
|
||||
|
||||
from bot.api_client import OasstApiClient
|
||||
from bot.config import Config
|
||||
|
||||
|
||||
@@ -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)
|
||||
````
|
||||
@@ -3,7 +3,6 @@
|
||||
import hikari
|
||||
import lightbulb
|
||||
from aiosqlite import Connection
|
||||
|
||||
from bot.db.schemas import GuildSettings
|
||||
from bot.utils import mention
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
black
|
||||
|
||||
codespell
|
||||
flake8
|
||||
isort
|
||||
nox
|
||||
pyright
|
||||
@@ -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
|
||||
@@ -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")
|
||||
@@ -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
|
||||
]
|
||||
Reference in New Issue
Block a user