From b92b9a7c11ab07c7e58309a2c74aacfe6f7ca80d Mon Sep 17 00:00:00 2001 From: Mark Gillard Date: Sat, 9 Sep 2023 09:41:09 +0300 Subject: [PATCH] use Python 3.5 `typing` annotations consistently fixes #32 --- .editorconfig | 7 +++++-- .gitattributes | 15 ++++++++------- .github/workflows/ci.yaml | 5 ++++- CHANGELOG.md | 4 ++++ src/poxy/css.py | 8 ++++++-- src/poxy/doxygen.py | 3 ++- src/poxy/emoji.py | 7 ++++--- src/poxy/repos.py | 8 ++++++-- src/poxy/soup.py | 6 ++++-- src/poxy/svg.py | 6 ++++-- src/poxy/version.py | 2 ++ src/poxy/version.txt | 2 +- src/poxy/xml_utils.py | 8 +++++--- 13 files changed, 55 insertions(+), 26 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2094b44..e36bb3d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,10 +10,13 @@ trim_trailing_whitespace = true charset = utf-8 max_line_length = 120 -[*.{gitattributes,yml,vcxproj,vcxproj.filters,sln,rc,clang-format,py}] +[*.{md,markdown}] +trim_trailing_whitespace = false + +[*.{gitattributes,yaml,yml,vcxproj,vcxproj.filters,sln,rc,clang-format,toml,py,cmake}] indent_style = space -[{Doxyfile,Doxyfile-mcss}] +[{Doxyfile,Doxyfile-mcss,CMakeLists.txt}] indent_style = space [*.{hlsl,rc,sln,vcxproj,vcxproj.filters}] diff --git a/.gitattributes b/.gitattributes index 81c6314..e4fc856 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,17 +7,17 @@ *.cs eol=lf diff=csharp -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain *.dot diff=astextplain *.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain *.rtf diff=astextplain *.RTF diff=astextplain +*.doc binary +*.DOC binary +*.docx binary +*.DOCX binary +*.pdf binary +*.PDF binary *.ai binary *.bin binary *.bmp binary @@ -36,5 +36,6 @@ *.xlsx binary */generated/** linguist-generated -*/m.css/** linguist-vendored */tests/test_*/** linguist-generated +*/m.css/** linguist-vendored +*/mcss/** linguist-vendored diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4194d0a..f2f30db 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -57,8 +57,11 @@ jobs: #- "Release_1_9_5" #- "Release_1_9_6" - "none" + os: + - "ubuntu-latest" + - "ubuntu-20.04" - runs-on: ubuntu-latest + runs-on: "${{ matrix.os }}" defaults: run: diff --git a/CHANGELOG.md b/CHANGELOG.md index 55fd1d1..d2054da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.13.8 - 2023-09-09 + +- fixed regression for Python <= 3.8 (#32) (@timjanik) + ## v0.13.7 - 2023-08-17 - fixed minor syntax highlighting issues diff --git a/src/poxy/css.py b/src/poxy/css.py index 898d4d8..3c024e7 100644 --- a/src/poxy/css.py +++ b/src/poxy/css.py @@ -7,13 +7,17 @@ Functions for working with CSS files. """ +from typing import Tuple + from . import paths from .utils import * RX_COMMENT = re.compile(r'''/[*].+?[*]/''', flags=re.DOTALL) RX_IMPORT = re.compile(r'''@import\s+url\(\s*['"]?\s*(.+?)\s*['"]?\s*\)\s*;''', flags=re.I) RX_MCSS_FILENAME = re.compile(r'(?:m|pygments)-[a-z0-9_-]+[.]css$', flags=re.I) -RX_GOOGLE_FONT = re.compile(r'''url\(\s*['"]?(https://fonts[.]gstatic[.]com/[a-z0-9_/%+?:-]+?[.]woff2)['"]?\s*\)''', flags=re.I) +RX_GOOGLE_FONT = re.compile( + r'''url\(\s*['"]?(https://fonts[.]gstatic[.]com/[a-z0-9_/%+?:-]+?[.]woff2)['"]?\s*\)''', flags=re.I +) def strip_comments(text) -> str: @@ -38,7 +42,7 @@ def has_mcss_filename(path) -> bool: return bool(RX_MCSS_FILENAME.match(path)) -def resolve_imports(text, cwd=None, use_cached_fonts=True) -> typing.Tuple[str, bool]: +def resolve_imports(text, cwd=None, use_cached_fonts=True) -> Tuple[str, bool]: if cwd is None: cwd = Path.cwd() cwd = coerce_path(cwd).resolve() diff --git a/src/poxy/doxygen.py b/src/poxy/doxygen.py index a875f3a..e7634c7 100644 --- a/src/poxy/doxygen.py +++ b/src/poxy/doxygen.py @@ -11,6 +11,7 @@ import os import shutil import subprocess +from typing import Tuple from lxml import etree @@ -111,7 +112,7 @@ def test_path(p): return path.val -def version() -> tuple[int, int, int]: +def version() -> Tuple[int, int, int]: if not hasattr(version, "val"): proc = subprocess.run([str(path()), r'--version'], capture_output=True, encoding=r'utf-8', check=True) ret = proc.stdout.strip() if proc.stdout is not None else '' diff --git a/src/poxy/emoji.py b/src/poxy/emoji.py index 714bc9b..d3df9b5 100644 --- a/src/poxy/emoji.py +++ b/src/poxy/emoji.py @@ -8,6 +8,7 @@ """ import json +from typing import Collection, Union from . import paths from .utils import * @@ -38,7 +39,7 @@ def update_database_file(): class Emoji(object): - def __init__(self, key: str, codepoints: typing.Union[int, typing.Collection[int]], uri: str): + def __init__(self, key: str, codepoints: Union[int, Collection[int]], uri: str): self.key = str(key) self.codepoints = [int(cp) for cp in coerce_collection(codepoints)] self.codepoints.sort() @@ -80,14 +81,14 @@ def __init__(self): if key in self.__by_key and alias not in self.__by_key: self.__by_key[alias] = self.__by_key[key] - def __contains__(self, key: typing.Union[int, str]) -> bool: + def __contains__(self, key: Union[int, str]) -> bool: assert key is not None if isinstance(key, int): return key in self.__by_codepoint else: return key.lower().replace(r'-', r'_') in self.__by_key - def __getitem__(self, key: typing.Union[int, str]) -> Emoji: + def __getitem__(self, key: Union[int, str]) -> Emoji: assert key is not None if isinstance(key, int): if key in self.__by_codepoint: diff --git a/src/poxy/repos.py b/src/poxy/repos.py index 5feb801..f4d191c 100644 --- a/src/poxy/repos.py +++ b/src/poxy/repos.py @@ -7,12 +7,14 @@ Functions and classes for working with various source control repositories. """ +from typing import Tuple + from .utils import * RX_REPO_PAIR = re.compile(r"""\s*([a-zA-Z0-9_+.-]+)\s*[/\\:,;|]\s*([a-zA-Z0-9_+.-]+)\s*""") -def extract_user_and_repo(s) -> typing.Tuple[str, str]: +def extract_user_and_repo(s) -> Tuple[str, str]: assert s is not None s = str(s) global RX_REPO_PAIR @@ -38,7 +40,9 @@ def __init__(self, user_and_repo: str): self.issues_uri = rf'{self.uri}/issues' self.pull_requests_uri = rf'{self.uri}/pulls' self.releases_uri = rf'{self.uri}/releases' - self.release_badge_uri = (rf'https://img.shields.io/github/v/release/{self.user}/{self.repository}?style=flat-square',) + self.release_badge_uri = ( + rf'https://img.shields.io/github/v/release/{self.user}/{self.repository}?style=flat-square', + ) self.icon_filename = rf'poxy-icon-{GitHub.KEY}.svg' def __bool__(self) -> bool: diff --git a/src/poxy/soup.py b/src/poxy/soup.py index c8896e2..8f34502 100644 --- a/src/poxy/soup.py +++ b/src/poxy/soup.py @@ -7,6 +7,8 @@ Helpers for working with HTML using BeautifulSoup. """ +from typing import List, Union + import bs4 from .utils import * @@ -126,7 +128,7 @@ def set_class(tag, classes): add_class(tag, classes) -def get_classes(tag) -> list: +def get_classes(tag) -> List[str]: assert tag is not None if 'class' not in tag.attrs: return [] @@ -153,7 +155,7 @@ def has_any_classes(tag, *classes) -> bool: class HTMLDocument(object): - def __init__(self, source: typing.Union[str, Path], logger): + def __init__(self, source: Union[str, Path], logger): self.__logger = logger assert source is not None diff --git a/src/poxy/svg.py b/src/poxy/svg.py index cc4df2b..28b494e 100644 --- a/src/poxy/svg.py +++ b/src/poxy/svg.py @@ -7,6 +7,8 @@ Functions and classes for working with SVG files. """ +from typing import Sequence, Union + from lxml import etree from . import xml_utils @@ -18,11 +20,11 @@ class SVG(object): def __init__( self, # - file_path: typing.Union[Path, str], + file_path: Union[Path, str], logger=None, root_id: str = None, id_namespace: str = None, - root_classes: typing.Union[str, typing.Sequence[str]] = None, + root_classes: Union[str, Sequence[str]] = None, ): # read file svg = read_all_text_from_file(file_path, logger=logger) diff --git a/src/poxy/version.py b/src/poxy/version.py index 80bd68e..9787171 100644 --- a/src/poxy/version.py +++ b/src/poxy/version.py @@ -5,6 +5,7 @@ # SPDX-License-Identifier: MIT from pathlib import Path +from typing import Tuple VERSION = () @@ -13,5 +14,6 @@ assert len(VERSION) == 3 VERSION_STRING = r'.'.join([str(v) for v in VERSION]) +VERSION: Tuple[int, int, int] __all__ = [r'VERSION', r'VERSION_STRING'] diff --git a/src/poxy/version.txt b/src/poxy/version.txt index 5daaa7b..94cade1 100644 --- a/src/poxy/version.txt +++ b/src/poxy/version.txt @@ -1 +1 @@ -0.13.7 +0.13.8 diff --git a/src/poxy/xml_utils.py b/src/poxy/xml_utils.py index 39b2182..a1a65f3 100644 --- a/src/poxy/xml_utils.py +++ b/src/poxy/xml_utils.py @@ -7,6 +7,8 @@ XML utilities - Helpers for working with XML using lxml. """ +from typing import Union + from lxml import etree from .utils import * @@ -34,7 +36,7 @@ def make_child(parent, tag_name: str, **attrs): return etree.SubElement(parent, tag_name, attrib=attrs) -def read(source: typing.Union[str, bytes, Path], parser=None, logger=None): +def read(source: Union[str, bytes, Path], parser=None, logger=None): assert source is not None assert source assert isinstance(source, (str, bytes, Path)) @@ -49,11 +51,11 @@ def read(source: typing.Union[str, bytes, Path], parser=None, logger=None): return etree.fromstring(source, parser=parser) -ElementTypes = typing.Union[etree.ElementBase, etree._Element, etree._ElementTree] +ElementTypes = Union[etree.ElementBase, etree._Element, etree._ElementTree] def write( - source: typing.Union[str, bytes, ElementTypes], + source: Union[str, bytes, ElementTypes], dest: Path, parser=None, logger=None,