From: "Desimone, Ashley E" <ashley.e.desimone@intel.com>
To: devel@edk2.groups.io
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>,
Puja Pandya <puja.pandya@intel.com>
Subject: [edk2-staging/EdkRepo] [PATCH] EdkRepo: Preferred Entry Point Support
Date: Mon, 28 Oct 2019 16:25:00 -0700 [thread overview]
Message-ID: <20191028232500.9212-1-ashley.e.desimone@intel.com> (raw)
Add support for defining and selecting a preferred entry point.
Signed-off-by: Ashley E Desimone <ashley.e.desimone@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
---
edkrepo/__main__.py | 4 +-
edkrepo/config/config_factory.py | 7 ++-
edkrepo/edkrepo_cli.py | 55 -------------------
edkrepo/edkrepo_entry_point.py | 103 +++++++++++++++++++++++++++++++++++
edkrepo_installer/Vendor/edkrepo.cfg | 7 ++-
setup.py | 2 +-
6 files changed, 117 insertions(+), 61 deletions(-)
create mode 100644 edkrepo/edkrepo_entry_point.py
diff --git a/edkrepo/__main__.py b/edkrepo/__main__.py
index 9bf3e50..115a779 100644
--- a/edkrepo/__main__.py
+++ b/edkrepo/__main__.py
@@ -24,11 +24,11 @@ for directory in sitepackages:
break
else:
imp.reload(edkrepo)
-import edkrepo.edkrepo_cli
+import edkrepo.edkrepo_entry_point
if __name__ == '__main__':
try:
- sys.exit(edkrepo.edkrepo_cli.main())
+ sys.exit(edkrepo.edkrepo_entry_point.main())
except Exception as e:
traceback.print_exc()
sys.exit(1)
diff --git a/edkrepo/config/config_factory.py b/edkrepo/config/config_factory.py
index 38844d7..e3a437f 100644
--- a/edkrepo/config/config_factory.py
+++ b/edkrepo/config/config_factory.py
@@ -125,11 +125,16 @@ class GlobalConfig(BaseConfig):
CfgProp('git-ver', 'minimum', 'minimum_req_git_ver', None, True),
CfgProp('git-ver', 'recommended', 'rec_git_ver', None, True),
CfgProp('command-packages', 'packages', 'command_packages', None, True),
- CfgProp('preferred-command-package', 'preferred-package', 'pref_pkg', None, True)]
+ CfgProp('preferred-command-package', 'preferred-package', 'pref_pkg', None, True),
+ CfgProp('preferred-entry-point', 'entry-point', 'pref_entry_point', None, True)]
if not os.path.isfile(self.filename):
raise EdkrepoGlobalConfigNotFoundException("edkrepo global config file {} does not exist".format(self.filename))
super().__init__(self.filename, True)
+ @property
+ def preferred_entry(self):
+ return (self.pref_entry_point.split(':')[0], self.pref_entry_point.split(':')[1])
+
@property
def command_packages_list(self):
initial_list = self.command_packages.split('|')
diff --git a/edkrepo/edkrepo_cli.py b/edkrepo/edkrepo_cli.py
index 8a74581..0b69860 100644
--- a/edkrepo/edkrepo_cli.py
+++ b/edkrepo/edkrepo_cli.py
@@ -23,61 +23,6 @@ import importlib.util
from git.exc import GitCommandError
-#Prefer the site-packages version of edkrepo
-sitepackages = site.getsitepackages()
-sys.path = sitepackages + sys.path
-import edkrepo
-edkrepo_site_dir = None
-edkrepo_package_path = os.path.dirname(os.path.dirname(edkrepo.__file__))
-for directory in sitepackages:
- if edkrepo_package_path == directory:
- edkrepo_site_dir = edkrepo_package_path
- break
-else:
- imp.reload(edkrepo)
- edkrepo_package_path = os.path.dirname(os.path.dirname(edkrepo.__file__))
- for directory in sitepackages:
- if edkrepo_package_path == directory:
- edkrepo_site_dir = edkrepo_package_path
- break
-if edkrepo_site_dir is None:
- print('Running EdkRepo from local source')
-
-#Determine if this module is being imported by the launcher script
-run_via_launcher_script = False
-importer = ""
-importer_file = ""
-f = inspect.currentframe().f_back
-while f is not None:
- if f.f_globals.get('__name__').find('importlib') == -1:
- importer = f.f_globals.get('__name__')
- importer_file = f.f_globals.get('__file__')
- if importer_file is None:
- importer_file = ""
- break
- f = f.f_back
-if importer == "__main__":
- if os.path.basename(importer_file).lower() == "__main__.py":
- if os.path.basename(os.path.dirname(importer_file)).lower().find('edkrepo') != -1:
- run_via_launcher_script = True
- elif os.path.basename(importer_file).lower().find('edkrepo') != -1:
- run_via_launcher_script = True
-
-if __name__ == "__main__" or run_via_launcher_script:
- #If this module is the entrypoint, we need to make
- #sure that the site-packages version is being executed
- if edkrepo_site_dir is not None and os.path.commonprefix([edkrepo_site_dir, __file__]) != edkrepo_site_dir:
- edkrepo_cli_file_name = os.path.join(edkrepo_site_dir, 'edkrepo', 'edkrepo_cli.py')
- if os.path.isfile(edkrepo_cli_file_name):
- spec = importlib.util.spec_from_file_location('edkrepo.edkrepo_cli', edkrepo_cli_file_name)
- edkrepo_cli = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(edkrepo_cli)
- try:
- sys.exit(edkrepo_cli.main())
- except Exception as e:
- traceback.print_exc()
- sys.exit(1)
-
from edkrepo.commands import command_factory
from edkrepo.config import config_factory
from edkrepo.common.edkrepo_exception import EdkrepoException, EdkrepoGlobalConfigNotFoundException
diff --git a/edkrepo/edkrepo_entry_point.py b/edkrepo/edkrepo_entry_point.py
new file mode 100644
index 0000000..1f74d1b
--- /dev/null
+++ b/edkrepo/edkrepo_entry_point.py
@@ -0,0 +1,103 @@
+#!/usr/bin/env python3
+#
+## @file
+# edkrepo_entry_point.py
+#
+# Copyright (c) 2017- 2019, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+import argparse
+import imp
+import importlib.util
+import inspect
+import json
+import os
+import pkg_resources
+import site
+import subprocess
+import sys
+import time
+import traceback
+from operator import itemgetter
+
+from git.exc import GitCommandError
+
+import edkrepo
+
+#Prefer the site-packages version of edkrepo
+sitepackages = site.getsitepackages()
+sys.path = sitepackages + sys.path
+edkrepo_site_dir = None
+edkrepo_package_path = os.path.dirname(os.path.dirname(edkrepo.__file__))
+for directory in sitepackages:
+ if edkrepo_package_path == directory:
+ edkrepo_site_dir = edkrepo_package_path
+ break
+else:
+ imp.reload(edkrepo)
+ edkrepo_package_path = os.path.dirname(os.path.dirname(edkrepo.__file__))
+ for directory in sitepackages:
+ if edkrepo_package_path == directory:
+ edkrepo_site_dir = edkrepo_package_path
+ break
+if edkrepo_site_dir is None:
+ print('Running EdkRepo from local source')
+
+#Determine if this module is being imported by the launcher script
+run_via_launcher_script = False
+importer = ""
+importer_file = ""
+f = inspect.currentframe().f_back
+while f is not None:
+ if f.f_globals.get('__name__').find('importlib') == -1:
+ importer = f.f_globals.get('__name__')
+ importer_file = f.f_globals.get('__file__')
+ if importer_file is None:
+ importer_file = ""
+ break
+ f = f.f_back
+if importer == "__main__":
+ if os.path.basename(importer_file).lower() == "__main__.py":
+ if os.path.basename(os.path.dirname(importer_file)).lower().find('edkrepo') != -1:
+ run_via_launcher_script = True
+ elif os.path.basename(importer_file).lower().find('edkrepo') != -1:
+ run_via_launcher_script = True
+
+if __name__ == "__main__" or run_via_launcher_script:
+ #If this module is the entrypoint, we need to make
+ #sure that the site-packages version is being executed
+ if edkrepo_site_dir is not None and os.path.commonprefix([edkrepo_site_dir, __file__]) != edkrepo_site_dir:
+ edkrepo_cli_file_name = os.path.join(edkrepo_site_dir, 'edkrepo', 'edkrepo_entry_point.py')
+ if os.path.isfile(edkrepo_cli_file_name):
+ spec = importlib.util.spec_from_file_location('edkrepo.edkrepo_entry_point.py', edkrepo_cli_file_name)
+ edkrepo_entry_point = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(edkrepo_entry_point)
+ try:
+ sys.exit(edkrepo_entry_point.main())
+ except Exception as e:
+ traceback.print_exc()
+ sys.exit(1)
+
+from edkrepo.config.config_factory import GlobalConfig
+
+def main():
+ cfg_file = GlobalConfig()
+ pref_entry = (cfg_file.preferred_entry[0]).replace('.py', '')
+ pref_entry_func = cfg_file.preferred_entry[1]
+
+ try:
+ mod = importlib.import_module(pref_entry)
+ func = getattr(mod, pref_entry_func)
+ func()
+ except:
+ print('Unable to launch preferred entry point. Launching default entry point edkrepo.edkrepo_cli.py')
+ import edkrepo.edkrepo_cli
+ edkrepo.edkrepo_cli.main()
+
+if __name__ == "__main__":
+ try:
+ sys.exit(main())
+ except Exception as e:
+ traceback.print_exc()
+ sys.exit(1)
\ No newline at end of file
diff --git a/edkrepo_installer/Vendor/edkrepo.cfg b/edkrepo_installer/Vendor/edkrepo.cfg
index 0312c74..7dcaf20 100644
--- a/edkrepo_installer/Vendor/edkrepo.cfg
+++ b/edkrepo_installer/Vendor/edkrepo.cfg
@@ -13,9 +13,12 @@ packages = edkrepo.commands
[preferred-command-package]
preferred-package = edkrepo.commands
+[preferred-entry-point]
+entry-point = edkrepo.edkrepo_cli:main
+
[sparsecheckout]
always_include = BaseTools|Conf|*.*
-always_exclude =
+always_exclude =
[f2f-cherry-pick]
-ignored_folder_substrings =
+ignored_folder_substrings =
diff --git a/setup.py b/setup.py
index 51f65d3..ed07594 100755
--- a/setup.py
+++ b/setup.py
@@ -18,7 +18,7 @@ setup(name='edkrepo',
include_package_data=True,
entry_points={
'console_scripts': [
- 'edkrepo = edkrepo.edkrepo_cli:main'
+ 'edkrepo = edkrepo.edkrepo_entry_point:main'
]
}
)
--
2.16.2.windows.1
next reply other threads:[~2019-10-28 23:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-28 23:25 Desimone, Ashley E [this message]
2019-10-28 23:47 ` [edk2-staging/EdkRepo] [PATCH] EdkRepo: Preferred Entry Point Support Nate DeSimone
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191028232500.9212-1-ashley.e.desimone@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox