Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions .github/workflows/lint_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python_version: ['3.8', '3.9','3.10']
env:
PYTHON_VERSION: ${{ matrix.python_version }}
steps:
- name: Add custom PYTHONUSERBASE to PATH
run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH

# Checks out the repository in the current folder.
- name: Checks out repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Set up the right version of Python
- name: Set up Python ${{ env.PYTHON_VERSION }}
id: python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand All @@ -62,7 +58,7 @@ jobs:
#
# Only when the context is exactly the same, we will restore the cache.
- name: Python Dependency Caching
uses: actions/cache@v2
uses: actions/cache@v4
id: python_cache
with:
path: ${{ env.PYTHONUSERBASE }}
Expand All @@ -72,7 +68,7 @@ jobs:

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

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

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

Expand All @@ -132,12 +128,12 @@ jobs:

# Checks out the repository in the current folder.
- name: Checks out repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Set up the right version of Python
- name: Set up Python ${{ env.PYTHON_VERSION }}
id: python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand All @@ -148,7 +144,7 @@ jobs:
#
# Only when the context is exactly the same, we will restore the cache.
- name: Python Dependency Caching
uses: actions/cache@v2
uses: actions/cache@v4
id: python_cache
with:
path: ${{ env.PYTHONUSERBASE }}
Expand All @@ -158,7 +154,7 @@ jobs:

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

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

coveralls-finish:
name: Indicate completion to coveralls.io
Expand Down Expand Up @@ -235,7 +231,7 @@ jobs:
- name: Upload a Build Artifact
if: always() && steps.prepare-artifact.outcome == 'success'
continue-on-error: true
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: pull-request-payload
path: pull_request_payload.json
13 changes: 7 additions & 6 deletions .github/workflows/status_embed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ on:

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

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

Expand Down
44 changes: 24 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ repos:
files: '(app\.json|template\.env|modmail\/(config\.py|default_config(\.toml|\.yaml)))$'
require_serial: true
additional_dependencies:
# so apparently these are needed, but the versions don't have to be pinned since it uses the local env
# go figure.
- atoml
- attrs
- click
- coloredlogs
- desert
- discord.py
- https://github.com/Rapptz/discord.py/archive/45d498c1b76deaf3b394d17ccf56112fa691d160.zip
- marshmallow
- python-dotenv
- pyyaml

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.6.0
hooks:
- id: check-case-conflict
- id: check-added-large-files
Expand All @@ -45,39 +43,45 @@ repos:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: local
hooks:
- id: generate_requirements.txt
name: Generate requirements.txt
entry: python -m scripts.export_requirements --docs
files: '(pyproject.toml|poetry.lock|requirements.txt|scripts\/export\_requirements\.py|docs\/.requirements.txt)$'
language: python
pass_filenames: false
require_serial: true
additional_dependencies:
- tomli~=1.2.1

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-use-type-annotations

- repo: https://github.com/python-poetry/poetry
rev: 1.8.0
hooks:
- id: poetry-check
name: Check poetry.lock is up to date

- repo: https://github.com/python-poetry/poetry-plugin-export
rev: 1.8.0
hooks:
- id: poetry-export
name: Generate requirements.txt
args: ['-qqq', -f, requirements.txt, --without-hashes, --output, requirements.txt]
files: '(pyproject.toml|poetry.lock|requirements.txt)$'
- id: poetry-export
name: Generate docs requirements.txt
args: ['-qqq', --only, docs, -f, constraints.txt, --without-hashes, --output, docs/.requirements.txt]
files: '(pyproject.toml|poetry.lock|docs\/.requirements.txt)$'

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
rev: 1.18.0
hooks:
- id: blacken-docs
additional_dependencies:
- black

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.8.0
hooks:
- id: black
language_version: python3
Expand Down
7 changes: 6 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.8"


python:
version: "3.8"
install:
- requirements: docs/.requirements.txt

Expand Down
31 changes: 24 additions & 7 deletions docs/.requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
# because we have mkdocs extensions
# and readthedocs doesn't support building from poetry
# we have to declare our dependencies here

