Skip to content

Commit 026a5ee

Browse files
update lint config (#138)
* update lint config * run lint config * add build tag to rtd * update dependencies * use poetry as the runner * update action versions * fix status embed * run tests on windows * don't run lint on every platform
1 parent df5dbb9 commit 026a5ee

File tree

19 files changed

+1504
-1654
lines changed

19 files changed

+1504
-1654
lines changed

.github/workflows/lint_test.yml

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,18 @@ jobs:
3636
runs-on: ubuntu-latest
3737
strategy:
3838
fail-fast: false
39-
matrix:
40-
python_version: ['3.8', '3.9','3.10']
41-
env:
42-
PYTHON_VERSION: ${{ matrix.python_version }}
4339
steps:
4440
- name: Add custom PYTHONUSERBASE to PATH
4541
run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH
4642

4743
# Checks out the repository in the current folder.
4844
- name: Checks out repository
49-
uses: actions/checkout@v2
45+
uses: actions/checkout@v4
5046

5147
# Set up the right version of Python
5248
- name: Set up Python ${{ env.PYTHON_VERSION }}
5349
id: python
54-
uses: actions/setup-python@v2
50+
uses: actions/setup-python@v5
5551
with:
5652
python-version: ${{ env.PYTHON_VERSION }}
5753

@@ -62,7 +58,7 @@ jobs:
6258
#
6359
# Only when the context is exactly the same, we will restore the cache.
6460
- name: Python Dependency Caching
65-
uses: actions/cache@v2
61+
uses: actions/cache@v4
6662
id: python_cache
6763
with:
6864
path: ${{ env.PYTHONUSERBASE }}
@@ -72,7 +68,7 @@ jobs:
7268

7369
# Install our dependencies if we did not restore a dependency cache
7470
- name: Install dependencies using poetry
75-
if: steps.python_cache.outputs.cache-hit != 'true'
71+
# if: steps.python_cache.outputs.cache-hit != 'true'
7672
run: |
7773
pip install poetry
7874
poetry install --no-interaction --no-ansi
@@ -81,7 +77,7 @@ jobs:
8177
# do create a new environment when our pre-commit setup changes,
8278
# we create a cache key based on relevant factors.
8379
- name: Pre-commit Environment Caching
84-
uses: actions/cache@v2
80+
uses: actions/cache@v4
8581
with:
8682
path: ${{ env.PRE_COMMIT_HOME }}
8783
key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
@@ -93,14 +89,14 @@ jobs:
9389
# we set PIP_USER=0 to not do a user install.
9490
- name: Run pre-commit hooks
9591
id: pre-commit
96-
run: export PIP_USER=0; SKIP="no-commit-to-branch,black,flake8" pre-commit run --all-files
92+
run: export PIP_USER=0; SKIP="no-commit-to-branch,black,flake8" poetry run pre-commit run --all-files
9793

9894
# Run black seperately as we don't want to reformat the files
9995
# just error if something isn't formatted correctly.
10096
- name: Check files with black
10197
id: black
10298
if: always() && (steps.pre-commit.outcome == 'success' || steps.pre-commit.outcome == 'failure')
103-
run: black . --check --diff --color
99+
run: poetry run black . --check --diff --color
104100

105101
# Run flake8 and have it format the linting errors in the format of
106102
# the GitHub Workflow command to register error annotations. This
@@ -113,7 +109,7 @@ jobs:
113109
- name: Run flake8
114110
id: flake8
115111
if: always() && (steps.pre-commit.outcome == 'success' || steps.pre-commit.outcome == 'failure')
116-
run: "flake8 \
112+
run: "poetry run flake8 \
117113
--format='::error file=%(path)s,line=%(row)d,col=%(col)d::\
118114
[flake8] %(code)s: %(text)s'"
119115

@@ -132,12 +128,12 @@ jobs:
132128

133129
# Checks out the repository in the current folder.
134130
- name: Checks out repository
135-
uses: actions/checkout@v2
131+
uses: actions/checkout@v4
136132

137133
# Set up the right version of Python
138134
- name: Set up Python ${{ env.PYTHON_VERSION }}
139135
id: python
140-
uses: actions/setup-python@v2
136+
uses: actions/setup-python@v5
141137
with:
142138
python-version: ${{ env.PYTHON_VERSION }}
143139

@@ -148,7 +144,7 @@ jobs:
148144
#
149145
# Only when the context is exactly the same, we will restore the cache.
150146
- name: Python Dependency Caching
151-
uses: actions/cache@v2
147+
uses: actions/cache@v4
152148
id: python_cache
153149
with:
154150
path: ${{ env.PYTHONUSERBASE }}
@@ -158,7 +154,7 @@ jobs:
158154

159155
# Install our dependencies if we did not restore a dependency cache
160156
- name: Install dependencies using poetry
161-
if: steps.python_cache.outputs.cache-hit != 'true'
157+
# if: steps.python_cache.outputs.cache-hit != 'true'
162158
run: |
163159
python -m pip install poetry
164160
python -m poetry install --no-interaction --no-ansi
@@ -168,7 +164,7 @@ jobs:
168164
# coverage report to github.
169165
- name: Run tests and generate coverage report
170166
id: run_tests
171-
run: python -m pytest tests -n auto --dist loadfile --cov --disable-warnings -q
167+
run: python -m poetry run pytest tests -n auto --dist loadfile --cov --disable-warnings -q
172168

173169
# This step will publish the coverage reports to coveralls.io and
174170
# print a "job" link in the output of the GitHub Action
@@ -183,7 +179,7 @@ jobs:
183179
COVERALLS_FLAG_NAME: coverage-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}
184180
COVERALLS_PARALLEL: true
185181
COVERALLS_SERVICE_NAME: github
186-
run: python -m coveralls
182+
run: python -m poetry run coveralls
187183

