-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(python,rust): build_info() provides detailed information how polars was built #5423
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of code-specific questions and suggestions (Python only).
On a high level, the most important question: why not integrate this information in pl.show_versions
?
And could you add an example output here (and in the docstring), so we know what we are talking about?
py-polars/polars/show_versions.py
Outdated
|
||
|
||
build_info = _closure_() | ||
del _closure_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would the method need to be deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_closure_
should be called only once. After it is deleted it cannot be called at all. Otherwise a user can call it again as
from polars.show_versions import _closure_
_closure_()
Python unfortunately does not have proper private visibility. Closures is the only way to emulate private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to refactor the code. _closure_
is gone altogether and code is simplified.
def build_info():
moved from polars/show_versions.py
into polars/build_info.py
to avoid any confusion with show_versions()
. Pushed PR update.
def test_build_info() -> None: | ||
build_info = pl.build_info() | ||
features = build_info.get("features", {}) | ||
if features: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we can test both branches here somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code already tests both branches:
- When
build_info
feature gate in enabledfeatures
field is populated and tested for presence ofBUILD_INFO
feature - Otherwise without
build_info
feature the only element present in dictionary isversion
and its presence is tested in theelse
part of the code (line 18, not shown in the snippet).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved testing code into test_build_info.py
file.
py-polars/polars/show_versions.py
Outdated
return build_info | ||
|
||
|
||
build_info = _closure_() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason to run this on import polars
? Why not leave as a method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a function at the same level as show_versions
and version
. If changing to method, of what class?
py-polars/polars/show_versions.py
Outdated
@@ -69,3 +70,36 @@ def _get_dep_version(dep_name: str) -> str: | |||
|
|||
# all our dependencies (as of 2022-08-11) implement __version__ | |||
return module_version | |||
|
|||
|
|||
def _closure_() -> _typing_.Callable[[], _typing_.Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method name could be more descriptive. I propose to call this build_info
, and import this method directly in __init__.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is already called build_info
. Closure _closure_
is here to create a private scope and initiate private variables that build_info()
returns. Closure executed once and then deleted. This is standard way to overcome python's limitation of not having proper private or static variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_closure_()
is gone now. See the updated PR.
py-polars/polars/show_versions.py
Outdated
@@ -3,6 +3,7 @@ | |||
import importlib | |||
import platform | |||
import sys | |||
import typing as _typing_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not do from typing import Callable, Any
? The underscores are not needed either?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I will change it and import only specific elements of typing
.
To avoid confusion with |
Good call. I will show structure of the output in the docstring. The returned dictionary is large (it lists all 200+ polars rust dependencies and their versions). For brevity, I will include partial output. |
…ars was built (implements pola-rs#5422) [new functionality is behind `build_info` feature gate] `polars.build_info()` returns dictionary with hierarchically organized information about how this polars was built -- features enabled, dependencies and their versions, compilation details, optimization/debug flags, rustc version, git commit information, and more. This information is useful when troubleshooting polars deployments.
Many thanks to @zundertj for insightful comments/suggestions.
Refactored python code per code review. Many thanks to @zundertj for insightful comments/suggestions. Also rebased the PR onto the latest master. |
@slonik-az : one thing I should have mentioned: could you also add an entry to this function in the Python API reference? I know this one is merged, but in a new PR. |
Thanks @slonik-az for the PR and thank you @zundertj for the review. |
Will do. |
Done in PR #5442 |
(resolves #5422)
[new functionality is behind
build_info
feature gate]polars.build_info()
returns dictionary with hierarchically organized information about how this polars was built -- features enabled, dependencies and their versions, compilation details, optimization/debug flags, rustc version, git commit information, and more.This information is useful when troubleshooting
polars
deployments.