Skip to content

Commit

Permalink
feat(python,rust): build_info() provides detailed information how pol…
Browse files Browse the repository at this point in the history
…ars was built (#5423)
  • Loading branch information
slonik-az authored Nov 6, 2022
1 parent 6e33883 commit 1f45cb4
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 2 deletions.
164 changes: 164 additions & 0 deletions py-polars/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions py-polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ once_cell = "1"
polars-core = { path = "../polars/polars-core", default-features = false }
polars-lazy = { path = "../polars/polars-lazy", features = ["python"], default-features = false }
pyo3 = { version = "0.16", features = ["abi3-py37", "extension-module", "multiple-pymethods"] }
pyo3-built = { version = "0.4", optional = true }
serde_json = { version = "1", optional = true }
thiserror = "^1.0"

Expand Down Expand Up @@ -60,6 +61,7 @@ pivot = ["polars/pivot"]
top_k = ["polars/top_k"]
propagate_nans = ["polars/propagate_nans"]
sql = ["polars/sql"]
build_info = ["dep:pyo3-built", "dep:built"]

all = [
"json",
Expand All @@ -83,6 +85,7 @@ all = [
"object",
"pivot",
"top_k",
"build_info",
# we need to add this, as maturin fails if we don't
# remove this once polars-algo is released
"polars/algo",
Expand Down Expand Up @@ -170,3 +173,6 @@ lto = "fat"
# This is ignored here; would be set in .cargo/config.toml.
# Should not be used when packaging
# target-cpu = "native"

[build-dependencies]
built = { version = "0.5", features = ["chrono", "git2"], optional = true }
19 changes: 19 additions & 0 deletions py-polars/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// Build script using 'built' crate to generate build info.
fn main() {
#[cfg(feature = "build_info")]
{
extern crate built;
use std::env;
use std::path::Path;

let src = env::var("CARGO_MANIFEST_DIR").unwrap();
let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs");
let mut opts = built::Options::default();

opts.set_dependencies(true).set_compiler(true).set_env(true);

built::write_built_file_with_opts(&opts, Path::new(&src), &dst)
.expect("Failed to acquire build-time information");
}
}
5 changes: 3 additions & 2 deletions py-polars/polars/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import warnings

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

from polars.build_info import build_info
from polars.cfg import Config
from polars.convert import (
from_arrow,
Expand Down Expand Up @@ -291,11 +293,10 @@ def version() -> str:
"threadpool_size",
# version
"show_versions",
"build_info",
"SQLContext",
]

__version__ = version()

import os

os.environ["POLARS_ALLOW_EXTENSION"] = "true"
29 changes: 29 additions & 0 deletions py-polars/polars/build_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations

from typing import Any

try:
from polars.polars import version

_version_ = version()
except ImportError:
_version_ = "<missing>"

try:
from polars.polars import _build_info_
except ImportError:
_build_info_ = {}

_build_info_["version"] = _version_


def build_info() -> dict[str, Any]:
"""
Return a dict with polars build information.
If polars was compiled with "build_info" feature gate return the full build info,
otherwise only version is included. The full build information dict contains
the following keys ['build', 'info-time', 'dependencies', 'features', 'host',
'target', 'git', 'version'].
"""
return _build_info_
Loading

0 comments on commit 1f45cb4

Please sign in to comment.