From 3bd350d52f0ec0d8d042792e22673e6868049ddb Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Sat, 20 Dec 2014 23:04:46 +0100 Subject: [PATCH] clean __pycache__ dir --- setup.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 2c6cc62..ee89fac 100644 --- a/setup.py +++ b/setup.py @@ -257,7 +257,7 @@ def set_rthook(): class clean_local(Command): - pats = ['*.py[co]', '*_ui.py', '*_rc.py'] + pats = ['*.py[co]', '*_ui.py', '*_rc.py', '__pycache__'] excludedirs = ['.git', 'build', 'dist'] user_options = [] @@ -269,13 +269,20 @@ class clean_local(Command): def run(self): for e in self._walkpaths('.'): - os.remove(e) + if os.path.isdir(e): + shutil.rmtree(e) + else: + os.remove(e) def _walkpaths(self, path): - for root, _dirs, files in os.walk(path): + for root, dirs, files in os.walk(path): if any(root == join(path, e) or root.startswith( join(path, e, '')) for e in self.excludedirs): continue + for d in dirs: + fpath = join(root, d) + if any(fnmatch(d, p) for p in self.pats): + yield fpath for e in files: fpath = join(root, e) if any(fnmatch(fpath, p) for p in self.pats):