From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web10.3056.1575936138979471338 for ; Mon, 09 Dec 2019 16:02:19 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: nathaniel.l.desimone@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Dec 2019 16:02:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,297,1571727600"; d="scan'208";a="210243589" Received: from nldesimo-mac02.jf.intel.com ([10.24.15.92]) by fmsmga007.fm.intel.com with ESMTP; 09 Dec 2019 16:02:17 -0800 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: Ashley E Desimone , Puja Pandya , Nathaniel L Desimone Subject: [edk2-staging/EdkRepo] [PATCH] EdkRepo: EdkRepo fails to run in detached HEAD mode Date: Mon, 9 Dec 2019 16:02:07 -0800 Message-Id: <20191210000207.62998-1-nathaniel.l.desimone@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If the current working directory is a git repo, then the EdkRepo entrypoint will fail to execute. This is caused by the command_factory being overzealous while searching for commands and constructing GitPython objects and searching those objects for EdkRepo commands. Cc: Ashley E Desimone Cc: Puja Pandya Signed-off-by: Nathaniel L Desimone --- edkrepo/commands/command_factory.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/edkrepo/commands/command_factory.py b/edkrepo/commands/command_factory.py index 9f2e923..b607724 100644 --- a/edkrepo/commands/command_factory.py +++ b/edkrepo/commands/command_factory.py @@ -61,9 +61,16 @@ def get_commands(): if module == '__init__.py' or os.path.splitext(module)[1] != '.py': continue mod = importlib.import_module('{}.{}'.format(cmd_dir[0], os.path.splitext(module)[0])) + mod_path = os.path.normcase(os.path.normpath(inspect.getfile(mod))) classes = inspect.getmembers(mod, predicate=inspect.isclass) for cls in classes: - if _is_command(cls[1]): + in_same_module = False + try: + if mod_path == os.path.normcase(os.path.normpath(inspect.getfile(cls[1]))): + in_same_module = True + except TypeError: + pass + if in_same_module and _is_command(cls[1]): if cmd_dir[0] == pref_cmd_pkg: pref_commands.update([(cls[0], cls[1])]) else: -- 2.20.1