forked from github/pelican
Merge pull request #3223 from offbyone/switch-to-ruff
This commit is contained in:
commit
269751b033
6 changed files with 34 additions and 38 deletions
16
.github/workflows/main.yml
vendored
16
.github/workflows/main.yml
vendored
|
|
@ -62,16 +62,20 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
- name: Install Poetry
|
||||||
|
run: pipx install poetry
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: "3.9"
|
python-version: "3.9"
|
||||||
cache: "pip"
|
cache: "poetry"
|
||||||
cache-dependency-path: "**/requirements/*"
|
cache-dependency-path: "pyproject.toml"
|
||||||
- name: Install tox
|
- name: Install dependencies
|
||||||
run: python -m pip install -U pip tox
|
run: |
|
||||||
- name: Check
|
poetry env use "3.9"
|
||||||
run: tox -e flake8
|
poetry install --no-interaction --no-root
|
||||||
|
- name: Run linters
|
||||||
|
run: poetry run invoke lint --diff
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
name: Build docs
|
name: Build docs
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,11 @@ repos:
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: forbid-new-submodules
|
- id: forbid-new-submodules
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: 3.9.2
|
rev: v0.1.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: ruff
|
||||||
name: Flake8 on commit diff
|
- id: ruff-format
|
||||||
description: This hook limits Flake8 checks to changed lines of code.
|
args: ["--check"]
|
||||||
entry: bash
|
|
||||||
args: [-c, 'git diff HEAD | flake8 --diff --max-line-length=88']
|
|
||||||
|
|
||||||
exclude: ^pelican/tests/output/
|
exclude: ^pelican/tests/output/
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ def err(msg, die=None):
|
||||||
"""Print an error message and exits if an exit code is given"""
|
"""Print an error message and exits if an exit code is given"""
|
||||||
sys.stderr.write(msg + '\n')
|
sys.stderr.write(msg + '\n')
|
||||||
if die:
|
if die:
|
||||||
sys.exit(die if type(die) is int else 1)
|
sys.exit(die if isinstance(die, int) else 1)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -135,16 +135,16 @@ def themes():
|
||||||
|
|
||||||
def list_themes(v=False):
|
def list_themes(v=False):
|
||||||
"""Display the list of the themes"""
|
"""Display the list of the themes"""
|
||||||
for t, l in themes():
|
for theme_path, link_target in themes():
|
||||||
if not v:
|
if not v:
|
||||||
t = os.path.basename(t)
|
theme_path = os.path.basename(theme_path)
|
||||||
if l:
|
if link_target:
|
||||||
if v:
|
if v:
|
||||||
print(t + (" (symbolic link to `" + l + "')"))
|
print(theme_path + (" (symbolic link to `" + link_target + "')"))
|
||||||
else:
|
else:
|
||||||
print(t + '@')
|
print(theme_path + '@')
|
||||||
else:
|
else:
|
||||||
print(t)
|
print(theme_path)
|
||||||
|
|
||||||
|
|
||||||
def remove(theme_name, v=False):
|
def remove(theme_name, v=False):
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ pytest = "^7.1"
|
||||||
pytest-cov = "^4.0"
|
pytest-cov = "^4.0"
|
||||||
pytest-sugar = "^0.9.5"
|
pytest-sugar = "^0.9.5"
|
||||||
pytest-xdist = "^2.0"
|
pytest-xdist = "^2.0"
|
||||||
|
ruff = "^0.1.3"
|
||||||
tox = {version = "^3.13", optional = true}
|
tox = {version = "^3.13", optional = true}
|
||||||
flake8 = "^3.8"
|
flake8 = "^3.8"
|
||||||
flake8-import-order = "^0.18.1"
|
flake8-import-order = "^0.18.1"
|
||||||
|
|
|
||||||
15
tasks.py
15
tasks.py
|
|
@ -66,13 +66,20 @@ def isort(c, check=False, diff=False):
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def flake8(c):
|
def ruff(c, fix=False, diff=False):
|
||||||
c.run(f"git diff HEAD | {VENV_BIN}/flake8 --diff --max-line-length=88", pty=PTY)
|
"""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
|
@task
|
||||||
def lint(c):
|
def lint(c, fix=False, diff=False):
|
||||||
flake8(c)
|
"""Check code style via linting tools."""
|
||||||
|
ruff(c, fix=fix, diff=diff)
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
|
|
|
||||||
14
tox.ini
14
tox.ini
|
|
@ -30,17 +30,3 @@ filterwarnings =
|
||||||
default::DeprecationWarning
|
default::DeprecationWarning
|
||||||
error:.*:Warning:pelican
|
error:.*:Warning:pelican
|
||||||
addopts = -n auto -r a
|
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
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue