MCPcopy
hub / github.com/pex-tool/pex / safe_mkdir

Function safe_mkdir

pex/common.py:571–585  ·  view source on GitHub ↗

Safely create a directory. Ensures a directory is present. If it's not there, it is created. If it is, it's a no-op. If clean is True, ensures the directory is empty.

(directory, clean=False)

Source from the content-addressed store, hash-verified

569
570
571def safe_mkdir(directory, clean=False):
572 # type: (_Text, bool) -> _Text
573 """Safely create a directory.
574
575 Ensures a directory is present. If it's not there, it is created. If it is, it's a no-op. If
576 clean is True, ensures the directory is empty.
577 """
578 if clean:
579 safe_rmtree(directory)
580 try:
581 os.makedirs(directory)
582 except OSError as e:
583 if e.errno != errno.EEXIST:
584 raise
585 return directory
586
587
588def safe_open(filename, *args, **kwargs):

Callers 15

preserveFunction · 0.90
_install_distributionFunction · 0.90
extract_codeMethod · 0.90
extract_import_hookMethod · 0.90
extract_bootstrapMethod · 0.90
extract_codeMethod · 0.90
extract_import_hookMethod · 0.90
atomic_directoryFunction · 0.90
generate_reportsMethod · 0.90
_spawn_reportMethod · 0.90
create_whlFunction · 0.90

Calls 1

safe_rmtreeFunction · 0.85

Tested by 15

test_directory_hasherFunction · 0.72
test_zip_file_type_modeFunction · 0.72
test_pex_executableFunction · 0.72
test_pyenv_shimsMethod · 0.72
create_indexFunction · 0.72
test_bind_resource_pathFunction · 0.72
find_linksFunction · 0.72
indexFunction · 0.72