Skip to content

Commit

Permalink
Merge pull request #3223 from offbyone/switch-to-ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayer committed Oct 28, 2023
2 parents 85bf982 + 33d6712 commit 269751b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 38 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/main.yml
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions .pre-commit-config.yaml
Expand Up @@ -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/
14 changes: 7 additions & 7 deletions pelican/tools/pelican_themes.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -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"
Expand Down
15 changes: 11 additions & 4 deletions tasks.py
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions tox.ini
Expand Up @@ -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

0 comments on commit 269751b

Please sign in to comment.