Skip to content

Commit 8a4e6a8

Browse files
committed
Print file in which cmd is defined; print such meta-data after code.
1 parent d97c5a2 commit 8a4e6a8

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

spin/__main__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,14 @@ def group(ctx):
132132

133133
try:
134134
cmd_func = getattr(mod, func)
135+
cmd_func.module = mod # metadata for use by `introspect` command
135136
except AttributeError:
136137
print(f"!! Could not load command `{func}` from file `{path}`.\n")
137138
continue
138139

140+
# Save command definition for use in `introspect`
141+
cmd_func.spec = cmd
142+
139143
default_kwargs = cmd_default_kwargs.get(cmd)
140144
import functools
141145

@@ -148,8 +152,6 @@ def group(ctx):
148152
if option.name in default_kwargs:
149153
option.default = default_kwargs[option.name]
150154

151-
cmd_func.spec = cmd # store where this function is defined
152-
# for use in `introspect` command
153155
commands[cmd] = cmd_func
154156

155157
group.add_command(commands[cmd], section=section)

spin/cmds/meta.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,30 @@ def introspect(*, cmd):
3131
try:
3232
code = inspect.getsource(cmd_func.callback)
3333
except TypeError:
34+
# Perhaps a partial, try again
3435
code = inspect.getsource(cmd_func.callback.func)
3536

36-
click.secho(
37-
f"The `{cmd}` command is defined in `{cmd_func.spec}`:\n",
38-
bold=True,
39-
fg="magenta",
40-
)
41-
4237
try:
4338
code = _highlight(code)
4439
except ImportError:
4540
pass
4641

4742
print(code)
4843

44+
click.secho(
45+
f"The `{cmd}` command is defined as `{cmd_func.spec}`.",
46+
bold=True,
47+
fg="magenta",
48+
)
49+
50+
click.secho(
51+
f"The code is in `{cmd_func.module.__file__}`.", bold=True, fg="magenta"
52+
)
53+
4954
if cmd_func.spec in overrides:
5055
click.secho(
51-
"The function has the following keyword overrides defined:\n",
56+
"\nThe function has the following keyword overrides defined:\n",
5257
bold=True,
5358
fg="magenta",
5459
)
55-
print(overrides[cmd_func.spec])
60+
print(" ", overrides[cmd_func.spec], "\n")

0 commit comments

Comments
 (0)