From 052118a722f056424efa5cb4c6f9c86192427989 Mon Sep 17 00:00:00 2001 From: Tim Paine <3105306+timkpaine@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:50:05 -0400 Subject: [PATCH] Allow for extra arguments to hatchling build --- backend/src/hatchling/cli/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/src/hatchling/cli/__init__.py b/backend/src/hatchling/cli/__init__.py index 6d2a22b99..f56a5fa27 100644 --- a/backend/src/hatchling/cli/__init__.py +++ b/backend/src/hatchling/cli/__init__.py @@ -17,7 +17,18 @@ def hatchling() -> int: metadata_command(subparsers, defaults) version_command(subparsers, defaults) - kwargs = vars(parser.parse_args()) + # Parse known arguments + kwargs, extras = parser.parse_known_args() + + # Extras can exist to be detected in custom hooks and plugins, + # but they must be after a '--' separator + if extras and extras[0] != "--": + parser.print_help() + return 1 + + # Wrap the parsed arguments in a dictionary + kwargs = vars(kwargs) + try: command = kwargs.pop('func') except KeyError: