|
4 | 4 | from __future__ import annotations |
5 | 5 |
|
6 | 6 | # %% auto 0 |
7 | | -__all__ = ['spark_chars', 'walk', 'globtastic', 'maybe_open', 'image_size', 'bunzip', 'loads', 'loads_multi', 'dumps', |
| 7 | +__all__ = ['spark_chars', 'walk', 'globtastic', 'maybe_open', 'mkdir', 'image_size', 'bunzip', 'loads', 'loads_multi', 'dumps', |
8 | 8 | 'untar_dir', 'repo_details', 'run', 'open_file', 'save_pickle', 'load_pickle', 'dict2obj', 'obj2dict', |
9 | 9 | 'repr_dict', 'is_listy', 'mapped', 'IterLen', 'ReindexCollection', 'get_source_link', 'truncstr', |
10 | 10 | 'sparkline', 'modify_exception', 'round_multiple', 'set_num_threads', 'join_path_file', 'autostart', |
@@ -74,6 +74,14 @@ def maybe_open(f, mode='r', **kwargs): |
74 | 74 | with open(f, mode, **kwargs) as f: yield f |
75 | 75 | else: yield f |
76 | 76 |
|
| 77 | +# %% ../nbs/03_xtras.ipynb 26 |
| 78 | +def mkdir(path, exist_ok=False, parents=False, overwrite=False, **kwargs): |
| 79 | + "Creates and returns a directory defined by `path`, optionally removing previous existing directory if `overwrite` is `True`" |
| 80 | + path = Path(path) |
| 81 | + if path.exists() and overwrite: shutil.rmtree(path) |
| 82 | + path.mkdir(exist_ok=exist_ok, parents=parents, **kwargs) |
| 83 | + return path |
| 84 | + |
77 | 85 | # %% ../nbs/03_xtras.ipynb 28 |
78 | 86 | def image_size(fn): |
79 | 87 | "Tuple of (w,h) for png, gif, or jpg; `None` otherwise" |
|
0 commit comments