Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 3803bc6

Browse files
feat(python): add support for v3.12 (#762)
This is just essentially adding tests & a classifier. The only notable change is to avoid a deprecation warning in `prisma_cleanup`.
1 parent 6b5a5f0 commit 3803bc6

File tree

7 files changed

+13
-30
lines changed

7 files changed

+13
-30
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
fail-fast: false
2525
matrix:
2626
os: [ubuntu-latest, windows-latest]
27-
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
27+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
2828
include:
2929
- os: ubuntu-latest
3030
python-version: "3.10"

pipelines/test.nox.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pipelines.utils.prisma import generate
77

88

9-
@nox.session(python=['3.7', '3.8', '3.9', '3.10', '3.11'])
9+
@nox.session(python=['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'])
1010
def test(session: nox.Session) -> None:
1111
setup_env(session)
1212
session.install('-r', 'pipelines/requirements/test.txt')

scripts/ci.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'3.9': '3.9',
99
'3.10': '3.10',
1010
'3.11': '3.11',
11+
'3.12': '3.12',
1112
}
1213

1314

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def requirements(name: str) -> List[str]:
9090
'Programming Language :: Python :: 3.9',
9191
'Programming Language :: Python :: 3.10',
9292
'Programming Language :: Python :: 3.11',
93+
'Programming Language :: Python :: 3.12',
9394
'Operating System :: POSIX',
9495
'Operating System :: MacOS',
9596
'Operating System :: POSIX :: Linux',

src/prisma_cleanup/_cleanup.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
2-
import pkgutil
32
from pathlib import Path
3+
from importlib.util import find_spec
44
from typing_extensions import Protocol, runtime_checkable
55

66
PRISMA_INIT_CONTENTS = "__title__ = 'prisma'"
@@ -24,14 +24,14 @@ def main(*args: str) -> None:
2424
def cleanup(pkg_name: str = 'prisma') -> None:
2525
"""Remove python files that are auto-generated by Prisma Client Python"""
2626

27-
# pkgutil.get_loader() can return a loader that doesn't have access to
28-
# the packages source location. We should provide an easy to understand error
29-
# for this case even if it is incredibly unlikey (if not impossible)
30-
# to happen in our use case
31-
loader = pkgutil.get_loader(pkg_name) # pyright: ignore[reportDeprecated]
32-
if loader is None:
27+
spec = find_spec(pkg_name)
28+
if spec is None:
3329
raise RuntimeError(f'Could not resolve package: {pkg_name}')
3430

31+
loader = spec.loader
32+
if loader is None:
33+
raise RuntimeError(f'No loader defined for: {pkg_name}')
34+
3535
if not isinstance(loader, SourceLoader):
3636
raise RuntimeError(f'Received unresolvable import loader: {loader}')
3737

tests/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
prisma.register(Prisma())
2727

28+
pytest.register_assert_rewrite('tests.test_generation.utils')
29+
2830

2931
@pytest.fixture()
3032
def runner(monkeypatch: 'MonkeyPatch') -> Runner:

tests/test_generation/test_prisma_cleanup.py

-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import sys
2-
import pkgutil
32
import subprocess
4-
from typing import TYPE_CHECKING
53

64
import pytest
75
from prisma_cleanup import cleanup
@@ -12,9 +10,6 @@
1210
from .utils import assert_module_is_clean, assert_module_not_clean
1311
from ..utils import Testdir
1412

15-
if TYPE_CHECKING:
16-
from _pytest.monkeypatch import MonkeyPatch
17-
1813

1914
def test_main(testdir: Testdir) -> None:
2015
"""Main entrypoint"""
@@ -58,22 +53,6 @@ def test_main_works_with_erroneous_client(testdir: Testdir) -> None:
5853
assert_module_is_clean(path)
5954

6055

61-
def test_unresolvable_loader(monkeypatch: 'MonkeyPatch') -> None:
62-
"""pkgutil.get_loader() can return a loader that doesn't have access to
63-
the packages source location.
64-
"""
65-
66-
def patched_get_loader(pkg: str) -> object:
67-
return 'Dummy'
68-
69-
monkeypatch.setattr(pkgutil, 'get_loader', patched_get_loader)
70-
71-
with pytest.raises(RuntimeError) as exc:
72-
cleanup()
73-
74-
assert exc.value.args[0] == 'Received unresolvable import loader: Dummy'
75-
76-
7756
def test_custom_package(testdir: Testdir) -> None:
7857
"""Cleaning up custom package location"""
7958
path = testdir.path / 'app' / 'prisma'

0 commit comments

Comments
 (0)