Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 359cad3

Browse files
authored
Merge pull request #14944 from anntzer/style
Shorten style.py.
2 parents 2cc5d8d + 0a93e5b commit 359cad3

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
API changes
2+
```````````
3+
4+
``style.core.is_style_file`` and ``style.core.iter_style_files`` are deprecated.

lib/matplotlib/style/core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import contextlib
1515
import logging
1616
import os
17+
from pathlib import Path
1718
import re
1819
import warnings
1920

@@ -53,6 +54,7 @@ def _remove_blacklisted_style_params(d, warn=True):
5354
return o
5455

5556

57+
@cbook.deprecated("3.2")
5658
def is_style_file(filename):
5759
"""Return True if the filename looks like a style file."""
5860
return STYLE_FILE_PATTERN.match(filename) is not None
@@ -167,6 +169,7 @@ def update_user_library(library):
167169
return library
168170

169171

172+
@cbook.deprecated("3.2")
170173
def iter_style_files(style_dir):
171174
"""Yield file path and name of styles in the given directory."""
172175
for path in os.listdir(style_dir):
@@ -178,17 +181,14 @@ def iter_style_files(style_dir):
178181

179182

180183
def read_style_directory(style_dir):
181-
"""Return dictionary of styles defined in `style_dir`."""
184+
"""Return dictionary of styles defined in *style_dir*."""
182185
styles = dict()
183-
for path, name in iter_style_files(style_dir):
186+
for path in Path(style_dir).glob(f"*.{STYLE_EXTENSION}"):
184187
with warnings.catch_warnings(record=True) as warns:
185-
styles[name] = rc_params_from_file(path,
186-
use_default_template=False)
187-
188+
styles[path.stem] = rc_params_from_file(
189+
path, use_default_template=False)
188190
for w in warns:
189-
message = 'In %s: %s' % (path, w.message)
190-
_log.warning(message)
191-
191+
_log.warning('In %s: %s', path, w.message)
192192
return styles
193193

194194

0 commit comments

Comments
 (0)