Skip to content

Commit a9ce371

Browse files
committed
Don't expose private styles in style.available
They remain in `style.library`, because that's how we look them up, but this prevents them being exposed as something someone might use. Also, fix `reload_library`, which was accidentally modifying the original base library information each time. Fixes itprojects/MasVisGtk#13
1 parent 413ea8f commit a9ce371

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/matplotlib/style/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ def update_nested_dict(main_dict, new_dict):
245245
def reload_library():
246246
"""Reload the style library."""
247247
library.clear()
248-
library.update(_update_user_library(_base_library))
249-
available[:] = sorted(library.keys())
248+
library.update(_update_user_library(_base_library.copy()))
249+
available[:] = sorted(name for name in library
250+
if not name.startswith('_') or name not in _base_library)
250251

251252

252253
reload_library()

lib/matplotlib/tests/test_style.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def temp_style(style_name, settings=None):
2121
if not settings:
2222
settings = DUMMY_SETTINGS
2323
temp_file = f'{style_name}.mplstyle'
24+
orig_library_paths = style.USER_LIBRARY_PATHS
2425
try:
2526
with TemporaryDirectory() as tmpdir:
2627
# Write style settings to file in the tmpdir.
@@ -32,6 +33,7 @@ def temp_style(style_name, settings=None):
3233
style.reload_library()
3334
yield
3435
finally:
36+
style.USER_LIBRARY_PATHS = orig_library_paths
3537
style.reload_library()
3638

3739

@@ -46,8 +48,10 @@ def test_invalid_rc_warning_includes_filename(caplog):
4648

4749

4850
def test_available():
51+
assert '_classic_test_patch' not in style.available
4952
with temp_style('_test_', DUMMY_SETTINGS):
5053
assert '_test_' in style.available
54+
assert '_test_' not in style.available
5155

5256

5357
def test_use():

0 commit comments

Comments
 (0)