Skip to content

Commit

Permalink
build: copier-auto-update
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Jun 24, 2024
1 parent 32ca2f3 commit 571daaa
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Answer file maintained by Copier for: https://github.com/KyleKing/mdformat-plugin-template
# DO NOT MODIFY THIS FILE. Edit by re-running copier and changing responses to the questions
# Check into version control.
_commit: 0.1.4
_commit: 0.2.4
_src_path: gh:KyleKing/mdformat-plugin-template
author_email: dev.act.kyle@gmail.com
author_name: Kyle King
Expand Down
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
Expand All @@ -16,7 +16,7 @@ repos:
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
exclude: \.copier-answers\.yml
exclude: \.copier-answers\.yml|__snapshots__/.*\.ambr
- id: fix-byte-order-marker
- id: fix-encoding-pragma
args: [--remove]
Expand All @@ -26,13 +26,9 @@ repos:
- id: pretty-format-json
args: [--autofix, --indent=4]
- id: trailing-whitespace
exclude: tests/.*fixtures.*\.md
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
exclude: tests/.*fixtures.*\.md|__snapshots__/.*\.ambr
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
rev: v0.4.10
hooks:
- id: ruff
args: [--fix]
Expand All @@ -42,15 +38,18 @@ repos:
hooks:
- id: mdformat
additional_dependencies:
- mdformat-mkdocs[recommended]>=2.0.6
- mdformat-gfm-alerts>=0.0.1
exclude: tests/.+\.md
- mdformat-mkdocs[recommended]>=3.0.0
- mdformat-gfm-alerts>=1.0.1
args: [--wrap=no]
exclude: tests/.+\.md
stages: ["pre-commit"]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
stages: ["pre-commit"]
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: toml-sort-fix
stages: ["pre-commit"]
69 changes: 0 additions & 69 deletions .ruff.toml

This file was deleted.

11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Development

## API Documentation

A collection of useful resources to reference when developing new features:

