From 7dfc799f255815de1665e257a93987598aab95f4 Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Sat, 28 Oct 2023 10:44:39 -0700 Subject: [PATCH 1/5] Use ruff in pre-commit --- .pre-commit-config.yaml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c0c85b00..f68521e5f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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/ From 58fd8553850a161f1656599f4d0d40f43eefbf82 Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Sat, 28 Oct 2023 10:54:09 -0700 Subject: [PATCH 2/5] inv task now uses ruff --- pyproject.toml | 1 + tasks.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 826c11799..b3eaa0d14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tasks.py b/tasks.py index 148899c79..d41e2955d 100644 --- a/tasks.py +++ b/tasks.py @@ -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 From 6cf6a1ffe97b23074cf4e8c223fb6174d4092ae4 Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Sat, 28 Oct 2023 10:58:41 -0700 Subject: [PATCH 3/5] Ruff lint fixes --- pelican/tools/pelican_themes.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pelican/tools/pelican_themes.py b/pelican/tools/pelican_themes.py index 96d07c1f5..b8bf1be2e 100755 --- a/pelican/tools/pelican_themes.py +++ b/pelican/tools/pelican_themes.py @@ -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): From 29b10ef6e640f017757fd0afeb67dcd607cf2e75 Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Sat, 28 Oct 2023 11:02:06 -0700 Subject: [PATCH 4/5] Use poetry directly in lints --- .github/workflows/main.yml | 16 ++++++++++------ tox.ini | 14 -------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0ffd9c61..b59c53160 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 + - name: Run linters + run: poetry run invoke lint --diff docs: name: Build docs diff --git a/tox.ini b/tox.ini index c31044ca4..361c52dd0 100644 --- a/tox.ini +++ b/tox.ini @@ -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 From 33d6712e8b1283354b305ea73ac0ee3331092dfc Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Sat, 28 Oct 2023 11:18:24 -0700 Subject: [PATCH 5/5] Don't install pelican's dependencies to lint --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b59c53160..b477cecb7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -73,7 +73,7 @@ jobs: - name: Install dependencies run: | poetry env use "3.9" - poetry install --no-interaction + poetry install --no-interaction --no-root - name: Run linters run: poetry run invoke lint --diff