From f5a0187b1aada6ed25af6ead4824bd5e8f8bfa7b Mon Sep 17 00:00:00 2001 From: Nathaniel Haller Date: Tue, 30 Apr 2024 15:03:58 -0700 Subject: [PATCH 1/4] Add a script to run edkrepo_cli.py without edkrepo installed to host. As the edkrepo installer is not run, include a requirements file for the python requirements. Signed-off-by: Nathaniel Haller --- edkrepo_dev.py | 54 ++++++++++++++++++++++++++++ edkrepo_dev_requirements_windows.txt | 5 +++ 2 files changed, 59 insertions(+) create mode 100644 edkrepo_dev.py create mode 100644 edkrepo_dev_requirements_windows.txt diff --git a/edkrepo_dev.py b/edkrepo_dev.py new file mode 100644 index 0000000..0277709 --- /dev/null +++ b/edkrepo_dev.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# +## @file +# edkrepo_dev.py +# +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +import sys +import traceback +if sys.version_info >= (3, 8): + from importlib.metadata import version +else: + import pkg_resources +from edkrepo.config.config_factory import GlobalConfig +from edkrepo.common.edkrepo_exception import EdkrepoGlobalConfigNotFoundException +from edkrepo import edkrepo_cli + +if __name__ == '__main__': + # Run the edkrepo command line interface without building and running the edkrepo installer. + # Minimum Python version and Git version in README.md + # Additional Python requirements in edkrepo_dev_requirements_windows.txt + # EdkRepo 'git bash' features support require the installer to use. + try: + # If a global config file was not installed, do not continue further. + GlobalConfig() + except EdkrepoGlobalConfigNotFoundException as e: + traceback.print_exc() + print() + print("Create a global edkrepo.cfg file before running edkrepo_dev.py.") + print("example global config file: edk2-edkrepo/edkrepo_installer/Vendor/edkrepo.cfg") + sys.exit(102) + except Exception as e: + traceback.print_exc() + sys.exit(1) + + try: + # If system has edkrepo installed, exit + if sys.version_info >= (3, 8): + edkrepo_version = version("edkrepo") + else: + edkrepo_version = pkg_resources.get_distribution("edkrepo").version + print("Edkrepo is found installed on the system. Edkrepo version: ", edkrepo_version) + print("Run the edkrepo uninstaller before using 'edkrepo_dev.py'.") + sys.exit(1) + except: + print("edkrepo running from development source.") + + try: + sys.exit(edkrepo_cli.main()) + except Exception as e: + traceback.print_exc() + sys.exit(1) diff --git a/edkrepo_dev_requirements_windows.txt b/edkrepo_dev_requirements_windows.txt new file mode 100644 index 0000000..25c18e4 --- /dev/null +++ b/edkrepo_dev_requirements_windows.txt @@ -0,0 +1,5 @@ +colorama>=0.4.4 +gitdb>=4.0.7 +GitPython>=3.1.14 +smmap>=4.0.0 + From a37015a57091dbb2c04f970292e4a7e05e9e067a Mon Sep 17 00:00:00 2001 From: Nathaniel Haller Date: Thu, 30 May 2024 15:04:34 -0700 Subject: [PATCH 2/4] Add .gitignore file for pycache folders. Running edkrepo_dev.py from the source repo directly creates __pycache__ folders. Create a .gitignore file to ignore those folders. Signed-off-by: Nathaniel Haller --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..27bf8f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ + From 6937b476bba25608bedeae041844fac863390028 Mon Sep 17 00:00:00 2001 From: Nathaniel Haller Date: Thu, 30 May 2024 15:12:07 -0700 Subject: [PATCH 3/4] Add a edkrepo_dev_local_data directory for config file development tests. When running edkrepo_dev.py, if no other global config directory is found, edkrepo_dev_local_data directory relative to the edkrepo_dev.py script becomes the default. All config files and manifest repos added to the edkrepo_dev_local_data directory by edkrepo_dev.py will be ignored by git. Use of the edkrepo_dev.py edkrepo_dev_local_data directory is limited to 'win32' platforms. Signed-off-by: Nathaniel Haller --- .gitignore | 2 ++ edkrepo/config/config_factory.py | 4 ++++ edkrepo_dev_local_data/README | 2 ++ 3 files changed, 8 insertions(+) create mode 100644 edkrepo_dev_local_data/README diff --git a/.gitignore b/.gitignore index 27bf8f2..7c70844 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +edkrepo_dev_local_data/*/ +edkrepo_dev_local_data/*.* __pycache__/ diff --git a/edkrepo/config/config_factory.py b/edkrepo/config/config_factory.py index 7808704..9945b6d 100644 --- a/edkrepo/config/config_factory.py +++ b/edkrepo/config/config_factory.py @@ -26,6 +26,7 @@ def get_edkrepo_global_data_directory(): global_data_dir = None + local_data_dir = None if sys.platform == "win32": shell32 = oledll.shell32 SHGetFolderPath = shell32.SHGetFolderPathW @@ -36,11 +37,14 @@ def get_edkrepo_global_data_directory(): common_appdata = create_unicode_buffer(MAX_PATH) SHGetFolderPath(None, CSIDL_COMMON_APPDATA, None, SHGFP_TYPE_CURRENT, common_appdata) global_data_dir = os.path.join(common_appdata.value, "edkrepo") + local_data_dir = os.path.join(os.path.dirname(sys.argv[0]), "edkrepo_dev_local_data") elif sys.platform == "darwin" or sys.platform.startswith("linux") or os.name == "posix": global_data_dir = expanduser("~/.edkrepo") if not os.path.isdir(global_data_dir): if not os.path.exists(os.path.dirname(global_data_dir)): raise EdkrepoGlobalDataDirectoryNotFoundException(humble.GLOBAL_DATA_DIR_NOT_FOUND.format(os.path.dirname(global_data_dir))) + if sys.platform == "win32" and os.path.isdir(local_data_dir): + return local_data_dir os.mkdir(global_data_dir) return global_data_dir diff --git a/edkrepo_dev_local_data/README b/edkrepo_dev_local_data/README new file mode 100644 index 0000000..505cdfe --- /dev/null +++ b/edkrepo_dev_local_data/README @@ -0,0 +1,2 @@ +For edkrepo_dev.py use, this folder has the least priority to be selected as the edkrepo global data directory. + From d3a70f6fedc370ea262d9c53add01505a6b60614 Mon Sep 17 00:00:00 2001 From: Nathaniel Haller Date: Tue, 18 Jun 2024 16:26:01 -0700 Subject: [PATCH 4/4] Raise ImportError if no command-packages are successfully imported. If the cfg file contains command-packages section includes multiple packages, raise ImportError if all packages fail to import. GlobalConfig file command-packages can be expanded and remain testable with with Tianocore edk2-edkrepo edkrepo.commands. Signed-off-by: Nathaniel Haller --- edkrepo/commands/command_factory.py | 12 ++++++++++-- edkrepo/commands/humble/command_factory_humble.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 edkrepo/commands/humble/command_factory_humble.py diff --git a/edkrepo/commands/command_factory.py b/edkrepo/commands/command_factory.py index 76211fe..5fea8ba 100644 --- a/edkrepo/commands/command_factory.py +++ b/edkrepo/commands/command_factory.py @@ -14,6 +14,8 @@ from edkrepo.commands.edkrepo_command import EdkrepoCommand from edkrepo.commands.composite_command import CompositeCommand from edkrepo.config.config_factory import GlobalConfig +import edkrepo.common.ui_functions as ui_functions +import edkrepo.commands.humble.command_factory_humble as humble def _is_command(CommandClass): if CommandClass == EdkrepoCommand: @@ -54,8 +56,14 @@ def get_commands(): cmd_search_dirs = [] for cmd_pkg in cmd_pkg_list: - mod = importlib.import_module(cmd_pkg) - cmd_search_dirs.append((cmd_pkg, os.path.dirname(mod.__file__))) + try: + mod = importlib.import_module(cmd_pkg) + cmd_search_dirs.append((cmd_pkg, os.path.dirname(mod.__file__))) + except ImportError: + ui_functions.print_info_msg(humble.COMMAND_PACKAGE_NOT_FOUND.format(cmd_pkg), header=False) + if cmd_search_dirs == []: + ui_functions.print_info_msg(humble.COMMAND_PACKAGES_NOT_FOUND, header=False) + raise ImportError (cmd_pkg_list) for cmd_dir in cmd_search_dirs: for module in os.listdir(cmd_dir[1]): if module == '__init__.py' or os.path.splitext(module)[1] != '.py': diff --git a/edkrepo/commands/humble/command_factory_humble.py b/edkrepo/commands/humble/command_factory_humble.py new file mode 100644 index 0000000..9a94797 --- /dev/null +++ b/edkrepo/commands/humble/command_factory_humble.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 +# +## @file +# command_factory_humble.py +# +# Copyright (c) 2024, Intel Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +COMMAND_PACKAGE_NOT_FOUND = 'command-package {} defined in the cfg file was not found.' +COMMAND_PACKAGES_NOT_FOUND = 'No command-packages defined in the cfg file were found.'