Never delete any files in the .git directory when cleaning manually

This is how results can be removed from os.walk(), according to https://docs.python.org/3/library/os.html#os.walk.
This commit is contained in:
Luflosi 2019-06-23 17:06:21 +02:00
parent 0e1a423889
commit 3ea3a85694
No known key found for this signature in database
GPG Key ID: 14140F703B7D8362

View File

@ -790,7 +790,9 @@ def clean():
os.unlink(x)
safe_remove('build', 'compile_commands.json', 'linux-package', 'kitty.app')
for root, dirs, files in os.walk('.'):
exclude = ('.git',)
for root, dirs, files in os.walk('.', topdown=True):
dirs[:] = [d for d in dirs if d not in exclude]
remove_dirs = {d for d in dirs if d == '__pycache__'}
[(shutil.rmtree(os.path.join(root, d)), dirs.remove(d)) for d in remove_dirs]
for f in files: