Skip to content

mkdir is in the stdlib in Py3. #10439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
import locale
import logging
import os
from pathlib import Path
import re
import shutil
import stat
Expand Down Expand Up @@ -651,14 +652,10 @@ def _get_xdg_cache_dir():


def _get_config_or_cache_dir(xdg_base):
from matplotlib.cbook import mkdirs

configdir = os.environ.get('MPLCONFIGDIR')
if configdir is not None:
configdir = os.path.abspath(configdir)
if not os.path.exists(configdir):
mkdirs(configdir)

Path(configdir).mkdir(parents=True, exist_ok=True)
if not _is_writable_dir(configdir):
return _create_tmp_config_dir()
return configdir
Expand All @@ -678,7 +675,7 @@ def _get_config_or_cache_dir(xdg_base):
return p
else:
try:
mkdirs(p)
Path(p).mkdir(parents=True, exist_ok=True)
except OSError:
pass
else:
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ def __delattr__(self, name):
return self


@deprecated("3.0")
def mkdirs(newdir, mode=0o777):
"""
make directory *newdir* recursively, and set *mode*. Equivalent to ::
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@

import sys, os, shutil, io, re, textwrap
from os.path import relpath
from pathlib import Path
import traceback
import warnings

Expand Down Expand Up @@ -846,8 +847,7 @@ def run(arguments, content, options, state_machine, state, lineno):
state_machine.insert_input(total_lines, source=source_file_name)

# copy image files to builder's output directory, if necessary
if not os.path.exists(dest_dir):
cbook.mkdirs(dest_dir)
Path(dest_dir).mkdir(parents=True, exist_ok=True)

for code_piece, images in results:
for img in images:
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/testing/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import hashlib
import itertools
import os
from pathlib import Path
import re
import shutil
import sys
Expand Down Expand Up @@ -85,11 +86,10 @@ def get_cache_dir():
if cachedir is None:
raise RuntimeError('Could not find a suitable configuration directory')
cache_dir = os.path.join(cachedir, 'test_cache')
if not os.path.exists(cache_dir):
try:
cbook.mkdirs(cache_dir)
except IOError:
return None
try:
Path(cache_dir).mkdir(parents=True, exist_ok=True)
except IOError:
return None
if not os.access(cache_dir, os.W_OK):
return None
return cache_dir
Expand Down
9 changes: 4 additions & 5 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import functools
import inspect
import os
import sys
from pathlib import Path
import shutil
import warnings
import sys
import unittest
import warnings

# Note - don't import nose up here - import it only as needed in functions.
# This allows other functions here to be used by pytest-based testing suites
Expand Down Expand Up @@ -532,9 +533,7 @@ def find_dotted_module(module_name, path=None):

baseline_dir = os.path.join(basedir, 'baseline_images', subdir)
result_dir = os.path.abspath(os.path.join('result_images', subdir))

if not os.path.exists(result_dir):
cbook.mkdirs(result_dir)
Path(result_dir).mkdir(parents=True, exist_ok=True)

return baseline_dir, result_dir

Expand Down
17 changes: 9 additions & 8 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@

import copy
import glob
import hashlib
import logging
import os
from pathlib import Path
import shutil
import sys
import warnings
import logging

from hashlib import md5

import distutils.version
import numpy as np
import matplotlib as mpl
from matplotlib import rcParams
from matplotlib._png import read_png
from matplotlib.cbook import mkdirs, Locked
from matplotlib.cbook import Locked
from matplotlib.compat.subprocess import subprocess, Popen, PIPE, STDOUT
import matplotlib.dviread as dviread
import re
Expand Down Expand Up @@ -88,7 +88,7 @@ class TexManager(object):
cachedir = mpl.get_cachedir()
if cachedir is not None:
texcache = os.path.join(cachedir, 'tex.cache')
mkdirs(texcache)
Path(texcache).mkdir(parents=True, exist_ok=True)
else:
# Should only happen in a restricted environment (such as Google App
# Engine). Deal with this gracefully by not creating a cache directory.
Expand Down Expand Up @@ -136,7 +136,7 @@ def __init__(self):
raise RuntimeError('Cannot create TexManager, as there is no '
'cache directory available')

mkdirs(self.texcache)
Path(self.texcache).mkdir(parents=True, exist_ok=True)
ff = rcParams['font.family']
if len(ff) == 1 and ff[0].lower() in self.font_families:
self.font_family = ff[0].lower()
Expand Down Expand Up @@ -171,7 +171,7 @@ def __init__(self):
# correct png is selected for strings rendered with same font and dpi
# even if the latex preamble changes within the session
preamble_bytes = self.get_custom_preamble().encode('utf-8')
fontconfig.append(md5(preamble_bytes).hexdigest())
fontconfig.append(hashlib.md5(preamble_bytes).hexdigest())
self._fontconfig = ''.join(fontconfig)

# The following packages and commands need to be included in the latex
Expand All @@ -188,7 +188,8 @@ def get_basefile(self, tex, fontsize, dpi=None):
"""
s = ''.join([tex, self.get_font_config(), '%f' % fontsize,
self.get_custom_preamble(), str(dpi or '')])
return os.path.join(self.texcache, md5(s.encode('utf-8')).hexdigest())
return os.path.join(
self.texcache, hashlib.md5(s.encode('utf-8')).hexdigest())

def get_font_config(self):
"""Reinitializes self if relevant rcParams on have changed."""
Expand Down