188184
coveralls-finish:
189185
name: Indicate completion to coveralls.io
@@ -235,7 +231,7 @@ jobs:
235231
- name: Upload a Build Artifact
236232
if: always() && steps.prepare-artifact.outcome == 'success'
237233
continue-on-error: true
238-
uses: actions/upload-artifact@v2
234+
uses: actions/upload-artifact@v4
239235
with:
240236
name: pull-request-payload
241237
path: pull_request_payload.json

.github/workflows/status_embed.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ on:
1111

1212
jobs:
1313
status_embed:
14-
name: Send Status Embed to Discord
14+
name: Send Status Embed to Discord
1515
runs-on: ubuntu-latest
16+
if: ${{ !endsWith(github.actor, '[bot]') }}
1617

1718
steps:
1819
# Process the artifact uploaded in the `pull_request`-triggered workflow:
@@ -23,13 +24,13 @@ jobs:
2324
curl -s -H "Authorization: token $GITHUB_TOKEN" ${{ github.event.workflow_run.artifacts_url }} > artifacts.json
2425
DOWNLOAD_URL=$(cat artifacts.json | jq -r '.artifacts[] | select(.name == "pull-request-payload") | .archive_download_url')
2526
[ -z "$DOWNLOAD_URL" ] && exit 1
26-
wget --quiet --header="Authorization: token $GITHUB_TOKEN" -O pull_request_payload.zip $DOWNLOAD_URL || exit 2
27+
curl -sSL -H "Authorization: token $GITHUB_TOKEN" -o pull_request_payload.zip $DOWNLOAD_URL || exit 2
2728
unzip -p pull_request_payload.zip > pull_request_payload.json
2829
[ -s pull_request_payload.json ] || exit 3
29-
echo "::set-output name=pr_author_login::$(jq -r '.user.login // empty' pull_request_payload.json)"
30-
echo "::set-output name=pr_number::$(jq -r '.number // empty' pull_request_payload.json)"
31-
echo "::set-output name=pr_title::$(jq -r '.title // empty' pull_request_payload.json)"
32-
echo "::set-output name=pr_source::$(jq -r '.head.label // empty' pull_request_payload.json)"
30+
echo "pr_author_login=$(jq -r '.user.login // empty' pull_request_payload.json)" >> $GITHUB_OUTPUT
31+
echo "pr_number=$(jq -r '.number // empty' pull_request_payload.json)" >> $GITHUB_OUTPUT
32+
echo "pr_title=$(jq -r '.title // empty' pull_request_payload.json)" >> $GITHUB_OUTPUT
33+
echo "pr_source=$(jq -r '.head.label // empty' pull_request_payload.json)" >> $GITHUB_OUTPUT
3334
env:
3435
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3536

