diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c0ffd9c6..b477cecb 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 --no-root + - name: Run linters + run: poetry run invoke lint --diff docs: name: Build docs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c0c85b0..f68521e5 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/ diff --git a/pelican/tools/pelican_themes.py b/pelican/tools/pelican_themes.py index 47f1a625..1ad3a333 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): diff --git a/pyproject.toml b/pyproject.toml index 826c1179..b3eaa0d1 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 e4268ec6..efdef8a4 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 diff --git a/tox.ini b/tox.ini index c31044ca..361c52dd 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