Coverage for src/prisma/__init__.py: 93%
26 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1# -*- coding: utf-8 -*-
3__title__ = 'prisma'
4__author__ = 'RobertCraigie'
5__license__ = 'APACHE'
6__copyright__ = 'Copyright 2020-2023 RobertCraigie'
7__version__ = '0.15.0'
9from typing import TYPE_CHECKING
11from . import errors as errors
12from .utils import setup_logging
13from ._types import PrismaMethod as PrismaMethod
14from ._config import config as config
15from ._metrics import (
16 Metric as Metric,
17 Metrics as Metrics,
18 MetricHistogram as MetricHistogram,
19)
20from .validator import *
22# the import ordering is important here because
23# we rely on the fact that `prisma/client.py` is the
24# first piece of generated code that is loaded. This is
25# especially useful for `python -m prisma_cleanup`
26try:
27 from .client import * # noqa: I001, TID251
28 from .fields import * # noqa: TID251
29 from . import (
30 bases as bases, # noqa: TID251
31 types as types, # noqa: TID251
32 models as models, # noqa: TID251
33 partials as partials, # noqa: TID251
34 )
35except ModuleNotFoundError:
36 # code has not been generated yet
37 # TODO: this could swallow unexpected errors
39 # we only define this magic function when the client has not
40 # been generated for performance reasons and we hide it from
41 # type checkers so that they don't incidentally disable type
42 # checking due to the dynamic nature of the `__getattr__`
43 # magic dunder method.
44 if not TYPE_CHECKING:
46 def __getattr__(name: str):
47 try:
48 return globals()[name]
49 except KeyError as err:
50 # TODO: support checking for 'models' here too
51 if name in {'Prisma', 'Client'}: 51 ↛ 53line 51 didn't jump to line 53, because the condition on line 51 was never true
52 # TODO: remove this frame from the stack trace
53 raise RuntimeError(
54 "The Client hasn't been generated yet, "
55 'you must run `prisma generate` before you can use the client.\n'
56 'See https://prisma-client-py.readthedocs.io/en/stable/reference/troubleshooting/#client-has-not-been-generated-yet'
57 ) from None
59 # leaves handling of this potential error to Python as per PEP 562
60 raise AttributeError() from err
63setup_logging()