FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Don't expose private styles in style.available by QuLogic · Pull Request #30235 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 4 additions & 3 deletions lib/matplotlib/style/__init__.py
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
Expand Up @@ -6,7 +6,8 @@
``context``
Context manager to use a style sheet temporarily.
``available``
List available style sheets.
List available style sheets. Underscore-prefixed names are considered private and
not listed, though may still be accessed directly from ``library``.
``library``
A dictionary of style names and matplotlib settings.
"""
Expand Down Expand Up @@ -245,8 +246,8 @@ def update_nested_dict(main_dict, new_dict):
def reload_library():
"""Reload the style library."""
library.clear()
library.update(_update_user_library(_base_library))
available[:] = sorted(library.keys())
library.update(_update_user_library(_base_library.copy()))
available[:] = sorted(name for name in library if not name.startswith('_'))


reload_library()
15 changes: 13 additions & 2 deletions lib/matplotlib/tests/test_style.py
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
Expand Up @@ -21,6 +21,7 @@ def temp_style(style_name, settings=None):
if not settings:
settings = DUMMY_SETTINGS
temp_file = f'{style_name}.mplstyle'
orig_library_paths = style.USER_LIBRARY_PATHS
try:
with TemporaryDirectory() as tmpdir:
# Write style settings to file in the tmpdir.
Expand All @@ -32,6 +33,7 @@ def temp_style(style_name, settings=None):
style.reload_library()
yield
finally:
style.USER_LIBRARY_PATHS = orig_library_paths
style.reload_library()


Expand All @@ -46,8 +48,17 @@ def test_invalid_rc_warning_includes_filename(caplog):


def test_available():
with temp_style('_test_', DUMMY_SETTINGS):
assert '_test_' in style.available
# Private name should not be listed in available but still usable.
assert '_classic_test_patch' not in style.available
assert '_classic_test_patch' in style.library

with temp_style('_test_', DUMMY_SETTINGS), temp_style('dummy', DUMMY_SETTINGS):
assert 'dummy' in style.available
assert 'dummy' in style.library
assert '_test_' not in style.available
assert '_test_' in style.library
assert 'dummy' not in style.available
assert '_test_' not in style.available


def test_use():
Expand Down

Back | FazBrowse Home | New Git URL