From 32473d7dc77fa75658c008fabd6f002e5814bacf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 12 Mar 2018 07:50:54 +0530 Subject: [PATCH] make clean fallsback to manual cleaning when not in a git checkout Fixes #379 --- setup.py | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 77fe5e464..d79abdb4c 100755 --- a/setup.py +++ b/setup.py @@ -3,6 +3,7 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal import argparse +import glob import importlib import json import os @@ -594,14 +595,37 @@ Categories=System; def clean(): - for f in subprocess.check_output( - 'git ls-files --others --ignored --exclude-from=.gitignore'.split() - ).decode('utf-8').splitlines(): - if f.startswith('logo/kitty.iconset') or f.startswith('dev/'): - continue - os.unlink(f) - if os.sep in f and not os.listdir(os.path.dirname(f)): - os.rmdir(os.path.dirname(f)) + os.chdir(os.path.dirname(os.path.abspath(__file__))) + if os.path.exists('.git'): + for f in subprocess.check_output( + 'git ls-files --others --ignored --exclude-from=.gitignore'.split() + ).decode('utf-8').splitlines(): + if f.startswith('logo/kitty.iconset') or f.startswith('dev/'): + continue + os.unlink(f) + if os.sep in f and not os.listdir(os.path.dirname(f)): + os.rmdir(os.path.dirname(f)) + return + # Not a git checkout, clean manually + + def safe_remove(*entries): + for x in entries: + if os.path.exists(x): + if os.path.isdir(x): + shutil.rmtree(x) + else: + os.unlink(x) + + shutil.rmtree('build', 'compile_commands.json') + for root, dirs, files in os.walk('.'): + 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: + ext = f.rpartition('.')[-1] + if ext in ('so', 'dylib', 'pyc', 'pyo'): + os.unlink(os.path.join(root, f)) + for x in glob.glob('glfw/*-protocol.[ch]'): + os.unlink(x) def option_parser():