Skip to content

Fix duplication of docs in extend_command #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions spin/cmds/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("_", "-")
Expand Down
2 changes: 2 additions & 0 deletions spin/tests/test_extend_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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():
Expand Down
Loading