Skip to content

Commit

Permalink
use Python 3.5 typing annotations consistently
Browse files Browse the repository at this point in the history
fixes #32
  • Loading branch information
marzer committed Sep 9, 2023
1 parent 2a7b351 commit b92b9a7
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 26 deletions.
7 changes: 5 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
Expand Down
15 changes: 8 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,5 +36,6 @@
*.xlsx binary

*/generated/** linguist-generated
*/m.css/** linguist-vendored
*/tests/test_*/** linguist-generated
*/m.css/** linguist-vendored
*/mcss/** linguist-vendored
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/poxy/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/poxy/doxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import shutil
import subprocess
from typing import Tuple

from lxml import etree

Expand Down Expand Up @@ -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 ''
Expand Down
7 changes: 4 additions & 3 deletions src/poxy/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import json
from typing import Collection, Union

from . import paths
from .utils import *
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions src/poxy/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions src/poxy/soup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Helpers for working with HTML using BeautifulSoup.
"""

from typing import List, Union

import bs4

from .utils import *
Expand Down Expand Up @@ -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 []
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/poxy/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/poxy/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: MIT

from pathlib import Path
from typing import Tuple

VERSION = ()

Expand All @@ -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']
2 changes: 1 addition & 1 deletion src/poxy/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.7
0.13.8
8 changes: 5 additions & 3 deletions src/poxy/xml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
XML utilities - Helpers for working with XML using lxml.
"""

from typing import Union

from lxml import etree

from .utils import *
Expand Down Expand Up @@ -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))
Expand All @@ -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,
Expand Down

0 comments on commit b92b9a7

Please sign in to comment.