1
0
Fork 0
forked from github/pelican

Merge pull request #3223 from offbyone/switch-to-ruff

This commit is contained in:
Justin Mayer 2023-10-28 22:38:26 +02:00 committed by GitHub
commit 269751b033
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 38 deletions

View file

@ -62,16 +62,20 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip"
cache-dependency-path: "**/requirements/*"
- name: Install tox
run: python -m pip install -U pip tox
- name: Check
run: tox -e flake8
cache: "poetry"
cache-dependency-path: "pyproject.toml"
- name: Install dependencies
run: |
poetry env use "3.9"
poetry install --no-interaction --no-root
- name: Run linters
run: poetry run invoke lint --diff
docs:
name: Build docs

View file

@ -13,13 +13,11 @@ repos:
- id: end-of-file-fixer
- id: forbid-new-submodules
- id: trailing-whitespace
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.0
hooks:
- id: flake8
name: Flake8 on commit diff
description: This hook limits Flake8 checks to changed lines of code.
entry: bash
args: [-c, 'git diff HEAD | flake8 --diff --max-line-length=88']
- id: ruff
- id: ruff-format
args: ["--check"]
exclude: ^pelican/tests/output/

View file

@ -10,7 +10,7 @@ def err(msg, die=None):
"""Print an error message and exits if an exit code is given"""
sys.stderr.write(msg + '\n')
if die:
sys.exit(die if type(die) is int else 1)
sys.exit(die if isinstance(die, int) else 1)
try:
@ -135,16 +135,16 @@ def themes():
def list_themes(v=False):
"""Display the list of the themes"""
for t, l in themes():
for theme_path, link_target in themes():
if not v:
t = os.path.basename(t)
if l:
theme_path = os.path.basename(theme_path)
if link_target:
if v:
print(t + (" (symbolic link to `" + l + "')"))
print(theme_path + (" (symbolic link to `" + link_target + "')"))
else:
print(t + '@')
print(theme_path + '@')
else:
print(t)
print(theme_path)
def remove(theme_name, v=False):

View file

@ -57,6 +57,7 @@ pytest = "^7.1"
pytest-cov = "^4.0"
pytest-sugar = "^0.9.5"
pytest-xdist = "^2.0"
ruff = "^0.1.3"
tox = {version = "^3.13", optional = true}
flake8 = "^3.8"
flake8-import-order = "^0.18.1"

View file

@ -66,13 +66,20 @@ def isort(c, check=False, diff=False):
@task
def flake8(c):
c.run(f"git diff HEAD | {VENV_BIN}/flake8 --diff --max-line-length=88", pty=PTY)
def ruff(c, fix=False, diff=False):
"""Run Ruff to ensure code meets project standards."""
diff_flag, fix_flag = "", ""
if fix:
fix_flag = "--fix"
if diff:
diff_flag = "--diff"
c.run(f"{VENV_BIN}/ruff check {diff_flag} {fix_flag} .", pty=PTY)
@task
def lint(c):
flake8(c)
def lint(c, fix=False, diff=False):
"""Check code style via linting tools."""
ruff(c, fix=fix, diff=diff)
@task

14
tox.ini
View file

@ -30,17 +30,3 @@ filterwarnings =
default::DeprecationWarning
error:.*:Warning:pelican
addopts = -n auto -r a
[flake8]
application-import-names = pelican
import-order-style = cryptography
max-line-length = 88
[testenv:flake8]
basepython = python3.9
skip_install = true
deps =
-rrequirements/style.pip
commands =
flake8 --version
flake8 pelican