Skip to content

Commit 0b31711

Browse files
authored
add build_info to _pydantic_core (#749)
1 parent 964066b commit 0b31711

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

python/pydantic_core/_pydantic_core.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ from _typeshed import SupportsAllComparisons
2222
__all__ = [
2323
'__version__',
2424
'build_profile',
25+
'build_info',
2526
'_recursion_limit',
2627
'ArgsKwargs',
2728
'SchemaValidator',
@@ -45,6 +46,7 @@ __all__ = [
4546
]
4647
__version__: str
4748
build_profile: str
49+
build_info: str
4850
_recursion_limit: int
4951

5052
_T = TypeVar('_T', default=Any, covariant=True)

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,20 @@ pub fn get_version() -> String {
4343
version.replace("-alpha", "a").replace("-beta", "b")
4444
}
4545

46+
pub fn build_info() -> String {
47+
format!(
48+
"profile={} pgo={} mimalloc={}",
49+
env!("PROFILE"),
50+
option_env!("RUSTFLAGS").unwrap_or("").contains("-Cprofile-use="),
51+
cfg!(feature = "mimalloc")
52+
)
53+
}
54+
4655
#[pymodule]
4756
fn _pydantic_core(py: Python, m: &PyModule) -> PyResult<()> {
4857
m.add("__version__", get_version())?;
4958
m.add("build_profile", env!("PROFILE"))?;
59+
m.add("build_info", build_info())?;
5060
m.add("_recursion_limit", recursion_guard::RECURSION_GUARD_LIMIT)?;
5161
m.add("PydanticUndefined", PydanticUndefinedType::new(py))?;
5262
m.add_class::<PydanticUndefinedType>()?;

tests/test_misc.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
from typing_extensions import get_args
77

88
from pydantic_core import CoreSchema, CoreSchemaType, PydanticUndefined, core_schema
9-
from pydantic_core._pydantic_core import SchemaError, SchemaValidator, ValidationError, __version__, build_profile
9+
from pydantic_core._pydantic_core import (
10+
SchemaError,
11+
SchemaValidator,
12+
ValidationError,
13+
__version__,
14+
build_info,
15+
build_profile,
16+
)
1017

1118

1219
@pytest.mark.parametrize('obj', [ValidationError, SchemaValidator, SchemaError])
@@ -23,6 +30,10 @@ def test_build_profile():
2330
assert build_profile in ('debug', 'release')
2431

2532

33+
def test_build_info():
34+
assert isinstance(build_info, str)
35+
36+
2637
def test_schema_error():
2738
err = SchemaError('test')
2839
assert isinstance(err, Exception)

0 commit comments

Comments
 (0)