Coverage for src/prisma/cli/commands/version.py: 96%
21 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
1import json
2from typing import List
3from pathlib import Path
4from importlib import import_module
6import click
8from ... import config, __version__
9from ..utils import pretty_info
10from ...binaries.platform import binary_platform
13@click.command('version', short_help='Display Prisma Client Python version information.')
14@click.option(
15 '--json',
16 'output_json',
17 is_flag=True,
18 help='Output version information in JSON format.',
19)
20def cli(output_json: bool) -> None:
21 """Display Prisma Client Python version information."""
22 extras = {
23 'dev': 'nox',
24 'docs': 'mkdocs',
25 }
26 installed: List[str] = []
27 for extra, module in extras.items():
28 try:
29 import_module(module)
30 except ImportError:
31 continue
32 else:
33 installed.append(extra)
35 info = {
36 'prisma': config.prisma_version,
37 'prisma client python': __version__,
38 'platform': binary_platform(),
39 'expected engine version': config.expected_engine_version,
40 'installed extras': installed,
41 'install path': str(Path(__file__).resolve().parent.parent.parent),
42 'binary cache dir': str(config.binary_cache_dir),
43 }
45 if output_json:
46 click.echo(json.dumps({k.replace(' ', '-'): v for k, v in info.items()}, indent=2))
47 else:
48 click.echo(pretty_info(info))