Skip to content

Commit

Permalink
Add pre-commit configuration, some new checks and reformat (#50)
Browse files Browse the repository at this point in the history
* Add flake8 configuration

* Add pyproject.toml

* Remove max line length from make files

* Run Black

* Fix End of Files

* Trim trailing whitespace

* Pretty format JSON

* Add pre-commit configuration

* Update the GH Actions workflow to run pre-commit

* Add various Problem Matchers

* Update Flake8 URL to github

* Downgrade formatter version for black's required-version

* fix python-version, update actions, add required-version

* bump version

* reformat!

* fortunately, this will be squashed...

---------

Co-authored-by: jack1142 <[email protected]>
Co-authored-by: Neuro Assassin <[email protected]>
  • Loading branch information
3 people authored Aug 5, 2023
1 parent 75d9c45 commit 6ad4ec4
Show file tree
Hide file tree
Showing 67 changed files with 508 additions and 274 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 99
select = E9,F7,F82
extend-exclude=.venv/,.stubs/
26 changes: 0 additions & 26 deletions .github/workflows/lint_python.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/matchers/check-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"__comment": "Credits to: https://github.com/home-assistant/core/blob/d32c364d7f9e138e0dd9363b34b3cb39f4afcd06/.github/workflows/matchers/check-json.json",
"problemMatcher": [
{
"owner": "check-json",
"pattern": [
{
"regexp": "^(.+):\\s(Failed to json decode\\s.+\\sline\\s(\\d+)\\scolumn\\s(\\d+).+)$",
"file": 1,
"message": 2,
"line": 3,
"column": 4
}
]
}
]
}
16 changes: 16 additions & 0 deletions .github/workflows/matchers/check-toml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "check-toml",
"pattern": [
{
"regexp": "^(.+\\.toml):\\s(.+line\\s(\\d+)\\scolumn\\s(\\d+).+)$",
"file": 1,
"message": 2,
"line": 3,
"column": 4
}
]
}
]
}
19 changes: 19 additions & 0 deletions .github/workflows/matchers/check-yaml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"problemMatcher": [
{
"owner": "check-yaml",
"pattern": [
{
"regexp": "^(.+)$",
"message": 1
},
{
"regexp": "^ in \"(.+\\.ya?ml)\", line (\\d+), column (\\d+)$",
"file": 1,
"line": 2,
"column": 3
}
]
}
]
}
32 changes: 32 additions & 0 deletions .github/workflows/matchers/flake8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"__comment": "Credits to: https://github.com/home-assistant/core/blob/d32c364d7f9e138e0dd9363b34b3cb39f4afcd06/.github/workflows/matchers/flake8.json",
"problemMatcher": [
{
"owner": "flake8-error",
"severity": "error",
"pattern": [
{
"regexp": "^(.+):(\\d+):(\\d+):\\s(([EF]\\d{3})\\s.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
]
},
{
"owner": "flake8-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^(.+):(\\d+):(\\d+):\\s(([CDNW]\\d{3})\\s.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
}
]
}
41 changes: 41 additions & 0 deletions .github/workflows/run_precommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run pre-commit

on: [push, pull_request]

jobs:
run_precommit:
name: Run pre-commit
runs-on: ubuntu-latest

steps:
# Checkout repository
- uses: actions/checkout@v3

# Setup Python and install pre-commit
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install pre-commit
run: |
pip install -U pre-commit
# Load cached pre-commit environment
- name: set PY
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}

# Register problem matchers
- name: Register problem matchers
run: |
echo "::add-matcher::.github/workflows/matchers/check-json.json"
echo "::add-matcher::.github/workflows/matchers/check-toml.json"
echo "::add-matcher::.github/workflows/matchers/check-yaml.json"
echo "::add-matcher::.github/workflows/matchers/flake8.json"
# Run pre-commit
- name: Run pre-commit
run: |
pre-commit run --show-diff-on-failure --color=never --all-files --verbose
17 changes: 0 additions & 17 deletions .github/workflows/style.yaml

