From 0efd1a0a4265642be1444775d35d5ca722a2c6eb Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Sat, 31 May 2025 20:23:29 +0530 Subject: [PATCH 1/2] DEV: Fix duplication of docs in extend_command Signed-off-by: Gagandeep Singh --- spin/cmds/util.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spin/cmds/util.py b/spin/cmds/util.py index e0ca361..f79dae3 100644 --- a/spin/cmds/util.py +++ b/spin/cmds/util.py @@ -170,9 +170,15 @@ def parent_cmd(*user_args, **user_kwargs): my_cmd.callback = click.pass_context(callback_with_parent_callback) my_cmd.callback._parent = user_func # type: ignore[attr-defined] + # If doc is present then combine it with user_func.__doc__ + # Otherwise override it with user_func.__doc__ + # if it is not empty. if doc is not None: - my_cmd.help = doc - my_cmd.help = (my_cmd.help or "") + "\n\n" + (user_func.__doc__ or "") + my_cmd.help = doc + "\n\n" + (user_func.__doc__ or "") + else: + my_cmd.help = (my_cmd.help or "") + if user_func.__doc__ is not None: + my_cmd.help = user_func.__doc__ my_cmd.help = my_cmd.help.strip() my_cmd.name = user_func.__name__.replace("_", "-") From a4c02611a16e9b59c6edd22ce1732ddc1bb804b9 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Sat, 31 May 2025 20:23:43 +0530 Subject: [PATCH 2/2] TEST: Updated tests for extend_command Signed-off-by: Gagandeep Singh --- spin/tests/test_extend_command.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spin/tests/test_extend_command.py b/spin/tests/test_extend_command.py index 9677e9f..547e8c8 100644 --- a/spin/tests/test_extend_command.py +++ b/spin/tests/test_extend_command.py @@ -28,6 +28,7 @@ def build_ext(*, parent_callback, extra=None, **kwargs): assert "Additional docstring" in get_usage(build_ext) assert "Additional docstring" not in get_usage(cmds.meson.build) + assert get_usage(cmds.meson.build) not in get_usage(build_ext) @extend_command(cmds.meson.build, doc="Hello world") def build_ext(*, parent_callback, extra=None, **kwargs): @@ -39,6 +40,7 @@ def build_ext(*, parent_callback, extra=None, **kwargs): doc = get_usage(build_ext) assert "Hello world\n" in doc assert "\n Additional docstring" in doc + assert get_usage(cmds.meson.build) not in get_usage(build_ext) def test_ext_additional_args():