Skip to content

Commit

Permalink
Upgrade to ruff for lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
fliiiix committed Oct 8, 2024
1 parent 2c72fa9 commit fa92cce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
python-version: 3.13
- name: Setup and install tools
run: |
python -m pip install --upgrade black flake8
- name: black format check
run: python -m black --check --line-length 120 pandoc_plantuml_filter.py tests
- name: flake8 format check
run: python -m flake8 --max-line-length 120 pandoc_plantuml_filter.py tests
python -m pip install --upgrade ruff
- name: format check
run: python -m ruff format --check
- name: lint check
run: python -m ruff check
test:
strategy:
fail-fast: false
Expand Down
7 changes: 3 additions & 4 deletions pandoc_plantuml_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
"""

import os
import sys
import subprocess
import sys

from pandocfilters import toJSONFilter, Para, Image
from pandocfilters import get_filename4code, get_caption, get_extension
from pandocfilters import Image, Para, get_caption, get_extension, get_filename4code, toJSONFilter

PLANTUML_BIN = os.environ.get("PLANTUML_BIN", "plantuml")

Expand Down Expand Up @@ -66,7 +65,7 @@ def plantuml(key, value, format_, meta):
with open(src, "wb") as f:
f.write(txt)

subprocess.check_call(PLANTUML_BIN.split() + ["-t" + filetype, src])
subprocess.check_call([*PLANTUML_BIN.split(), "-t" + filetype, src])
sys.stderr.write("Created image " + dest + "\n")

# Update symlink each run
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ dynamic = ["version"]
[project.scripts]
pandoc-plantuml = "pandoc_plantuml_filter:main"

[tool.ruff]
line-length = 120
# Rule descriptions: https://docs.astral.sh/ruff/rules/
lint.select = ["I", "E", "B", "F", "W", "N", "C4", "C90", "ARG", "PL", "RUF", "UP"]

[tool.setuptools_scm]
7 changes: 3 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import re
import subprocess

from pathlib import Path

import pytest
Expand Down Expand Up @@ -39,7 +38,7 @@ def test_digrams(tmp_path, filename, expected_content, expected_files):
input_file = str(__TEST_BASE_DIR__ / f"{filename}.md")
output_file = str(tmp_path / f"{filename}.tex")

cmd = subprocess.run(["pandoc", input_file, "-o", output_file, "--filter", "pandoc-plantuml"])
cmd = subprocess.run(["pandoc", input_file, "-o", output_file, "--filter", "pandoc-plantuml"], check=False)
assert cmd.returncode == 0

with open(output_file) as f:
Expand All @@ -56,7 +55,7 @@ def test_filetype_param_from_meta(tmp_path):
input_file = str(__TEST_BASE_DIR__ / "single-diagram-with-meta.md")
output_file = str(tmp_path / "single-diagram-with-meta.tex")

cmd = subprocess.run(["pandoc", input_file, "-o", output_file, "--filter", "pandoc-plantuml"])
cmd = subprocess.run(["pandoc", input_file, "-o", output_file, "--filter", "pandoc-plantuml"], check=False)
assert cmd.returncode == 0

with open(output_file) as f:
Expand All @@ -72,7 +71,7 @@ def test_filetype_metadata_is_overridden_from_cli(tmp_path):
output_file = str(tmp_path / "single-diagram-with-meta.tex")
args = ["--metadata=plantuml-format:jpg"]

cmd = subprocess.run(["pandoc", input_file, "-o", output_file, "--filter", "pandoc-plantuml"] + args)
cmd = subprocess.run(["pandoc", input_file, "-o", output_file, "--filter", "pandoc-plantuml", *args], check=False)
assert cmd.returncode == 0

with open(output_file) as f:
Expand Down

0 comments on commit fa92cce

Please sign in to comment.