[BUG] shutil.copytree() fails if dir exists
mbordash2 opened this issue · comments
mbordash2 commented
Bug Description
When deploying a static site the below error occurs in versions of Python > 3.7.
File "/Users/mbordash/Library/Caches/pypoetry/virtualenvs/site-rg1dOqK9-py3.8/lib/python3.8/site-packages/runway/cfngin/actions/deploy.py", line 209, in handle_hooks
_handle_hooks(stage=stage, hooks=hooks, provider=provider, context=context)
File "/Users/mbordash/Library/Caches/pypoetry/virtualenvs/site-rg1dOqK9-py3.8/lib/python3.8/site-packages/runway/cfngin/hooks/utils.py", line 123, in handle_hooks
result = cast(Any, method(context=context, provider=provider, **kwargs))
File "/Users/mbordash/Library/Caches/pypoetry/virtualenvs/site-rg1dOqK9-py3.8/lib/python3.8/site-packages/runway/cfngin/hooks/staticsite/auth_at_edge/lambda_config.py", line 124, in write
shutil.copytree(
File "/Users/mbordash/.pyenv/versions/3.8.13/lib/python3.8/shutil.py", line 557, in copytree
return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
File "/Users/mbordash/.pyenv/versions/3.8.13/lib/python3.8/shutil.py", line 458, in _copytree
os.makedirs(dst, exist_ok=dirs_exist_ok)
File "/Users/mbordash/.pyenv/versions/3.8.13/lib/python3.8/os.py", line 223, in makedirs
mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/var/folders/fy/l9v7hcpd7gxctnx64l1dr__40000gn/T/tmp82evub0o'
shutil.copytree(libEntity,newDir,dirs_exist_ok=True) resolves the issue.
LOGGER.debug(f"Detected Python Version: {platform.python_version()}")
if '3.7' in platform.python_version():
shutil.copytree(
os.path.join(os.path.dirname(__file__), "templates", handler), dirpath
)
else:
shutil.copytree(
os.path.join(os.path.dirname(__file__), "templates", handler), dirpath, dirs_exist_ok = True
)
Expected Behavior
StaticSite Lambda deployments work with Python 3.8+.
Steps To Reproduce
Deploy static site with python 3.8+.
Runway version
2.6.4
Installation Type
pypi (pip, pipenv, poetry, etc)
OS / Environment
- OS: macOS 12.6.3
- python version 3.8.13
Anything else?
Does the solution need to have python 3.7 support since EOL is coming up soon?