From 2c80dc2aeda42cd861849412471a9952df12541f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 Jun 2017 00:21:10 +0530 Subject: [PATCH] Remove orphaned compiled forms when switching branches --- setup/gui.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/setup/gui.py b/setup/gui.py index 1db58d0776..1c9c5aefd9 100644 --- a/setup/gui.py +++ b/setup/gui.py @@ -20,16 +20,19 @@ class GUI(Command): parser.add_option('--summary', default=False, action='store_true', help='Only display a summary about how many files were compiled') - @classmethod - def find_forms(cls): + def find_forms(self): # We do not use the calibre function find_forms as - # mporting calibre.gui2 may not work + # importing calibre.gui2 may not work forms = [] - for root, _, files in os.walk(cls.PATH): + for root, _, files in os.walk(self.PATH): for name in files: + path = os.path.abspath(os.path.join(root, name)) if name.endswith('.ui'): - forms.append(os.path.abspath(os.path.join(root, name))) - + forms.append(path) + elif name.endswith('_ui.py') or name.endswith('_ui.pyc'): + fname = path.rpartition('_')[0] + '.ui' + if not os.path.exists(fname): + os.remove(path) return forms @classmethod