mkdocs==1.2.3
mkdocs-material==7.2.6
mkdocs-markdownextradata-plugin==0.1.9
click==8.1.7 ; python_version >= "3.8" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows"
ghp-import==2.1.0 ; python_version >= "3.8" and python_version < "4.0"
importlib-metadata==8.5.0 ; python_version >= "3.8" and python_version < "3.10"
jinja2==3.1.4 ; python_version >= "3.8" and python_version < "4.0"
markdown==3.7 ; python_version >= "3.8" and python_version < "4.0"
markupsafe==2.1.5 ; python_version >= "3.8" and python_version < "4.0"
mergedeep==1.3.4 ; python_version >= "3.8" and python_version < "4.0"
mkdocs-get-deps==0.2.0 ; python_version >= "3.8" and python_version < "4.0"
mkdocs-markdownextradata-plugin==0.1.9 ; python_version >= "3.8" and python_version < "4.0"
mkdocs-material-extensions==1.3.1 ; python_version >= "3.8" and python_version < "4.0"
mkdocs-material==7.3.6 ; python_version >= "3.8" and python_version < "4.0"
mkdocs==1.6.1 ; python_version >= "3.8" and python_version < "4.0"
packaging==24.1 ; python_version >= "3.8" and python_version < "4.0"
pathspec==0.12.1 ; python_version >= "3.8" and python_version < "4.0"
platformdirs==4.3.6 ; python_version >= "3.8" and python_version < "4.0"
pygments==2.18.0 ; python_version >= "3.8" and python_version < "4.0"
pymdown-extensions==10.10.1 ; python_version >= "3.8" and python_version < "4.0"
python-dateutil==2.9.0.post0 ; python_version >= "3.8" and python_version < "4.0"
pyyaml-env-tag==0.1 ; python_version >= "3.8" and python_version < "4.0"
pyyaml==6.0.2 ; python_version >= "3.8" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.8" and python_version < "4.0"
watchdog==4.0.2 ; python_version >= "3.8" and python_version < "4.0"
zipp==3.20.2 ; python_version >= "3.8" and python_version < "3.10"
6 changes: 3 additions & 3 deletions modmail/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ class ConfigMetadata:
# as a solution, I'm implementing a field which can provide a rich converter object,
# in the style that discord.py uses. This will be called like discord py calls.
discord_converter: discord.ext.commands.converter.Converter = attr.ib(default=None)
discord_converter_attribute: typing.Optional[
types.FunctionType
] = None # if we want an attribute off of the converted value
discord_converter_attribute: typing.Optional[types.FunctionType] = (
None # if we want an attribute off of the converted value
)

# hidden values do not show up in the bot configuration menu
hidden: bool = False
Expand Down
2 changes: 1 addition & 1 deletion modmail/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def activate(self, instance: object) -> None:
if underlying_function not in self.pending_handlers:
continue

for (event_name, priority) in self.pending_handlers[underlying_function]:
for event_name, priority in self.pending_handlers[underlying_function]:
self._register_handler(event_name, priority, value)
self.pending_handlers[underlying_function].clear()

Expand Down
6 changes: 3 additions & 3 deletions modmail/extensions/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def __init__(self, bot: "ModmailBot"):
super().__init__(bot)
# validation for this configuration variable is be defered to fully implementing
# a new configuration system
self.relay_channel: Union[
discord.TextChannel, discord.PartialMessageable
] = self.bot.get_partial_messageable(self.bot.config.user.threads.relay_channel_id)
self.relay_channel: Union[discord.TextChannel, discord.PartialMessageable] = (
self.bot.get_partial_messageable(self.bot.config.user.threads.relay_channel_id)
)

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

Expand Down
1 change: 1 addition & 0 deletions modmail/plugins/local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Plugins should be like normal discord cogs, but should subclass `PluginCog` from
```py
from modmail.plugin_helpers import PluginCog


class MyPlugin(PluginCog):
pass
```
1 change: 1 addition & 0 deletions modmail/utils/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Originally adapated from: https://github.com/khk4912/EZPaginator/tree/84b5213741a78de266677b805c6f694ad94fedd6
"""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions modmail/utils/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Note: these are to used for general success or general errors. Typically, the error handler will make a
response if a command raises a discord.ext.commands.CommandError exception.
"""

import logging
import random
import typing
Expand Down
6 changes: 3 additions & 3 deletions modmail/utils/threads/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def __init__(
"""
self.thread = thread
self.recipient = recipient
self.log_message: Union[
discord.Message, discord.PartialMessage
] = log_message or self.thread.parent.get_partial_message(self.thread.id)
self.log_message: Union[discord.Message, discord.PartialMessage] = (
log_message or self.thread.parent.get_partial_message(self.thread.id)
)
self.messages = MessageDict()
self.close_after = self.thread.auto_archive_duration
self.has_sent_initial_message = has_sent_initial_message
Expand Down
Loading
Loading