Skip to content

Commit

Permalink
feat: drop support of python 3.7 (#194)
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Jun 12, 2024
1 parent 17d54eb commit 2ffb6b8
Show file tree
Hide file tree
Showing 27 changed files with 59 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: [frostming]# Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: [frostming]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", 3.11, 3.12]
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: [3.8, 3.9, "3.10", 3.11, 3.12, 3.13]
os: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- python-version: 3.8
os: macos-latest
- python-version: 3.9
os: macos-latest
include:
- python-version: 3.8
os: macos-13
- python-version: 3.9
os: macos-13

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
cache: true
allow-python-prereleases: true

- name: Install dependencies
run: pdm install -G toc -G codehilite
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ repos:
- id: fix-future-annotations

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.4.2
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
rev: v1.10.0
hooks:
- id: mypy
exclude: ^docs/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

Marko is a pure Python markdown parser that adheres to the specifications of [CommonMark's spec v0.30][spec]. It has been designed with high extensibility in mind, as detailed in the [Extensions](#extensions) section.

Marko requires Python 3.7 or higher.
Marko requires Python 3.8 or higher.

## Why Marko

Expand Down
1 change: 1 addition & 0 deletions marko/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Licensed under MIT.
Created by Frost Ming<[email protected]>
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Iterable, cast
Expand Down
1 change: 1 addition & 0 deletions marko/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Licensed under MIT.
Created by Frost Ming<[email protected]>
"""

from . import cli

if __name__ == "__main__":
Expand Down
16 changes: 7 additions & 9 deletions marko/ast_renderer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
AST renderers for inspecting the markdown parsing result.
"""

from __future__ import annotations

import html
Expand Down Expand Up @@ -35,23 +36,20 @@ class ASTRenderer(Renderer):
def render_raw_text(self, element: inline.RawText) -> dict[str, Any]:
return {
"element": "raw_text",
"children": html.unescape(element.children)
if element.escape
else element.children,
"children": (
html.unescape(element.children) if element.escape else element.children
),
"escape": element.escape,
}

@overload
def render_children(self, element: list[Element]) -> list[dict[str, Any]]:
...
def render_children(self, element: list[Element]) -> list[dict[str, Any]]: ...

@overload
def render_children(self, element: Element) -> dict[str, Any]:
...
def render_children(self, element: Element) -> dict[str, Any]: ...

@overload
def render_children(self, element: str) -> str:
...
def render_children(self, element: str) -> str: ...

def render_children(self, element):
if isinstance(element, list):
Expand Down
1 change: 1 addition & 0 deletions marko/block.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Block level elements
"""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions marko/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Command line interfaces
"""

import codecs
import importlib
import sys
Expand Down
6 changes: 5 additions & 1 deletion marko/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def get_type(cls, snake_case: bool = False) -> str:
"""

# Prevent override of BlockElement and InlineElement
if cls.override and cls.__base__ not in Element.__subclasses__():
if (
cls.override
and cls.__base__
and cls.__base__ not in Element.__subclasses__()
):
name = cls.__base__.__name__
else:
name = cls.__name__
Expand Down
1 change: 1 addition & 0 deletions marko/ext/codehilite.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
markdown = Markdown(extensions=['codehilite'])
markdown.convert('```python filename="my_script.py"\nprint('hello world')\n```')
"""

import json

from pygments import highlight
Expand Down
1 change: 1 addition & 0 deletions marko/ext/gfm/elements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Extra elements
"""

from __future__ import annotations

import itertools
Expand Down
6 changes: 3 additions & 3 deletions marko/ext/gfm/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def render_paragraph(self, element):

@render_dispatch(HTMLRenderer)
def render_strikethrough(self, element):
return "<del>{}</del>".format(self.render_children(element))
return f"<del>{self.render_children(element)}</del>"

@render_strikethrough.dispatch(MarkdownRenderer)
def render_strikethrough(self, element):
Expand All @@ -57,7 +57,7 @@ def render_html_block(self, element):
@render_dispatch(HTMLRenderer)
def render_table(self, element):
head, *body = element.children
theader = "<thead>\n{}</thead>".format(self.render(head))
theader = f"<thead>\n{self.render(head)}</thead>"
tbody = ""
if body:
tbody = "\n<tbody>\n{}</tbody>".format(
Expand All @@ -77,7 +77,7 @@ def render_table(self, element):

@render_dispatch(HTMLRenderer)
def render_table_row(self, element):
return "<tr>\n{}</tr>\n".format(self.render_children(element))
return f"<tr>\n{self.render_children(element)}</tr>\n"

@render_table_row.dispatch(MarkdownRenderer)
def render_table_row(self, element):
Expand Down
1 change: 1 addition & 0 deletions marko/ext/latex_renderer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
LaTeX renderer
"""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions marko/ext/pangu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
markdown = Markdown(extensions=['pangu'])
print(markdown(text))
"""

import re

from marko import HTMLRenderer
Expand Down
1 change: 1 addition & 0 deletions marko/ext/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
print(markdown.renderer.render_toc())
"""

import re

from slugify import slugify
Expand Down
7 changes: 3 additions & 4 deletions marko/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Helper functions and data structures
"""

from __future__ import annotations

import dataclasses
Expand Down Expand Up @@ -169,12 +170,10 @@ def super_render(self, r: Any, element: Element) -> Any:
raise NotImplementedError(f"Unsupported renderer {type(r)}") from None

@overload
def __get__(self: D, obj: None, owner: type) -> D:
...
def __get__(self: D, obj: None, owner: type) -> D: ...

@overload
def __get__(self: D, obj: Renderer, owner: type) -> RendererFunc:
...
def __get__(self: D, obj: Renderer, owner: type) -> RendererFunc: ...

def __get__(self: D, obj: Renderer | None, owner: type) -> RendererFunc | D:
if obj is None:
Expand Down
1 change: 1 addition & 0 deletions marko/html_renderer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
HTML renderer
"""

from __future__ import annotations

import html
Expand Down
1 change: 1 addition & 0 deletions marko/inline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Inline(span) level elements
"""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions marko/inline_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Parse inline elements
"""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions marko/md_renderer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Markdown renderer
"""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions marko/parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Base parser
"""

from __future__ import annotations

import itertools
Expand Down
1 change: 1 addition & 0 deletions marko/patterns.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Some regex patterns
"""

import re

tags = [
Expand Down
1 change: 1 addition & 0 deletions marko/renderer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Base renderer class
"""

from __future__ import annotations

import html
Expand Down
8 changes: 3 additions & 5 deletions marko/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _expect_re(self, regexp: Pattern[str] | str, pos: int) -> Match[str] | None:
return regexp.match(self._buffer, pos)

@staticmethod
@functools.lru_cache()
@functools.lru_cache
def match_prefix(prefix: str, line: str) -> int:
"""Check if the line starts with given prefix and
return the position of the end of prefix.
Expand Down Expand Up @@ -112,12 +112,10 @@ def expect_re(self, regexp: Pattern[str] | str) -> Match[str] | None:
return None

@overload
def next_line(self, require_prefix: Literal[False] = ...) -> str:
...
def next_line(self, require_prefix: Literal[False] = ...) -> str: ...

@overload
def next_line(self, require_prefix: Literal[True] = ...) -> str | None:
...
def next_line(self, require_prefix: Literal[True] = ...) -> str | None: ...

def next_line(self, require_prefix: bool = True) -> str | None:
"""Return the next line in the source.
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
{name = "Frost Ming", email = "[email protected]"},
]
dynamic = ["version"]
requires-python = ">=3.7"
requires-python = ">=3.8"
license = {text = "MIT"}
dependencies = []
description = "A markdown parser with high extensibility."
Expand All @@ -20,7 +20,6 @@ classifiers = [
"Intended Audience :: Developers",
'Operating System :: OS Independent',
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exclude_lines =
if TYPE_CHECKING:

[flake8]
ignore = E203,E501,W503,W504,W605,E741
ignore = E203,E501,W503,W504,W605,E741,E704

[mypy-tests.*]
ignore_errors = True
Expand Down

0 comments on commit 2ffb6b8

Please sign in to comment.