This file was deleted.

55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
default_language_version:
python: python3.8
exclude: ^.stubs/
repos:
- repo: https://github.com/psf/black
rev: 'refs/tags/23.7.0:refs/tags/23.7.0'
hooks:
- id: black
- repo: https://github.com/Pierre-Sassoulas/black-disable-checker
rev: 'v1.1.3'
hooks:
- id: black-disable-checker
- repo: https://github.com/pycqa/flake8
rev: '6.1.0'
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
# `.gitattributes` should technically already handle this
# but autocrlf can result in local files keeping the CRLF
# which is problematic for codespell
- id: end-of-file-fixer
# normally you would want this but Neuro is not very consistent :P
# - id: mixed-line-ending
# args:
# - "--fix=lf"

# Trailing whitespace is evil
- id: trailing-whitespace

# Require literal syntax when initializing builtin types
- id: check-builtin-literals

# Ensure that links to code on GitHub use the permalinks
- id: check-vcs-permalinks

# Syntax validation
- id: check-ast
- id: check-json
- id: check-toml
# can be switched to yamllint when this issue gets resolved:
# https://github.com/adrienverge/yamllint/issues/238
- id: check-yaml

# JSON auto-formatter
- id: pretty-format-json
args:
- "--autofix"
- "--indent=4"
- "--no-sort-keys"

# Checks for git-related issues
- id: check-case-conflict
- id: check-merge-conflict
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ PYTHON ?= python3.8

# Python Code Style
reformat:
$(PYTHON) -m black -l 99 .
$(PYTHON) -m black .
stylecheck:
$(PYTHON) -m black --check -l 99 .
$(PYTHON) -m black --check .
stylediff:
$(PYTHON) -m black --check --diff -l 99 .
$(PYTHON) -m black --check --diff .
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ For bugs, contact me at Neuro Assassin#4779 <@473541068378341376>. It would be

