From 206d78cca3711f0b83afa6ee4a827a0bf239066c Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sat, 3 Feb 2024 22:52:56 +0100 Subject: [PATCH] Template upgrade --- .github/workflows/autofix.yml | 29 +++++++++++++++++ .github/workflows/ci.yml | 10 ++---- .github/workflows/deploy-docs.yml | 2 +- .github/workflows/deploy-release.yml | 2 +- .tools/copier-answers.yml | 2 +- markdown_callouts/callouts.py | 8 ++--- markdown_callouts/github_callouts.py | 4 +-- pyproject.toml | 48 ++++++++++++++++------------ requirements/requirements-style.txt | 8 +++++ setup.py | 13 -------- tests/test_extension.py | 2 +- 11 files changed, 78 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/autofix.yml create mode 100644 requirements/requirements-style.txt delete mode 100644 setup.py diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml new file mode 100644 index 0000000..636f30a --- /dev/null +++ b/.github/workflows/autofix.yml @@ -0,0 +1,29 @@ +name: Auto-fix +on: + push: + pull_request: +jobs: + style: + runs-on: ubuntu-latest + steps: + - name: Download source + uses: actions/checkout@v4 + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install Hatch + run: | + pip install hatch + - name: Install dependencies + run: | + hatch run style:pip freeze + - name: Fix code style + run: | + hatch run style:fix --fix-only + - name: Check if any edits are necessary + run: | + git diff --color --exit-code + - name: Apply automatic fixes using pre-commit-ci-lite + if: failure() && github.event_name == 'pull_request' + uses: pre-commit-ci/lite-action@v1.0.1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92dc81f..6887eaa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - name: Download source uses: actions/checkout@v4 - name: Install Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{matrix.python}} - name: Pin to lowest versions @@ -55,7 +55,7 @@ jobs: - name: Download source uses: actions/checkout@v4 - name: Install Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.12' - name: Install Hatch @@ -68,11 +68,7 @@ jobs: - name: Check style if: always() run: | - hatch run style:fix - - name: Check formatting - if: always() - run: | - git diff --color --exit-code + hatch run style:check - name: Check types if: always() run: | diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 5cd52ba..c99bfbe 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -11,7 +11,7 @@ jobs: - name: Download source uses: actions/checkout@v4 - name: Install Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install dependencies diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml index 3446498..44fed5b 100644 --- a/.github/workflows/deploy-release.yml +++ b/.github/workflows/deploy-release.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.12' - name: Install dependencies diff --git a/.tools/copier-answers.yml b/.tools/copier-answers.yml index 08c584c..2268cc7 100644 --- a/.tools/copier-answers.yml +++ b/.tools/copier-answers.yml @@ -1,4 +1,4 @@ -_commit: 7d6f4ceea +_commit: 0903da199 _src_path: gh:oprypin/py-project-template copyright_date: '2021' mkdocs: true diff --git a/markdown_callouts/callouts.py b/markdown_callouts/callouts.py index f18402d..e1e6de7 100644 --- a/markdown_callouts/callouts.py +++ b/markdown_callouts/callouts.py @@ -11,14 +11,14 @@ # Based on https://github.com/Python-Markdown/markdown/blob/4acb949256adc535d6e6cd84c4fb47db8dda2f46/markdown/blockprocessors.py#L277 class _CalloutsBlockProcessor(BlockQuoteProcessor): - REGEX = re.compile(r"(^ {0,3}>([!?])? ?|\A)([A-Z]{2,}):([ \n])(.*)", flags=re.M) + REGEX = re.compile(r"(^ {0,3}>([!?])? ?|\A)([A-Z]{2,}):([ \n])(.*)", flags=re.MULTILINE) def test(self, parent: etree.Element, block: str) -> bool: m = self.REGEX.search(block) return ( m is not None and (m[1] or not self.parser.state.isstate("blockquote")) - and not util.nearing_recursion_limit() # type: ignore + and not util.nearing_recursion_limit() ) def run(self, parent: etree.Element, blocks: list[str]) -> None: @@ -142,7 +142,7 @@ def __init__(self, **kwargs) -> None: super().__init__(**kwargs) def extendMarkdown(self, md: Markdown) -> None: - parser = md.parser # type: ignore + parser = md.parser parser.blockprocessors.register( _CalloutsBlockProcessor(parser), "callouts", @@ -155,4 +155,4 @@ def extendMarkdown(self, md: Markdown) -> None: ) -makeExtension = CalloutsExtension +makeExtension = CalloutsExtension # NOQA: N816 diff --git a/markdown_callouts/github_callouts.py b/markdown_callouts/github_callouts.py index 8a310e9..dfb3f5f 100644 --- a/markdown_callouts/github_callouts.py +++ b/markdown_callouts/github_callouts.py @@ -46,7 +46,7 @@ def run(self, parent: etree.Element, blocks: list[str]) -> None: class GitHubCalloutsExtension(Extension): def extendMarkdown(self, md: Markdown) -> None: - parser = md.parser # type: ignore + parser = md.parser parser.blockprocessors.register( _GitHubCalloutsBlockProcessor(parser), "github-callouts", @@ -54,4 +54,4 @@ def extendMarkdown(self, md: Markdown) -> None: ) -makeExtension = GitHubCalloutsExtension +makeExtension = GitHubCalloutsExtension # NOQA: N816 diff --git a/pyproject.toml b/pyproject.toml index f355fa2..7f80b2f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,7 @@ include = ["/markdown_callouts", "/tests"] [tool.hatch.env] requires = [ "hatch-mkdocs", - "hatch-pip-compile", + "hatch-pip-compile >=1.7.0", ] [tool.hatch.envs.default.scripts] @@ -72,7 +72,7 @@ dependencies = [ ] [tool.hatch.envs.test.scripts] test = [ - "pytest -q", + "pytest -q {args}", ] [tool.hatch.envs.types] @@ -81,46 +81,54 @@ dependencies = [ "types-Markdown >=3.4.2", ] [tool.hatch.envs.types.scripts] -check = [ - "mypy markdown_callouts" -] +check = "mypy {args} markdown_callouts" [tool.hatch.envs.style] -skip-install = true +type = "pip-compile" +detached = true dependencies = [ "ruff", ] [tool.hatch.envs.style.scripts] +check = "ruff check markdown_callouts tests {args}" +format = "ruff format -q markdown_callouts tests" fix = [ - "ruff check --fix markdown_callouts tests", + "check --fix --unsafe-fixes", "format", ] -format = [ - "ruff format -q markdown_callouts tests", -] [tool.hatch.env.collectors.mkdocs.docs] [tool.hatch.envs.docs] type = "pip-compile" -pip-compile-hashes = false detached = false [tool.ruff] line-length = 100 +[tool.ruff.lint] +preview = true select = [ - "I", - "F", "W", "E", "UP", "YTT", "C4", "DTZ", "FA", "ISC", "PIE", "T20", "RSE", "TCH", - "B002", "B003", "B005", "B007", "B009", "B012", "B013", "B014", "B015", "B018", "B020", "B021", "B023", "B026", "B033", "B034", "B905", + "F", "E", "W", "I", "UP", "YTT", "C4", "DTZ", "T10", "FA", "ISC", "PIE", "T20", "RSE", "TCH", + "N803", "N804", "N805", "N806", "N807", "N815", "N816", "N999", + "B002", "B003", "B005", "B007", "B008", "B009", "B010", "B011", "B012", "B013", "B014", "B015", "B016", "B017", "B018", "B020", "B021", "B022", "B023", "B025", "B026", "B029", "B030", "B031", "B032", "B033", "B034", "B035", "B905", "COM818", - "PERF101", - "PGH002", "PGH004", "PGH005", + "G001", "G010", "G202", + "Q004", + "RET502", "RET504", + "SIM101", "SIM103", "SIM105", "SIM107", "SIM118", "SIM201", "SIM202", "SIM208", "SIM210", "SIM211", "SIM212", "SIM220", "SIM221", "SIM222", "SIM223", "SIM300", "SIM401", "SIM910", "SIM911", + "PGH003", "PGH004", "PGH005", + "PLC0105", "PLC0131", "PLC0132", "PLC0205", "PLC0208", "PLC0414", "PLC2401", "PLC2403", "PLC2701", "PLC2801", "PLC3002", + "PLE0100", "PLE0101", "PLE0116", "PLE0117", "PLE0118", "PLE0241", "PLE0302", "PLE0307", "PLE0604", "PLE0605", "PLE0704", "PLE1132", "PLE1142", "PLE1205", "PLE1206", "PLE1300", "PLE1307", "PLE1310", "PLE1507", "PLE1700", "PLE2502", "PLE2510", "PLE2512", "PLE2513", "PLE2514", "PLE2515", + "PLR0124", "PLR0133", "PLR0206", "PLR0402", "PLR1701", "PLR1722", "PLR1733", "PLR1736", + "PLW0108", "PLW0120", "PLW0127", "PLW0129", "PLW0131", "PLW0245", "PLW0406", "PLW0602", "PLW0603", "PLW0604", "PLW0711", "PLW1501", "PLW1508", "PLW1514", "PLW2101", "PLW3301", + "TRY302", "TRY401", "FLY002", - "PLC", "PLE", "PLR0124", "PLR0133", "PLR0206", "PLR0402", "PLR1701", "PLR1722", "PLW0120", "PLW0127", "PLW0129", "PLW0131", "PLW0406", "PLW0602", "PLW0603", "PLW0711", - "RUF001", "RUF005", "RUF007", "RUF010", "RUF013", "RUF100", "RUF200", - "SIM101", "SIM107", "SIM201", "SIM202", "SIM208", "SIM210", "SIM211", "SIM300", "SIM401", "SIM910", + "PERF101", "PERF102", "PERF402", "PERF403", + "FURB105", "FURB118", "FURB131", "FURB132", "FURB148", "FURB163", "FURB167", "FURB168", "FURB169", + "LOG001", "LOG009", + "RUF001", "RUF005", "RUF007", "RUF008", "RUF009", "RUF010", "RUF013", "RUF015", "RUF016", "RUF017", "RUF018", "RUF019", "RUF020", "RUF021", "RUF022", "RUF100", "RUF200", ] ignore = ["E501", "E731"] -[tool.ruff.flake8-comprehensions] +[tool.ruff.lint.flake8-comprehensions] allow-dict-calls-with-keyword-arguments = true [tool.mypy] diff --git a/requirements/requirements-style.txt b/requirements/requirements-style.txt new file mode 100644 index 0000000..103d940 --- /dev/null +++ b/requirements/requirements-style.txt @@ -0,0 +1,8 @@ +# +# This file is autogenerated by hatch-pip-compile with Python 3.11 +# +# - ruff +# + +ruff==0.2.0 + # via hatch.envs.style diff --git a/setup.py b/setup.py deleted file mode 100644 index c591feb..0000000 --- a/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -"""Installation using setup.py is not supported. -Use `pip install .` instead.""" - -import sys - -from setuptools import setup - -sys.exit(__doc__) - -# Fake reference so GitHub still considers it a real package for statistics purposes. -setup( - name="markdown-callouts", -) diff --git a/tests/test_extension.py b/tests/test_extension.py index fcf5173..72eb78c 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -25,5 +25,5 @@ def test_extension(request, golden): output = md.convert(golden["input"]) soup = bs4.BeautifulSoup(output, features="html.parser") html = soup.prettify().rstrip("\n") - html = re.sub(r"^( *)", r"\1\1", html, flags=re.M) + html = re.sub(r"^( *)", r"\1\1", html, flags=re.MULTILINE) assert html == golden.out["output"]