Skip to content

add build_info to _pydantic_core #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/pydantic_core/_pydantic_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ from _typeshed import SupportsAllComparisons
__all__ = [
'__version__',
'build_profile',
'build_info',
'_recursion_limit',
'ArgsKwargs',
'SchemaValidator',
Expand All @@ -45,6 +46,7 @@ __all__ = [
]
__version__: str
build_profile: str
build_info: str
_recursion_limit: int

_T = TypeVar('_T', default=Any, covariant=True)
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ pub fn get_version() -> String {
version.replace("-alpha", "a").replace("-beta", "b")
}

pub fn build_info() -> String {
format!(
"profile={} pgo={} mimalloc={}",
env!("PROFILE"),
option_env!("RUSTFLAGS").unwrap_or("").contains("-Cprofile-use="),
cfg!(feature = "mimalloc")
)
}

#[pymodule]
fn _pydantic_core(py: Python, m: &PyModule) -> PyResult<()> {
m.add("__version__", get_version())?;
m.add("build_profile", env!("PROFILE"))?;
m.add("build_info", build_info())?;
m.add("_recursion_limit", recursion_guard::RECURSION_GUARD_LIMIT)?;
m.add("PydanticUndefined", PydanticUndefinedType::new(py))?;
m.add_class::<PydanticUndefinedType>()?;
Expand Down
13 changes: 12 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
from typing_extensions import get_args

from pydantic_core import CoreSchema, CoreSchemaType, PydanticUndefined, core_schema
from pydantic_core._pydantic_core import SchemaError, SchemaValidator, ValidationError, __version__, build_profile
from pydantic_core._pydantic_core import (
SchemaError,
SchemaValidator,
ValidationError,
__version__,
build_info,
build_profile,
)


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


def test_build_info():
assert isinstance(build_info, str)


def test_schema_error():
err = SchemaError('test')
assert isinstance(err, Exception)
Expand Down