diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2018-11-16 05:01:54 -0800 |
---|---|---|
committer | Jon Dufresne <jon.dufresne@gmail.com> | 2018-11-20 18:37:05 -0800 |
commit | 77849f0ef6d80fc636f457c2d8925c4932c406c9 (patch) | |
tree | 270f19661ab4fdcf3a53f122688532018262744d /sphinx/util/osutil.py | |
parent | 2cbc921946c20e072965f746090003fe41f5ddf1 (diff) | |
download | sphinx-git-77849f0ef6d80fc636f457c2d8925c4932c406c9.tar.gz |
Simplify ensuredir() with Python3 stdlib features
- Simplify ensuredir() to equivalent os.makedir(name, exist_ok=True)
- Do not check if a directory exists before calling
ensuredir() (ensuredir() already handles it)
- Add exist_ok argument to path.makedirs() to follow same pattern
- Drop unnecessary .exists() check immediately before .isdir()
- Add tests for ensuredir
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r-- | sphinx/util/osutil.py | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index c7c0b0690..198076664 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -82,13 +82,7 @@ def relative_uri(base, to): def ensuredir(path): # type: (unicode) -> None """Ensure that a path exists.""" - try: - os.makedirs(path) - except OSError: - # If the path is already an existing directory (not a file!), - # that is OK. - if not os.path.isdir(path): - raise + os.makedirs(path, exist_ok=True) # type: ignore def walk(top, topdown=True, followlinks=False): |