Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4987dcd

Browse filesBrowse files
committed
Deal with all cases where get_configdir might return None.
Each case is either handled gracefully, or raises a RuntimeError.
1 parent 21921a3 commit 4987dcd
Copy full SHA for 4987dcd

File tree

Expand file treeCollapse file tree

5 files changed

+29
-13
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+29
-13
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+16-10Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -656,20 +656,25 @@ def matplotlib_fname():
656656
print("WARNING: File could not be renamed: %s" % e, file=sys.stderr)
657657

658658
home = get_home()
659+
configdir = get_configdir()
659660
if home:
660661
oldname = os.path.join( home, '.matplotlibrc')
661662
if os.path.exists(oldname):
662-
configdir = get_configdir()
663-
newname = os.path.join(configdir, 'matplotlibrc')
664-
print("""\
663+
if configdir is not None:
664+
newname = os.path.join(configdir, 'matplotlibrc')
665+
print("""\
665666
WARNING: Old rc filename "%s" found and renamed to
666667
new default rc file name "%s"."""%(oldname, newname), file=sys.stderr)
667668

668-
try:
669-
shutil.move(oldname, newname)
670-
except IOError as e:
671-
print("WARNING: File could not be renamed: %s" % e,
672-
file=sys.stderr)
669+
try:
670+
shutil.move(oldname, newname)
671+
except IOError as e:
672+
print("WARNING: File could not be renamed: %s" % e,
673+
file=sys.stderr)
674+
else:
675+
print("""\
676+
WARNING: Could not rename old rc file "%s": a suitable configuration directory
677+
could not be found.""" % oldname, file=sys.stderr)
673678

674679

675680
fname = os.path.join( os.getcwd(), 'matplotlibrc')
@@ -682,8 +687,9 @@ def matplotlib_fname():
682687
if os.path.exists(fname):
683688
return fname
684689

685-
fname = os.path.join(get_configdir(), 'matplotlibrc')
686-
if os.path.exists(fname): return fname
690+
if configdir is not None:
691+
fname = os.path.join(configdir, 'matplotlibrc')
692+
if os.path.exists(fname): return fname
687693

688694

689695
path = get_data_path() # guaranteed to exist or raise

‎lib/matplotlib/finance.py

Copy file name to clipboardExpand all lines: lib/matplotlib/finance.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929

3030
configdir = get_configdir()
31+
if configdir is None:
32+
raise RuntimeError('Could not find a suitable configuration directory')
3133
cachedir = os.path.join(configdir, 'finance.cache')
3234

3335

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,10 +1311,13 @@ def findfont(prop, fontext='ttf'):
13111311
return result
13121312

13131313
else:
1314+
configdir = get_configdir()
1315+
if configdir is None:
1316+
raise RuntimeError('Could not find a suitable configuration directory')
13141317
if sys.version_info[0] >= 3:
1315-
_fmcache = os.path.join(get_configdir(), 'fontList.py3k.cache')
1318+
_fmcache = os.path.join(configdir, 'fontList.py3k.cache')
13161319
else:
1317-
_fmcache = os.path.join(get_configdir(), 'fontList.cache')
1320+
_fmcache = os.path.join(configdir, 'fontList.cache')
13181321

13191322
fontManager = None
13201323

‎lib/matplotlib/testing/compare.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/compare.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ def compare_float( expected, actual, relTol = None, absTol = None ):
9999
# parameters old and new to a list that can be passed to Popen to
100100
# convert files with that extension to png format.
101101
def get_cache_dir():
102-
cache_dir = os.path.join(_get_configdir(), 'test_cache')
102+
configdir = _get_configdir()
103+
if configdir is None:
104+
raise RuntimeError('Could not find a suitable configuration directory')
105+
cache_dir = os.path.join(configdir, 'test_cache')
103106
if not os.path.exists(cache_dir):
104107
try:
105108
os.makedirs(cache_dir)

‎lib/matplotlib/texmanager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/texmanager.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class TexManager:
9494
oldcache = os.path.join(oldpath, '.tex.cache')
9595

9696
configdir = mpl.get_configdir()
97+
if configdir is None:
98+
raise RuntimeError('Could not find a suitable configuration directory')
9799
texcache = os.path.join(configdir, 'tex.cache')
98100

99101
if os.path.exists(oldcache):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.