Skip to content

Commit e69fcda

Browse files
sphuberchrisjsewellpre-commit-ci[bot]
authored
⬆️ Add support for Python 3.12 (chrisjsewell#41)
Co-authored-by: Chris Sewell <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent cf99555 commit e69fcda

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
os: [ubuntu-latest]
30-
python-version: ['3.8', '3.9', '3.10', '3.11']
30+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
3131

3232
runs-on: ${{ matrix.os }}
3333

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ classifiers = [
1919
"Programming Language :: Python :: 3.9",
2020
"Programming Language :: Python :: 3.10",
2121
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
2223
"Programming Language :: Python :: Implementation :: CPython",
2324
"Operating System :: OS Independent",
2425
"License :: OSI Approved :: BSD License",
@@ -27,6 +28,7 @@ requires-python = "~=3.8"
2728
dependencies = [
2829
"pytest>=3.5.0",
2930
"attrs<23,>=19",
31+
"importlib-metadata~=6.0;python_version<'3.10'",
3032
"importlib-resources~=5.0;python_version<'3.9'",
3133
"nbclient~=0.5.10",
3234
"nbdime",

pytest_notebook/plugin.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
- https://docs.pytest.org/en/latest/_modules/_pytest/hookspec.html
1212
1313
"""
14-
from distutils.util import strtobool as _str2bool
1514
import os
1615
import shlex
1716

@@ -135,7 +134,26 @@ def str2bool(string):
135134
"""
136135
if isinstance(string, bool):
137136
return string
138-
return bool(_str2bool(string))
137+
138+
_map = {
139+
"y": True,
140+
"yes": True,
141+
"t": True,
142+
"true": True,
143+
"on": True,
144+
"1": True,
145+
"n": False,
146+
"no": False,
147+
"f": False,
148+
"false": False,
149+
"off": False,
150+
"0": False,
151+
}
152+
153+
try:
154+
return _map[string.lower()]
155+
except KeyError:
156+
raise ValueError(f'"{string}" is not a valid bool value')
139157

140158

141159
def strip_quotes(string):

pytest_notebook/post_processors.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
from typing import Tuple
1212

1313
from nbformat import NotebookNode
14-
import pkg_resources
14+
15+
try:
16+
# python <= 3.9
17+
from importlib_metadata import entry_points
18+
except ImportError:
19+
from importlib.metadata import entry_points
1520

1621
logger = logging.getLogger(__name__)
1722

@@ -21,22 +26,19 @@
2126
@functools.lru_cache()
2227
def list_processor_names():
2328
"""List entry point names for post-processors."""
24-
return [ep.name for ep in pkg_resources.iter_entry_points(ENTRY_POINT_NAME)]
29+
return [ep.name for ep in entry_points().select(group=ENTRY_POINT_NAME)]
2530

2631

2732
@functools.lru_cache()
2833
def load_processor(name: str):
2934
"""Get a post-processors for an entry point name."""
30-
matches = [
31-
ep
32-
for ep in pkg_resources.iter_entry_points(ENTRY_POINT_NAME)
33-
if ep.name == name
34-
]
35-
if not matches:
35+
try:
36+
(entry_point,) = entry_points().select(group=ENTRY_POINT_NAME, name=name)
37+
except ValueError:
3638
raise ValueError(
3739
"entry point '{}' for group '{}' not found".format(name, ENTRY_POINT_NAME)
3840
)
39-
return matches[0].load()
41+
return entry_point.load()
4042

4143

4244
def document_processors():

0 commit comments

Comments
 (0)