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
12 changes: 6 additions & 6 deletions .github/workflows/lint_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- uses: actions/checkout@v6
with:
ref: ${{ env.ref }}
- uses: actions/setup-python@v6
- uses: astral-sh/ruff-action@v3
with:
python-version: "3.9"
- run: "python -m pip install git+https://github.com/pycqa/pyflakes@1911c20#egg=pyflakes git+https://github.com/pycqa/pycodestyle@d219c68#egg=pycodestyle git+https://github.com/pycqa/flake8@3.7.9#egg=flake8"
name: Install Flake8
- run: "python -m flake8 . --count --select=E9,F7,F82 --show-source"
name: Flake8 Linting
version: "0.15.9"
- uses: astral-sh/ruff-action@v3
with:
version: "0.15.9"
args: "format --check"
216 changes: 216 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/

# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# Redis
*.rdb
*.aof
*.pid

# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/

# ActiveMQ
activemq-data/

# SageMath parsed files
*.sage.py

# Environments
.env
.envrc
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/

# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/

# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/

# Streamlit
.streamlit/secrets.toml
14 changes: 5 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ repos:
- id: mixed-line-ending
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.3.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.9
hooks:
- id: black
args: [--target-version=py39, --line-length=99]
- repo: https://github.com/PyCQA/isort
rev: 8.0.1
hooks:
- id: isort
args: [--profile=black, --line-length=99]
- id: ruff
args: [--fix, --unsafe-fixes]
- id: ruff-format
24 changes: 10 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,21 @@ All contributions must be your own original work. If i suspect a contribution wa

## Guidelines for Submitting PRs
Always use the following:
- Black
- isort
- Ruff

## How to Use Black
- First, install Black:
## How to Use Ruff
- First, install Ruff:
```bash
pip install black
pip install ruff
```
- Then run
- Then run the linter (fixes imports, style, and common issues automatically):
```bash
black --line-length 99 <source_file_or_directory>
ruff check --fix <source_file_or_directory>
```

## How to use isort?
- First you will have to install it
- Then run the formatter:
```bash
[p]pip install isort
ruff format <source_file_or_directory>
```
- Then run
```bash
isort <source_file_or_directory>

Both commands must be run before submitting a PR. Ruff is configured in `pyproject.toml` at the root of the repo — no extra flags needed beyond what's shown above.
```
1 change: 1 addition & 0 deletions autopublisher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .autopublisher import AutoPublisher


__red_end_user_data_statement__ = "This cog does not persistently store data about users."


Expand Down
1 change: 1 addition & 0 deletions autopublisher/autopublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from .utils import increment_published_count, initialize_scheduler, schedule_resets
from .view import IgnoredNewsChannelsView, MetricsView


logger = getLogger("red.maxcogs.autopublisher")


Expand Down
4 changes: 2 additions & 2 deletions autopublisher/dashboard_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

from datetime import datetime
from typing import Any, Dict
from typing import Any

import discord
import pytz
Expand Down Expand Up @@ -51,7 +51,7 @@ async def on_dashboard_cog_add(self, dashboard_cog: commands.Cog) -> None:
dashboard_cog.rpc.third_parties_handler.add_third_party(self)

@dashboard_page(name="stats", description="View AutoPublisher statistics", is_owner=True)
async def dashboard_stats(self, user: discord.User, **kwargs) -> Dict[str, Any]:
async def dashboard_stats(self, user: discord.User, **kwargs) -> dict[str, Any]:
"""Dashboard page to display AutoPublisher stats."""
owner_tz = await get_owner_timezone(self.config)
data = await self.config.all()
Expand Down
1 change: 1 addition & 0 deletions autopublisher/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from red_commons.logging import getLogger
from redbot.core import Config, commands


logger = getLogger("red.maxcogs.autopublisher.utils")


Expand Down
15 changes: 7 additions & 8 deletions autopublisher/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import pytz
from red_commons.logging import getLogger
from redbot.core import commands
from redbot.core.utils.chat_formatting import box, header, humanize_number
from tabulate import tabulate
from redbot.core.utils.chat_formatting import box, humanize_number

from .utils import get_next_reset_times, get_owner_timezone


log = getLogger("red.maxcogs.autopublisher.view")


Expand Down Expand Up @@ -91,7 +91,7 @@ async def start(self, ctx: commands.Context) -> None:

async def interaction_check(self, interaction: discord.Interaction) -> bool:
"""Check if the user is allowed to interact."""
if interaction.user.id not in [self.ctx.author.id] + list(self.ctx.bot.owner_ids):
if interaction.user.id not in [self.ctx.author.id, *list(self.ctx.bot.owner_ids)]:
await interaction.response.send_message(
"You are not allowed to use this interaction.", ephemeral=True
)
Expand Down Expand Up @@ -184,13 +184,12 @@ def rate(val: int, days: int) -> str:
return f"{val / days:.1f}" if days > 0 else "N/A"

import calendar
from datetime import datetime
from datetime import timezone as dt_timezone

now = datetime.now(owner_tz)
days_in_month = calendar.monthrange(now.year, now.month)[1]
day_of_year = now.timetuple().tm_yday
week_day = now.weekday() + 1
now.weekday() + 1

weekly_avg = rate(weekly, 7)
monthly_avg = rate(monthly, days_in_month)
Expand All @@ -207,7 +206,7 @@ def total_bar(val: int) -> str:
return FILL * filled + EMPTY * (BAR_WIDTH - filled)

pct_weekly_of_monthly = f"{(weekly / monthly * 100):.1f}%" if monthly else "N/A"
pct_yearly_of_total = f"{(yearly / total * 100):.1f}%" if total else "N/A"
pct_yearly_of_total = f"{(yearly / total * 100):.1f}%" if total else "N/A"

last_pub = "Never"
if last_count_time:
Expand Down Expand Up @@ -265,7 +264,7 @@ def __init__(self, cog: commands.Cog) -> None:
self.cog = cog
self.ctx: commands.Context | None = None
self.message: discord.Message | None = None
self.owner_tz: "pytz.timezone | None" = None
self.owner_tz: pytz.timezone | None = None

self.refresh_button = discord.ui.Button(
label="Refresh", style=discord.ButtonStyle.green, emoji="🔄"
Expand Down Expand Up @@ -317,7 +316,7 @@ async def _update_view(self) -> None:
self.add_item(self.container)

async def interaction_check(self, interaction: discord.Interaction) -> bool:
if interaction.user.id not in [self.ctx.author.id] + list(self.ctx.bot.owner_ids):
if interaction.user.id not in [self.ctx.author.id, *list(self.ctx.bot.owner_ids)]:
await interaction.response.send_message(
"You are not allowed to use this interaction.", ephemeral=True
)
Expand Down
Loading
Loading