.pre-commit-config.yaml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,18 @@ repos:
1111
files: '(app\.json|template\.env|modmail\/(config\.py|default_config(\.toml|\.yaml)))$'
1212
require_serial: true
1313
additional_dependencies:
14-
# so apparently these are needed, but the versions don't have to be pinned since it uses the local env
15-
# go figure.
1614
- atoml
1715
- attrs
1816
- click
1917
- coloredlogs
2018
- desert
21-
- discord.py
19+
- https://github.com/Rapptz/discord.py/archive/45d498c1b76deaf3b394d17ccf56112fa691d160.zip
2220
- marshmallow
2321
- python-dotenv
2422
- pyyaml
2523

2624
- repo: https://github.com/pre-commit/pre-commit-hooks
27-
rev: v4.2.0
25+
rev: v4.6.0
2826
hooks:
2927
- id: check-case-conflict
3028
- id: check-added-large-files
@@ -45,39 +43,45 @@ repos:
4543
- id: trailing-whitespace
4644
args: [--markdown-linebreak-ext=md]
4745

48-
- repo: local
49-
hooks:
50-
- id: generate_requirements.txt
51-
name: Generate requirements.txt
52-
entry: python -m scripts.export_requirements --docs
53-
files: '(pyproject.toml|poetry.lock|requirements.txt|scripts\/export\_requirements\.py|docs\/.requirements.txt)$'
54-
language: python
55-
pass_filenames: false
56-
require_serial: true
57-
additional_dependencies:
58-
- tomli~=1.2.1
59-
6046
- repo: https://github.com/pre-commit/pygrep-hooks
61-
rev: v1.9.0
47+
rev: v1.10.0
6248
hooks:
6349
- id: python-check-blanket-noqa
6450
- id: python-check-blanket-type-ignore
6551
- id: python-use-type-annotations
6652

53+
- repo: https://github.com/python-poetry/poetry
54+
rev: 1.8.0
55+
hooks:
56+
- id: poetry-check
57+
name: Check poetry.lock is up to date
58+
59+
- repo: https://github.com/python-poetry/poetry-plugin-export
60+
rev: 1.8.0
61+
hooks:
62+
- id: poetry-export
63+
name: Generate requirements.txt
64+
args: ['-qqq', -f, requirements.txt, --without-hashes, --output, requirements.txt]
65+
files: '(pyproject.toml|poetry.lock|requirements.txt)$'
66+
- id: poetry-export
67+
name: Generate docs requirements.txt
68+
args: ['-qqq', --only, docs, -f, constraints.txt, --without-hashes, --output, docs/.requirements.txt]
69+
files: '(pyproject.toml|poetry.lock|docs\/.requirements.txt)$'
70+
6771
- repo: https://github.com/PyCQA/isort
68-
rev: 5.10.1
72+
rev: 5.13.2
6973
hooks:
7074
- id: isort
7175

7276
- repo: https://github.com/asottile/blacken-docs
73-
rev: v1.12.1
77+
rev: 1.18.0
7478
hooks:
7579
- id: blacken-docs
7680
additional_dependencies:
7781
- black
7882

7983
- repo: https://github.com/psf/black
80-
rev: 22.3.0
84+
rev: 24.8.0
8185
hooks:
8286
- id: black
8387
language_version: python3

.readthedocs.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
version: 2
22

3+
build:
4+
os: ubuntu-22.04
5+
tools:
6+
python: "3.8"
7+
8+
39
python:
4-
version: "3.8"
510
install:
611
- requirements: docs/.requirements.txt
712

