From dd9d5c3b07e946bd6086faa97084b4652b031abc Mon Sep 17 00:00:00 2001 From: Spencer Rak Date: Sun, 22 Jun 2025 10:10:27 -0400 Subject: [PATCH 1/2] Adds implicit behaviors for local directory --- carthage/utils.py | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/carthage/utils.py b/carthage/utils.py index 19bcf2cf..1e211ece 100644 --- a/carthage/utils.py +++ b/carthage/utils.py @@ -209,19 +209,20 @@ def add_carthage_arguments(parser): parser.add_argument('--config', metavar="file", default=[], + help='Specify a user configuration file. If unspecified, Carthage searches for ${PWD}/carthage_config.yml at startup. If this file exists it is read to override other configurations.', type=argparse.FileType('rt'), action='append') - parser.add_argument('--command-verbose', - help="Verbose command logging", - action=argparse.BooleanOptionalAction) - parser.add_argument('--tasks-verbose', - help="Verbose logging for tasks", - action=argparse.BooleanOptionalAction) + parser.add_argument('--no-default-config', + dest='default_config', + action='store_false', + default=True, + help='Disable reading /etc/carthage_system.conf as root and ~/.carthage.conf for other users.' + ) parser.add_argument('--plugin', dest='plugins', default=[], action='append', - help='Load a plugin into Carthage', + help='Load a plugin into Carthage. If unspecified, Carthage searches the current directory for carthage_plugin.yml and carthage_plugin.py. If these files are found, Carthage assumes the current directory is a Carthage plugin.', metavar='plugin') parser.add_argument('--pull-plugins', default=None, action='store_true', @@ -230,12 +231,12 @@ def add_carthage_arguments(parser): default=None, dest='pull_plugins', action='store_false', help='Do not pull plugins') - parser.add_argument('--no-default-config', - dest='default_config', - action='store_false', - default=True, - help='Disable reading /etc/carthage_system.conf as root and ~/.carthage.conf for other users.' - ) + parser.add_argument('--command-verbose', + help="Verbose command logging", + action=argparse.BooleanOptionalAction) + parser.add_argument('--tasks-verbose', + help="Verbose logging for tasks", + action=argparse.BooleanOptionalAction) return parser @@ -279,10 +280,26 @@ def container_debug_filter(record): logging.getLogger('urllib3.connectionpool').propagate = False if args.default_config: load_default_config(config) - if args.pull_plugins is not None: - config.pull_plugins = args.pull_plugins + cwd = Path(os.getcwd()) + if args.config == []: + if (cwd/"carthage_config.yml").is_file(): + root_logger.info("Found 'carthage_config.yml' in current directory. Continuing with implicit '--config carthage_config.yml'") + args.config.append((cwd/"carthage_config.yml").open("rt")) for f in args.config: config.load_yaml(f, ignore_import_errors=ignore_import_errors) + # we need to load our plugin (layout) first to determine if the layout plugin has set pull_plugins=False + if args.pull_plugins is not None: + config.pull_plugins = args.pull_plugins + if args.plugins == []: + if ( + (cwd/"carthage_plugin.py").is_file() + and (cwd/"carthage_plugin.yml").is_file() + ): + root_logger.info("Found Carthage plugin in current directory. Continuing with implicit '--plugin .'") + args.plugins.append(".") + else: + root_logger.fatal(f"'--plugin' was not specified and current directory does not appear to contain a Carthage plugin. Abort.") + exit(1) for p in args.plugins: base_injector(load_plugin, p, ignore_import_errors=ignore_import_errors) if args.tasks_verbose: From a584b30c4cf732174a4c18df7f0c7c374fe4b8c2 Mon Sep 17 00:00:00 2001 From: Spencer Rak Date: Fri, 8 Aug 2025 06:37:30 -0400 Subject: [PATCH 2/2] Always check if the current directory is a plugin --- carthage/utils.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/carthage/utils.py b/carthage/utils.py index 1e211ece..0c1e2d52 100644 --- a/carthage/utils.py +++ b/carthage/utils.py @@ -222,7 +222,7 @@ def add_carthage_arguments(parser): dest='plugins', default=[], action='append', - help='Load a plugin into Carthage. If unspecified, Carthage searches the current directory for carthage_plugin.yml and carthage_plugin.py. If these files are found, Carthage assumes the current directory is a Carthage plugin.', + help='Load a plugin into Carthage. Carthage always searches the current directory for carthage_plugin.yml and carthage_plugin.py. If these files are found, Carthage assumes the current directory is a Carthage plugin, and appends it to the plugin list.', metavar='plugin') parser.add_argument('--pull-plugins', default=None, action='store_true', @@ -290,16 +290,15 @@ def container_debug_filter(record): # we need to load our plugin (layout) first to determine if the layout plugin has set pull_plugins=False if args.pull_plugins is not None: config.pull_plugins = args.pull_plugins + if ( + (cwd/"carthage_plugin.py").is_file() + and (cwd/"carthage_plugin.yml").is_file() + ): + root_logger.info("Found Carthage plugin in current directory. Continuing with implicit '--plugin .'") + args.plugins.append(".") if args.plugins == []: - if ( - (cwd/"carthage_plugin.py").is_file() - and (cwd/"carthage_plugin.yml").is_file() - ): - root_logger.info("Found Carthage plugin in current directory. Continuing with implicit '--plugin .'") - args.plugins.append(".") - else: - root_logger.fatal(f"'--plugin' was not specified and current directory does not appear to contain a Carthage plugin. Abort.") - exit(1) + root_logger.fatal(f"'--plugin' was not specified and current directory does not appear to contain a Carthage plugin. Abort.") + exit(1) for p in args.plugins: base_injector(load_plugin, p, ignore_import_errors=ignore_import_errors) if args.tasks_verbose: