diff --git a/README.md b/README.md index 60a6b8b..047b9c5 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,14 @@ automatically by Travis-CI) pip install pytest python -m pytest +To run the full matrix of Python versions locally, use two commands: + + # old Python versions (via Docker) + docker run --rm -v .:/src -w /src makukha/multipython:unsafe tox run -m old + + # modern Python versions (via uv) + uvx --with tox-uv tox run -m new + Quick Start ----------- diff --git a/mf2util.py b/mf2util.py index 6354d0c..b0015f6 100644 --- a/mf2util.py +++ b/mf2util.py @@ -385,7 +385,7 @@ def do_convert(match): for tagname, attributes in URL_ATTRIBUTES.items(): for attribute in attributes: pattern = re.compile( - '<%s[^>]*?%s\s*=\s*[\'"](.*?)[\'"]' % (tagname, attribute), + r'<%s[^>]*?%s\s*=\s*[\'"](.*?)[\'"]' % (tagname, attribute), flags=re.DOTALL | re.MULTILINE | re.IGNORECASE) html = pattern.sub(do_convert, html) @@ -484,10 +484,10 @@ def parse_datetime(s): if not s: return None - s = re.sub('\s+', ' ', s) - date_re = "(?P\d{4,})-(?P\d{1,2})-(?P\d{1,2})" - time_re = "(?P\d{1,2}):(?P\d{2})(:(?P\d{2})(\.(?P\d+))?)?" - tz_re = "(?PZ)|(?P[+-])(?P\d{1,2}):?(?P\d{2})" + s = re.sub(r'\s+', ' ', s) + date_re = r"(?P\d{4,})-(?P\d{1,2})-(?P\d{1,2})" + time_re = r"(?P\d{1,2}):(?P\d{2})(:(?P\d{2})(\.(?P\d+))?)?" + tz_re = r"(?PZ)|(?P[+-])(?P\d{1,2}):?(?P\d{2})" dt_re = "%s((T| )%s ?(%s)?)?$" % (date_re, time_re, tz_re) m = re.match(dt_re, s) diff --git a/setup.py b/setup.py index 5dd522b..fe830f4 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def run_tests(self): setup(name='mf2util', - version='0.5.2', + version='0.5.2+zegnat.1', description='Python Microformats2 utilities, a companion to mf2py', long_description=""" Microformats2 Utilities diff --git a/tests/test_interpret.py b/tests/test_interpret.py index e134d94..19b32d2 100644 --- a/tests/test_interpret.py +++ b/tests/test_interpret.py @@ -4,12 +4,13 @@ """ from __future__ import unicode_literals from datetime import datetime, date, timedelta +import io import mf2util import json def load_test(testname): - return json.load(open('tests/interpret/%s.json' % testname)) + return json.load(io.open('tests/interpret/%s.json' % testname, encoding='utf-8')) def test_event(): diff --git a/tests/test_post_type_discovery.py b/tests/test_post_type_discovery.py index fffdd54..a169fbe 100644 --- a/tests/test_post_type_discovery.py +++ b/tests/test_post_type_discovery.py @@ -1,6 +1,7 @@ """Tests for post_type_discovery """ +import io import json import mf2util @@ -21,7 +22,7 @@ def test_post_type_discovery(): ('posttype/hcard_org', 'org'), # TODO add more tests ]: - parsed = json.load(open('tests/' + test + '.json')) + parsed = json.load(io.open('tests/' + test + '.json', encoding='utf-8')) types = (['h-card'] if implied_type in ('person', 'org') else ['h-entry', 'h-event']) entry = mf2util.find_first_entry(parsed, types) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..938071e --- /dev/null +++ b/tox.ini @@ -0,0 +1,11 @@ +[tox] +envlist = py27,py35,py36,py37,py38,py39,py310,py311,py312,py313,py314 +labels = + old = py27,py35,py36,py37 + new = py38,py39,py310,py311,py312,py313,py314 + +[testenv] +deps = + pytest + mf2py +commands = pytest tests