docs/.requirements.txt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
# because we have mkdocs extensions
2-
# and readthedocs doesn't support building from poetry
3-
# we have to declare our dependencies here
4-
5-
mkdocs==1.2.3
6-
mkdocs-material==7.2.6
7-
mkdocs-markdownextradata-plugin==0.1.9
1+
click==8.1.7 ; python_version >= "3.8" and python_version < "4.0"
2+
colorama==0.4.6 ; python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows"
3+
ghp-import==2.1.0 ; python_version >= "3.8" and python_version < "4.0"
4+
importlib-metadata==8.5.0 ; python_version >= "3.8" and python_version < "3.10"
5+
jinja2==3.1.4 ; python_version >= "3.8" and python_version < "4.0"
6+
markdown==3.7 ; python_version >= "3.8" and python_version < "4.0"
7+
markupsafe==2.1.5 ; python_version >= "3.8" and python_version < "4.0"
8+
mergedeep==1.3.4 ; python_version >= "3.8" and python_version < "4.0"
9+
mkdocs-get-deps==0.2.0 ; python_version >= "3.8" and python_version < "4.0"
10+
mkdocs-markdownextradata-plugin==0.1.9 ; python_version >= "3.8" and python_version < "4.0"
11+
mkdocs-material-extensions==1.3.1 ; python_version >= "3.8" and python_version < "4.0"
12+
mkdocs-material==7.3.6 ; python_version >= "3.8" and python_version < "4.0"
13+
mkdocs==1.6.1 ; python_version >= "3.8" and python_version < "4.0"
14+
packaging==24.1 ; python_version >= "3.8" and python_version < "4.0"
15+
pathspec==0.12.1 ; python_version >= "3.8" and python_version < "4.0"
16+
platformdirs==4.3.6 ; python_version >= "3.8" and python_version < "4.0"
17+
pygments==2.18.0 ; python_version >= "3.8" and python_version < "4.0"
18+
pymdown-extensions==10.10.1 ; python_version >= "3.8" and python_version < "4.0"
19+
python-dateutil==2.9.0.post0 ; python_version >= "3.8" and python_version < "4.0"
20+
pyyaml-env-tag==0.1 ; python_version >= "3.8" and python_version < "4.0"
21+
pyyaml==6.0.2 ; python_version >= "3.8" and python_version < "4.0"
22+
six==1.16.0 ; python_version >= "3.8" and python_version < "4.0"
23+
watchdog==4.0.2 ; python_version >= "3.8" and python_version < "4.0"
24+
zipp==3.20.2 ; python_version >= "3.8" and python_version < "3.10"

modmail/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ class ConfigMetadata:
202202
# as a solution, I'm implementing a field which can provide a rich converter object,
203203
# in the style that discord.py uses. This will be called like discord py calls.
204204
discord_converter: discord.ext.commands.converter.Converter = attr.ib(default=None)
205-
discord_converter_attribute: typing.Optional[
206-
types.FunctionType
207-
] = None # if we want an attribute off of the converted value
205+
discord_converter_attribute: typing.Optional[types.FunctionType] = (
206+
None # if we want an attribute off of the converted value
207+
)
208208

209209
# hidden values do not show up in the bot configuration menu
210210
hidden: bool = False

modmail/dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def activate(self, instance: object) -> None:
8080
if underlying_function not in self.pending_handlers:
8181
continue
8282

83-
for (event_name, priority) in self.pending_handlers[underlying_function]:
83+
for event_name, priority in self.pending_handlers[underlying_function]:
8484
self._register_handler(event_name, priority, value)
8585
self.pending_handlers[underlying_function].clear()
8686

modmail/extensions/threads.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ def __init__(self, bot: "ModmailBot"):
136136
super().__init__(bot)
137137
# validation for this configuration variable is be defered to fully implementing
138138
# a new configuration system
139-
self.relay_channel: Union[
140-
discord.TextChannel, discord.PartialMessageable
141-
] = self.bot.get_partial_messageable(self.bot.config.user.threads.relay_channel_id)
139+
self.relay_channel: Union[discord.TextChannel, discord.PartialMessageable] = (
140+
self.bot.get_partial_messageable(self.bot.config.user.threads.relay_channel_id)
141+
)
142142

143143
self.dms_to_users: Dict[int, int] = dict() # key: dm_channel.id, value: user.id
144144

modmail/plugins/local/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Plugins should be like normal discord cogs, but should subclass `PluginCog` from
77
```py
88
from modmail.plugin_helpers import PluginCog
99

10+
1011
class MyPlugin(PluginCog):
1112
pass
1213
```

modmail/utils/pagination.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
Originally adapated from: https://github.com/khk4912/EZPaginator/tree/84b5213741a78de266677b805c6f694ad94fedd6
55
"""
6+
67
from __future__ import annotations
78

89
import logging

0 commit comments

Comments
 (0)