Source code for blocks.utils.misc
import logging
import os
import os.path as path
import shutil
__all__ = ['create_clean_dir']
[docs]def raise_moved(name: str, new_name: str):
"""
Raise ``NameError`` with the function/feature moved/renamed info message.
.. tip::
Use this function when moving/renaming function/features. Our projects may rely on them!
:param name: old name of the function/feature
:param new_name: new name of the function/feature
:raise NameError: with the function/feature renamed/moved info message
"""
raise NameError('Function/feature `{}` is no longer available. It was moved/renamed to `{}`.'
.format(name, new_name))
[docs]def create_clean_dir(dir_name: str) -> str:
"""
Create a clean directory with the given name in CWD.
:param dir_name: directory name
:return: directory name
"""
if path.exists(dir_name):
logging.info('Directory `%s` exists, cleaning up', dir_name)
shutil.rmtree(dir_name)
os.makedirs(dir_name)
return dir_name