|
190 | 190 | _rcGlobals = {}
|
191 | 191 | _rcExtraParams = {}
|
192 | 192 |
|
193 |
| -# Get default font |
194 |
| -# WARNING: Had issues with Helvetica Neue on Linux, weirdly some characters |
195 |
| -# failed to render/printed nonsense, but Helvetica was fine. |
196 |
| -USER_RC = os.path.join(os.path.expanduser("~"), '.proplotrc') |
197 |
| -DEFAULT_RC = os.path.join(os.path.dirname(__file__), '.proplotrc') |
198 |
| -if not os.path.exists(DEFAULT_RC): |
199 |
| - raise ValueError('Default configuration file does not exist.') |
| 193 | +# Configuration files |
| 194 | +def _get_rc(): |
| 195 | + """Walks successive parent directories searching for ".proplotrc" and |
| 196 | + "proplotrc" files.""" |
| 197 | + # Local configuration |
| 198 | + rc = [] |
| 199 | + idir = os.getcwd() |
| 200 | + while idir: # not empty string |
| 201 | + for tail in ('.proplotrc', 'proplotrc'): |
| 202 | + irc = os.path.join(idir, tail) |
| 203 | + if os.path.exists(irc): |
| 204 | + rc.append(irc) |
| 205 | + ndir, _ = os.path.split(idir) |
| 206 | + if ndir == idir: |
| 207 | + break |
| 208 | + idir = ndir |
| 209 | + rc = rc[::-1] # sort from decreasing to increasing importantce |
| 210 | + # Home configuration |
| 211 | + irc = os.path.join(os.path.expanduser('~'), '.proplotrc') |
| 212 | + if os.path.exists(irc) and irc not in rc: |
| 213 | + rc.insert(0, irc) |
| 214 | + # Global configuration |
| 215 | + irc = os.path.join(os.path.dirname(__file__), '.proplotrc') |
| 216 | + if not os.path.exists(irc): |
| 217 | + raise ValueError('Default configuration file does not exist.') |
| 218 | + elif irc not in rc: |
| 219 | + rc.insert(0, irc) |
| 220 | + return rc |
200 | 221 |
|
201 | 222 | # "Global" settings and the lower-level settings they change
|
202 | 223 | # NOTE: This whole section, declaring dictionaries and sets, takes 1ms
|
@@ -397,7 +418,7 @@ def __init__(self):
|
397 | 418 | plt.style.use('default')
|
398 | 419 |
|
399 | 420 | # Load the defaults from file
|
400 |
| - for i,file in enumerate((DEFAULT_RC, USER_RC)): |
| 421 | + for i,file in enumerate(_get_rc()): |
401 | 422 | # Load
|
402 | 423 | if not os.path.exists(file):
|
403 | 424 | continue
|
|
0 commit comments