Coverage for pydantic/version.py: 100.00%
26 statements
« prev ^ index » next coverage.py v7.5.4, created at 2024-07-03 19:29 +0000
« prev ^ index » next coverage.py v7.5.4, created at 2024-07-03 19:29 +0000
1"""The `version` module holds the version information for Pydantic."""
3from __future__ import annotations as _annotations 1zABCabcdefghDiEFGHjklmnopqUVMNOPQRSTIJKLrstuvwxy
5__all__ = 'VERSION', 'version_info' 1zABCabcdefghDiEFGHjklmnopqUVMNOPQRSTIJKLrstuvwxy
7VERSION = '2.8.0' 1zABCabcdefghDiEFGHjklmnopqUVMNOPQRSTIJKLrstuvwxy
8"""The version of Pydantic.""" 1abcdefghijklmnopqMNOPQRSTrstuvwxy
11def version_short() -> str: 1zABCabcdefghDiEFGHjklmnopqUVMNOPQRSTIJKLrstuvwxy
12 """Return the `major.minor` part of Pydantic version.
14 It returns '2.1' if Pydantic version is '2.1.1'.
15 """
16 return '.'.join(VERSION.split('.')[:2]) 1zABCabcdefghDiEFGHjklmnopqUVMNOPQRSTIJKLrstuvwxy
19def version_info() -> str: 1zABCabcdefghDiEFGHjklmnopqUVMNOPQRSTIJKLrstuvwxy
20 """Return complete version information for Pydantic and its dependencies."""
21 import importlib.metadata as importlib_metadata 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
22 import os 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
23 import platform 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
24 import sys 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
25 from pathlib import Path 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
27 import pydantic_core._pydantic_core as pdc 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
29 from ._internal import _git as git 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
31 # get data about packages that are closely related to pydantic, use pydantic or often conflict with pydantic
32 package_names = { 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
33 'email-validator',
34 'fastapi',
35 'mypy',
36 'pydantic-extra-types',
37 'pydantic-settings',
38 'pyright',
39 'typing_extensions',
40 }
41 related_packages = [] 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
43 for dist in importlib_metadata.distributions(): 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
44 name = dist.metadata['Name'] 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
45 if name in package_names: 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
46 related_packages.append(f'{name}-{dist.version}') 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
48 pydantic_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
49 most_recent_commit = ( 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
50 git.git_revision(pydantic_dir) if git.is_git_repo(pydantic_dir) and git.have_git() else 'unknown'
51 )
53 info = { 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
54 'pydantic version': VERSION,
55 'pydantic-core version': pdc.__version__,
56 'pydantic-core build': getattr(pdc, 'build_info', None) or pdc.build_profile,
57 'install path': Path(__file__).resolve().parent,
58 'python version': sys.version,
59 'platform': platform.platform(),
60 'related packages': ' '.join(related_packages),
61 'commit': most_recent_commit,
62 }
63 return '\n'.join('{:>30} {}'.format(k + ':', str(v).replace('\n', ' ')) for k, v in info.items()) 1zABCabcdefghDiEFGHjklmnopqIJKLrstuvwxy
66def parse_mypy_version(version: str) -> tuple[int, ...]: 1zABCabcdefghDiEFGHjklmnopqUVMNOPQRSTIJKLrstuvwxy
67 """Parse mypy string version to tuple of ints.
69 It parses normal version like `0.930` and extra info followed by a `+` sign
70 like `0.940+dev.04cac4b5d911c4f9529e6ce86a27b44f28846f5d.dirty`.
72 Args:
73 version: The mypy version string.
75 Returns:
76 A tuple of ints. e.g. (0, 930).
77 """
78 return tuple(map(int, version.partition('+')[0].split('.'))) 1UVMNOPQRST