MCPcopy
hub / github.com/lektor/lektor / shell_cmd

Function shell_cmd

lektor/devcli.py:47–92  ·  view source on GitHub ↗

Starts a Python shell in the context of a Lektor project. This is particularly useful for debugging plugins and to explore the API. To quit the shell just use `quit()`. Within the shell various utilities are available right from the get-go for you. \b - `project`: the loaded

(ctx, extra_flags)

Source from the content-addressed store, hash-verified

45@extraflag
46@pass_context
47def shell_cmd(ctx, extra_flags):
48 """Starts a Python shell in the context of a Lektor project.
49
50 This is particularly useful for debugging plugins and to explore the
51 API. To quit the shell just use `quit()`. Within the shell various
52 utilities are available right from the get-go for you.
53
54 \b
55 - `project`: the loaded project as object.
56 - `env`: an environment for the loaded project.
57 - `pad`: a database pad initialized for the project and environment
58 that is ready to use.
59 """
60 ctx.load_plugins(extra_flags=extra_flags)
61 import code
62 from lektor.db import F, Tree
63 from lektor.builder import Builder
64
65 banner = "Python %s on %s\nLektor Project: %s" % (
66 sys.version,
67 sys.platform,
68 ctx.get_env().root_path,
69 )
70 ns = {}
71 startup = os.environ.get("PYTHONSTARTUP")
72 if startup and os.path.isfile(startup):
73 with open(startup, "r", encoding="utf-8") as f:
74 eval(compile(f.read(), startup, "exec"), ns) # pylint: disable=eval-used
75 pad = ctx.get_env().new_pad()
76 ns.update(
77 project=ctx.get_project(),
78 env=ctx.get_env(),
79 pad=pad,
80 tree=Tree(pad),
81 config=ctx.get_env().load_config(),
82 make_builder=lambda: Builder(
83 ctx.get_env().new_pad(), ctx.get_default_output_path()
84 ),
85 F=F,
86 )
87 try:
88 c = Config()
89 c.TerminalInteractiveShell.banner2 = banner
90 embed(config=c, user_ns=ns)
91 except NameError: # No IPython
92 code.interact(banner=banner, local=ns)
93
94
95@cli.command("publish-plugin", short_help="Publish a plugin to PyPI.")

Callers

nothing calls this directly

Calls 11

TreeClass · 0.90
BuilderClass · 0.90
ConfigClass · 0.85
get_envMethod · 0.80
get_projectMethod · 0.80
load_configMethod · 0.80
load_pluginsMethod · 0.45
getMethod · 0.45
new_padMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected