Coverage for src/prisma/cli/commands/dev.py: 54%
22 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
1from typing import Any, Optional, cast
3import click
5from .. import options
6from ..utils import error, generate_client
7from ...utils import module_exists, maybe_async_run, temp_env_update
10@click.group()
11def _cli() -> None:
12 """Commands for developing Prisma Client Python"""
15# There are some weird false positives that `cli` being a `Group` introduces
16# for some reason. Fixing the errors for one type checker causes errors in an another
17# so just switch to Any for the time being as this is internal and only used once, directly
18# below this line.
19cli: Any = cast(Any, _cli)
22@cli.command() # type: ignore[misc]
23@options.schema
24@options.skip_generate
25def playground(schema: Optional[str], skip_generate: bool) -> None:
26 """Run the GraphQL playground"""
27 if skip_generate and not module_exists('prisma.client'): 27 ↛ 30line 27 didn't jump to line 30, because the condition on line 27 was never false
28 error('Prisma Client Python has not been generated yet.')
29 else:
30 generate_client(schema=schema, reload=True)
32 # TODO: this assumes we are generating to the same location that we are being invoked from
33 from ... import Prisma
34 from ...engine import QueryEngine
36 client = Prisma()
37 engine_class = client._engine_class
38 if engine_class.__name__ == 'QueryEngine':
39 with temp_env_update({'__PRISMA_PY_PLAYGROUND': '1'}):
40 maybe_async_run(client.connect)
42 # TODO: this is the result of a badly designed class
43 engine = cast(QueryEngine, client._engine)
44 assert engine.process is not None, 'Engine process unavailable for some reason'
45 engine.process.wait()
46 else: # pragma: no cover
47 error(f'Unsupported engine type: "{engine_class}"')