Skip to content

Commit 1af1574

Browse files
authored
chore: modernize py3 versions (#21)
- Add support for Python 3.8, 3.9, 3.10, 3.11 and 3.12. - Drop support for 2.7, 3.4, 3.5, 3.6 and 3.7. - Update distribution packaging (``pyproject.toml``). - Update test runner to ``pytest``. - Refactor tests using ``pytest`` patterns. - Remove 'peppercorn.compat' module - Add Github workflow CI
1 parent e2dd963 commit 1af1574

10 files changed

Lines changed: 463 additions & 271 deletions

File tree

.github/workflows/ci-tests.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Build and test
2+
3+
on:
4+
# Build only on pushes to main or one of the release branches
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
# Build pull requests
10+
pull_request:
11+
12+
jobs:
13+
test:
14+
strategy:
15+
matrix:
16+
py:
17+
- "3.8"
18+
- "3.9"
19+
- "3.10"
20+
- "3.11"
21+
- "3.12"
22+
- "pypy-3.10"
23+
os:
24+
- "ubuntu-latest"
25+
architecture:
26+
- x64
27+
include:
28+
# Only run coverage on ubuntu-latest, except on pypy3
29+
- os: "ubuntu-latest"
30+
pytest-args: "--cov"
31+
- os: "ubuntu-latest"
32+
py: "pypy-3.7"
33+
pytest-args: ""
34+
name: "Python: ${{ matrix.py }}-${{ matrix.architecture }} on ${{ matrix.os }}"
35+
runs-on: ${{ matrix.os }}
36+
steps:
37+
- uses: actions/checkout@v2
38+
- name: Setup python
39+
uses: actions/setup-python@v4
40+
with:
41+
python-version: ${{ matrix.py }}
42+
architecture: ${{ matrix.architecture }}
43+
- run: pip install --upgrade setuptools pip
44+
- run: pip install tox
45+
- name: Running tox
46+
run: tox -e py -- ${{ matrix.pytest-args }}
47+
coverage:
48+
runs-on: ubuntu-latest
49+
name: Validate coverage
50+
steps:
51+
- uses: actions/checkout@v2
52+
- name: Setup python
53+
uses: actions/setup-python@v4
54+
with:
55+
python-version: 3.12
56+
architecture: x64
57+
- run: pip install --upgrade setuptools pip
58+
- run: |
59+
pip install tox
60+
tox -e py312-cover,coverage
61+
docs:
62+
runs-on: ubuntu-latest
63+
name: Build the documentation
64+
steps:
65+
- uses: actions/checkout@v2
66+
- name: Setup python
67+
uses: actions/setup-python@v4
68+
with:
69+
python-version: 3.12
70+
architecture: x64
71+
- run: pip install --upgrade setuptools pip
72+
- run: |
73+
pip install tox
74+
tox -e docs

CHANGES.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
Changes
22
=======
33

4+
0.7 (unreleased)
5+
----------------
6+
7+
- Add Github workflow CI.
8+
9+
- Update distribution packaging (``pyproject.toml``).
10+
11+
- Update test runner to ``pytest``.
12+
13+
- Refactor tests using ``pytest`` patterns.
14+
15+
- Add support for Python 3.8, 3.9, 3.10, 3.11 and 3.12.
16+
17+
- Drop support for 2.7, 3.4, 3.5, 3.6 and 3.7.
18+
19+
- Remove the ``pytest.compat`` module.
20+
21+
422
0.6 (2018-08-24)
523
----------------
624

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# out serve to show the default value.
1414

1515
import datetime
16-
import pkg_resources
16+
from importlib import metadata
1717
import pylons_sphinx_themes
1818

1919

@@ -36,7 +36,7 @@
3636

3737
# Add any Sphinx extension module names here, as strings. They can be
3838
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
39-
extensions = ['sphinx.ext.autodoc']
39+
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest']
4040

4141
# Add any paths that contain templates here, relative to this directory.
4242
templates_path = ['.templates']
@@ -57,7 +57,7 @@
5757
# other places throughout the built documents.
5858
#
5959
# The short X.Y version.
60-
version = pkg_resources.get_distribution('peppercorn').version
60+
version = metadata.version('peppercorn')
6161
# The full version, including alpha/beta/rc tags.
6262
release = version
6363

peppercorn/__init__.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11

2-
def data_type(value):
3-
if ':' in value:
4-
return [ x.strip() for x in value.rsplit(':', 1) ]
5-
return ('', value.strip())
6-
72
START = '__start__'
83
END = '__end__'
94
SEQUENCE = 'sequence'
@@ -13,6 +8,30 @@ def data_type(value):
138
TYPS = (SEQUENCE, MAPPING, RENAME, IGNORE)
149

1510

11+
def data_type(value):
12+
if ':' in value:
13+
return [ x.strip() for x in value.rsplit(':', 1) ]
14+
return ('', value.strip())
15+
16+
17+
class UnknownStartMarker(ValueError):
18+
def __init__(self, token):
19+
self.token = token
20+
super().__init__(
21+
f"Unknown start marker {repr(token)}"
22+
)
23+
24+
25+
class TooManyEndMarkers(ValueError):
26+
def __init__(self):
27+
super().__init__("Too many end markers")
28+
29+
30+
class NotEnoughEndMarkers(ValueError):
31+
def __init__(self):
32+
super().__init__("Not enough end markers")
33+
34+
1635
def parse(tokens):
1736
""" Infer a data structure from the ordered set of fields and
1837
return it."""
@@ -28,7 +47,7 @@ def parse(tokens):
2847
if typ in TYPS:
2948
out = []
3049
else:
31-
raise ValueError("Unknown start marker %s" % repr(token))
50+
raise UnknownStartMarker(token)
3251
elif key == END:
3352
if typ == SEQUENCE:
3453
parsed = [v for (k, v) in out]
@@ -39,7 +58,7 @@ def parse(tokens):
3958
elif typ == IGNORE:
4059
parsed = None
4160
else:
42-
raise ValueError("Too many end markers")
61+
raise TooManyEndMarkers()
4362
prev_target, prev_typ, out = stack.pop()
4463
if parsed is not None:
4564
out.append((target, parsed))
@@ -49,6 +68,6 @@ def parse(tokens):
4968
out.append(token)
5069

5170
if stack:
52-
raise ValueError("Not enough end markers")
71+
raise NotEnoughEndMarkers()
5372

5473
return dict(out)

peppercorn/compat.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)