-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: Added display modes for show_runtime
#26255
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
Open
ganesh-k13
wants to merge
4
commits into
numpy:main
Choose a base branch
from
ganesh-k13:show_runtime_modes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
30dd1ec
ENH: Added display modes for `show_runtime`
ganesh-k13 9c89a44
TYP: Added typing for modified `show_runtime`
ganesh-k13 525373d
DOC: Display modes for `show_runtime` (#26255)
ganesh-k13 4f36145
TST: Fixed existing tests that used display modes
ganesh-k13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
`np.show_runtime` has display modes | ||
----------------------------------- | ||
|
||
`np.show_runtime` now has a new optional parameter ``mode`` to help | ||
customize the output. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from enum import Enum | ||
|
||
|
||
class ConfigDisplayModes(Enum): | ||
stdout = "stdout" | ||
dicts = "dicts" | ||
|
||
|
||
def cleanup_empty_dict_values(d): | ||
""" | ||
Removes empty values in a `dict` recursively | ||
This ensures we remove values that Meson could not provide to CONFIG | ||
""" | ||
if isinstance(d, dict): | ||
return { | ||
k: cleanup_empty_dict_values(v) | ||
for k, v in d.items() | ||
if v and cleanup_empty_dict_values(v) | ||
} | ||
else: | ||
return d | ||
|
||
|
||
def check_pyyaml(): | ||
import yaml | ||
|
||
return yaml | ||
|
||
|
||
def print_or_return_config(mode, config): | ||
if mode == ConfigDisplayModes.stdout.value: | ||
try: # Non-standard library, check import | ||
yaml = check_pyyaml() | ||
|
||
print(yaml.dump(config)) | ||
except ModuleNotFoundError: | ||
import warnings | ||
import json | ||
|
||
warnings.warn("Install `pyyaml` for better output", stacklevel=1) | ||
print(json.dumps(config, indent=2)) | ||
elif mode == ConfigDisplayModes.dicts.value: | ||
return config | ||
else: | ||
raise AttributeError( | ||
"Invalid `mode`, use one of: " | ||
f"{', '.join([e.value for e in ConfigDisplayModes])}" | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@BvB93 / @mattip / @rgommers , just curious, how did the UT not catch this? I went over the typing UT but didn't quite get how it's not failing. Should we add some tests?
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 answer to that question is pretty much always "yes, if they are not slow and complicated"
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'll take this up in a following PR. It's a bit hard to navigate the
typing
tests.