Skip to content

Commit 1f45cb4

Browse files
authored
feat(python,rust): build_info() provides detailed information how polars was built (#5423)
1 parent 6e33883 commit 1f45cb4

File tree

7 files changed

+247
-2
lines changed

7 files changed

+247
-2
lines changed

py-polars/Cargo.lock

Lines changed: 164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py-polars/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ once_cell = "1"
3131
polars-core = { path = "../polars/polars-core", default-features = false }
3232
polars-lazy = { path = "../polars/polars-lazy", features = ["python"], default-features = false }
3333
pyo3 = { version = "0.16", features = ["abi3-py37", "extension-module", "multiple-pymethods"] }
34+
pyo3-built = { version = "0.4", optional = true }
3435
serde_json = { version = "1", optional = true }
3536
thiserror = "^1.0"
3637

@@ -60,6 +61,7 @@ pivot = ["polars/pivot"]
6061
top_k = ["polars/top_k"]
6162
propagate_nans = ["polars/propagate_nans"]
6263
sql = ["polars/sql"]
64+
build_info = ["dep:pyo3-built", "dep:built"]
6365

6466
all = [
6567
"json",
@@ -83,6 +85,7 @@ all = [
8385
"object",
8486
"pivot",
8587
"top_k",
88+
"build_info",
8689
# we need to add this, as maturin fails if we don't
8790
# remove this once polars-algo is released
8891
"polars/algo",
@@ -170,3 +173,6 @@ lto = "fat"
170173
# This is ignored here; would be set in .cargo/config.toml.
171174
# Should not be used when packaging
172175
# target-cpu = "native"
176+
177+
[build-dependencies]
178+
built = { version = "0.5", features = ["chrono", "git2"], optional = true }

py-polars/build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// Build script using 'built' crate to generate build info.
2+
3+
fn main() {
4+
#[cfg(feature = "build_info")]
5+
{
6+
extern crate built;
7+
use std::env;
8+
use std::path::Path;
9+
10+
let src = env::var("CARGO_MANIFEST_DIR").unwrap();
11+
let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs");
12+
let mut opts = built::Options::default();
13+
14+
opts.set_dependencies(true).set_compiler(true).set_env(true);
15+
16+
built::write_built_file_with_opts(&opts, Path::new(&src), &dst)
17+
.expect("Failed to acquire build-time information");
18+
}
19+
}

py-polars/polars/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import warnings
23

34
try:
@@ -10,6 +11,7 @@ def version() -> str:
1011
# this is only useful for documentation
1112
warnings.warn("polars binary missing!")
1213

14+
from polars.build_info import build_info
1315
from polars.cfg import Config
1416
from polars.convert import (
1517
from_arrow,
@@ -291,11 +293,10 @@ def version() -> str:
291293
"threadpool_size",
292294
# version
293295
"show_versions",
296+
"build_info",
294297
"SQLContext",
295298
]
296299

297300
__version__ = version()
298301

299-
import os
300-
301302
os.environ["POLARS_ALLOW_EXTENSION"] = "true"

py-polars/polars/build_info.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
try:
6+
from polars.polars import version
7+
8+
_version_ = version()
9+
except ImportError:
10+
_version_ = "<missing>"
11+
12+
try:
13+
from polars.polars import _build_info_
14+
except ImportError:
15+
_build_info_ = {}
16+
17+
_build_info_["version"] = _version_
18+
19+
20+
def build_info() -> dict[str, Any]:
21+
"""
22+
Return a dict with polars build information.
23+
24+
If polars was compiled with "build_info" feature gate return the full build info,
25+
otherwise only version is included. The full build information dict contains
26+
the following keys ['build', 'info-time', 'dependencies', 'features', 'host',
27+
'target', 'git', 'version'].
28+
"""
29+
return _build_info_

0 commit comments

Comments
 (0)