- [`markdown-it-py` documentation](https://markdown-it-py.readthedocs.io/en/latest/using.html)
- [`markdown-it` (JS) documentation](https://markdown-it.github.io/markdown-it)

## Local Development

This package utilizes [flit](https://flit.readthedocs.io) as the build engine, and [tox](https://tox.readthedocs.io) for test automation.

To install these development dependencies:
Expand All @@ -25,7 +34,7 @@ The easiest way to write tests, is to edit `tests/fixtures.md`
To run the code formatting and style checks:

```bash
tox -e py38-pre-commit
tox -e py312-pre-commit
```

or directly
Expand Down
2 changes: 2 additions & 0 deletions mdformat_gfm_alerts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
__version__ = "1.0.1"

from .plugin import RENDERERS, update_mdit

__all__ = ("RENDERERS", "update_mdit")
7 changes: 7 additions & 0 deletions mdformat_gfm_alerts/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
new_token,
parse_possible_blockquote_admon_factory,
)

__all__ = (
"AlertData",
"gfm_alerts_plugin_factory",
"new_token",
"parse_possible_blockquote_admon_factory",
)
14 changes: 10 additions & 4 deletions mdformat_gfm_alerts/factories/_gfm_blockquote_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@

from markdown_it import MarkdownIt
from markdown_it.rules_block import StateBlock
from markdown_it.rules_inline import StateInline
from mdit_py_plugins.utils import is_code_block

if TYPE_CHECKING:
from markdown_it.token import Token


# FYI: copied from mdformat_admon.factories
# https://github.com/KyleKing/mdformat-admon/blob/43c54ed39124161abded0f2b632aa906450077cc/mdformat_admon/factories/_whitespace_admon_factories.py#L180-L187
@contextmanager
def new_token(state: StateBlock, name: str, kind: str) -> Generator[Token, None, None]:
"""Creates scoped token."""
def new_token(
state: StateBlock | StateInline,
name: str,
kind: str,
) -> Generator[Token, None, None]:
"""Create scoped token."""
yield state.push(f"{name}_open", kind, 1)
state.push(f"{name}_close", kind, -1)

Expand All @@ -35,8 +41,8 @@ def new_token(state: StateBlock, name: str, kind: str) -> Generator[Token, None,
class AlertState(NamedTuple):
"""Frozen state."""

parentType: str
lineMax: int
parentType: str # noqa: N815
lineMax: int # noqa: N815


class AlertData(NamedTuple):
Expand Down
2 changes: 2 additions & 0 deletions mdformat_gfm_alerts/mdit_plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from ._gfm_alerts import GFM_ALERTS_PREFIX, format_gfm_alerts_markup, gfm_alerts_plugin

__all__ = ("GFM_ALERTS_PREFIX", "format_gfm_alerts_markup", "gfm_alerts_plugin")
10 changes: 5 additions & 5 deletions mdformat_gfm_alerts/mdit_plugins/_gfm_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from markdown_it.rules_block import StateBlock

from ..factories import (
from mdformat_gfm_alerts.factories import (
AlertData,
gfm_alerts_plugin_factory,
new_token,
Expand Down Expand Up @@ -71,15 +71,15 @@ def format_gfm_alerts_markup(

def alert_logic(
state: StateBlock,
startLine: int,
endLine: int,
start_line: int,
end_line: int,
silent: bool,
) -> bool:
"""Parse GitHub Alerts."""
parser_func = parse_possible_blockquote_admon_factory(GFM_ALERTS_PREFIX, PATTERNS)
result = parser_func(state, startLine, endLine, silent)
result = parser_func(state, start_line, end_line, silent)
if isinstance(result, AlertData):
format_gfm_alerts_markup(state, startLine, admonition=result)
format_gfm_alerts_markup(state, start_line, admonition=result)
return True
return result

Expand Down
Empty file added mdformat_gfm_alerts/py.typed
Empty file.
87 changes: 82 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"mdformat >= 0.7.16",
"mdit-py-plugins >= 0.4.0",
"mdformat >= 0.7.17",
"mdit-py-plugins >= 0.4.1",
]
dynamic = ["description", "version"]
keywords = ["markdown", "markdown-it", "mdformat"]
keywords = ["markdown", "markdown-it", "mdformat", "mdformat_plugin_template"]
name = "mdformat_gfm_alerts"
readme = "README.md"
requires-python = ">=3.8.0"
requires-python = ">=3.8.5"

[project.entry-points."mdformat.parser_extension"]
gfm_alerts = "mdformat_gfm_alerts"
Expand All @@ -34,18 +34,95 @@ test = [
]

[project.urls]
"Bug Tracker" = "https://github.com/kyleking/mdformat-gfm-alerts/issues"
"Changelog" = "https://github.com/kyleking/mdformat-gfm-alerts/releases"
homepage = "https://github.com/kyleking/mdformat-gfm-alerts"

[tool.flit.sdist]
exclude = [".github/", "tests/"]
include = []

[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
enable_error_code = ["ignore-without-code", "possibly-undefined", "redundant-expr", "truthy-bool"]
extra_checks = true
files = ["mdformat_gfm_alerts", "tests"]
no_implicit_reexport = true
python_version = "3.8"
show_column_numbers = true
show_error_codes = true
strict_equality = true
warn_no_return = true
warn_redundant_casts = true
warn_unreachable = true
warn_unused_configs = true
warn_unused_ignores = true

[tool.pyright]
include = ["mdformat_gfm_alerts", "tests"]
pythonVersion = "3.8"

[tool.pytest-watcher]
ignore_patterns = []
now = true
patterns = ["*.md", "*.py"]
runner = "tox"
runner_args = ["-e", "py38-beartype"]
runner_args = ["-e", "py312-beartype"]

[tool.ruff]
# Docs: https://github.com/charliermarsh/ruff
# Tip: poetry run python -m ruff --explain RUF100
line-length = 88
target-version = 'py38'

[tool.ruff.lint]
ignore = [
'ANN002', # Missing type annotation for `*args`
'ANN003', # Missing type annotation for `**kwargs`
'ANN101', # Missing type annotation for `self` in method (automatically inferred)
'ANN102', # Missing type annotation for `cls` in classmethod (automatically inferred)
'BLE001', # Do not catch blind exception: `Exception`
'CPY001', # Missing copyright notice at top of file
'D203', # "1 blank line required before class docstring" (Conflicts with D211)
'D213', # "Multi-line docstring summary should start at the second line" (Conflicts with D212)
'EM101', # Exception must not use a string literal, assign to variable first
'FBT001', # Boolean-typed positional argument in function definition
'FIX001', # Line contains FIXME
'FIX002', # Line contains TODO
'FIX004', # Line contains HACK
'PLR0913', # Too many arguments in function definition (6 > 5)
'TCH002', # Move third-party import `mdformat.renderer.typing.Postprocess` into a type-checking block (for beartype)
'TCH003', # Move standard library import `argparse` into a type-checking block (for beartype)
'TD001', # Invalid TODO tag: `FIXME`
'TD002', # Missing author in TODO; try: `# TODO(<author_name>): ...`
'TD003', # Missing issue link on the line following this TODO
'TRY003', # Avoid specifying long messages outside the exception class
]
preview = true
select = ['ALL']
unfixable = [
'ERA001', # Commented out code
]

[tool.ruff.lint.isort]
known-first-party = ['mdformat_gfm_alerts', 'tests']

[tool.ruff.lint.per-file-ignores]
'__init__.py' = [
'D104', # Missing docstring in public package
]
'tests/*.py' = [
'ANN001', # Missing type annotation for function argument
'ANN201', # Missing return type annotation for public function
'ANN202', # Missing return type annotation for private function `test_make_diffable`
'ARG001', # Unused function argument: `line`
'D100', # Missing docstring in public module
'D103', # Missing docstring in public function
'PLC2701', # Private name import `_<>` from external module
'PT004', # flake8-pytest-style: fixture does not return
'S101', # Use of `assert` detected
]

[tool.tomlsort]
all = true
Expand Down
14 changes: 14 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Ignore beartype warnings from tests."""

from contextlib import suppress

with suppress(ImportError): # Only suppress beartype warnings when installed
from warnings import filterwarnings

from beartype.roar import (
BeartypeClawDecorWarning, # Too many False Positives using NamedTuples
BeartypeDecorHintPep585DeprecationWarning,
)

filterwarnings("ignore", category=BeartypeClawDecorWarning)
filterwarnings("ignore", category=BeartypeDecorHintPep585DeprecationWarning)
2 changes: 1 addition & 1 deletion tests/format/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from markdown_it.utils import read_fixture_file

from ..helpers import print_text
from tests.helpers import print_text

FIXTURE_PATH = Path(__file__).parent / "fixtures.md"
fixtures = read_fixture_file(FIXTURE_PATH)
Expand Down
Loading

0 comments on commit 571daaa

Please sign in to comment.