[PrettyTable](https://pypi.org/project/PrettyTable/) and [FuzzyWuzzy](https://pypi.org/project/fuzzywuzzy/) are required for the listpermissions cog.

[Back to Table of Contents](#table-of-contents)
[Back to Table of Contents](#table-of-contents)
2 changes: 1 addition & 1 deletion authgg/authgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def authgg(self, ctx):
@authgg.command()
async def resethwid(self, ctx, apikey: str, *, name: Optional[str] = None):
"""Reset a user's HWID lock on auth.gg for the specified API key name.
The API key name must be the friendly name provided by `[p]authgg keys add`."""
if not await self.bot.is_owner(ctx.author):
roles = await self.conf.roles()
Expand Down
2 changes: 1 addition & 1 deletion authgg/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
],
"requirements": [],
"hidden": false
}
}
25 changes: 16 additions & 9 deletions color/info.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"author" : ["Neuro Assassin"],
"install_msg" : "Thank you for downloading this cog. In-message shortcuts are disabled by guild by default. An administrator can change this rule by running `[p]color msgshort true`",
"name" : "color",
"short" : "Tells you the hexadecimal values, rgb values and names of colors",
"description" : "This cog will tell you the hexadecimal value, rgb value and the name of the color that is supplied to it.",
"tags" : ["tools"],
"requirements" : ["colour", "pillow"],
"hidden" : false
}
"author": [
"Neuro Assassin"
],
"install_msg": "Thank you for downloading this cog. In-message shortcuts are disabled by guild by default. An administrator can change this rule by running `[p]color msgshort true`",
"name": "color",
"short": "Tells you the hexadecimal values, rgb values and names of colors",
"description": "This cog will tell you the hexadecimal value, rgb value and the name of the color that is supplied to it.",
"tags": [
"tools"
],
"requirements": [
"colour",
"pillow"
],
"hidden": false
}
4 changes: 2 additions & 2 deletions commandchart/commandchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
MIT License
Copyright (c) 2018-Present NeuroAssassin
Copyright (c) 2018-Present NeuroAssassin
Copyright (c) 2016-present aikaterna
Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -131,7 +131,7 @@ def create_chart(self, top, others, channel):
@commands.guild_only()
@commands.command()
async def commandchart(
self, ctx, channel: typing.Optional[discord.TextChannel] = None, number: int = 5000,
self, ctx, channel: typing.Optional[discord.TextChannel] = None, number: int = 5000
):
"""See the used commands in a certain channel within a certain amount of messages."""
e = discord.Embed(description="Loading...", color=0x000099)
Expand Down
24 changes: 15 additions & 9 deletions commandchart/info.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"author" : ["Neuro Assassin"],
"install_msg" : "Thank you for downloading this cog.",
"name" : "commandchart",
"short" : "Tells the used and usages of commands! Based off of aikaterna's chatchart cog.",
"description" : "This cog tells a Discord User the commands used, and the usage of them, in the last so and so messages. Based off of aikaterna's chatchart cog.",
"tags" : ["tools"],
"requirements" : ["matplotlib"],
"hidden" : false
}
"author": [
"Neuro Assassin"
],
"install_msg": "Thank you for downloading this cog.",
"name": "commandchart",
"short": "Tells the used and usages of commands! Based off of aikaterna's chatchart cog.",
"description": "This cog tells a Discord User the commands used, and the usage of them, in the last so and so messages. Based off of aikaterna's chatchart cog.",
"tags": [
"tools"
],
"requirements": [
"matplotlib"
],
"hidden": false
}
9 changes: 6 additions & 3 deletions cooldown/cooldown.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class Cooldown(commands.Cog):
WARNING: Some cooldowns are meant to be in place, meaning that they should not be removed.
Any contributors to this cog are not at fault if it is used improperly, and is instead at
the fault of the person running the command. By installing this cog, you agree to these terms."""
the fault of the person running the command. By installing this cog, you agree to these terms.
"""

def __init__(self, bot):
self.bot = bot
Expand Down Expand Up @@ -99,7 +100,8 @@ async def add(self, ctx, rate: int, per, btype, *, command):
- Rate: how many times
- Per: during how long
- Type: for what type
- Command: for what command. Do not use a prefix, and does not work with aliases. Please pass the actual command for the alias if you wish."""
- Command: for what command. Do not use a prefix, and does not work with aliases. Please pass the actual command for the alias if you wish.
"""
ttype = None
per = per.lower()
np = per[:-1]
Expand Down Expand Up @@ -191,7 +193,8 @@ async def remove(self, ctx, *, command):
Please do note however: some commands are meant to have cooldowns. They may prevent something malicious from happening, or maybe your device from breaking or from being used too much. I (Neuro Assassin <@473541068378341376>) or any other contributor to this cog take no responsibility for any complications that may result because of this. Use at your own risk.
Note: Does not actually remove the command cooldown (undocumented), so instead it allows for the command to be run 100000 times every 1 second until the next boot up, where it will not be added (unless you are removing a cooldown from outside of this cog, then it will be kept after restart)."""
Note: Does not actually remove the command cooldown (undocumented), so instead it allows for the command to be run 100000 times every 1 second until the next boot up, where it will not be added (unless you are removing a cooldown from outside of this cog, then it will be kept after restart).
"""
cmd = self.bot.get_command(command)
if cmd == None or not str(cmd) == command:
return await ctx.send("Invalid command argument.")
Expand Down
2 changes: 1 addition & 1 deletion cooldown/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"tools"
],
"hidden": false
}
}
2 changes: 1 addition & 1 deletion dashboard/abc/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ async def dashboard(self, ctx: commands.Context):


class DBMixin:
""" This is mostly here to easily mess with things... """
"""This is mostly here to easily mess with things..."""

c = dashboard
Loading

0 comments on commit 6ad4ec4

Please sign in to comment.