plugin#

plugin_help.abort() None[source]#

Abort console to discard all changes.

plugin_help.dump_wrapper(wrapper: Wrapper | None = None) None[source]#

Dump wrapper to file.

plugin_help.ensure_import(module: str, dependencies: None | str | Sequence[str] = None) module[source]#

Import the module, if it does not exist, try to install the dependencies, and then import it again.

Parameters:
  • module – The module is being tested for existence.

  • dependencies – If the module does not exist, install these dependencies. If the dependencies is None, install the module as dependencies directly.

plugin_help.exit() None[source]#

Exit console for no more operations.

plugin_help.get_container(wrapper=None) Mapping[source]#

Get the sigil containers.

plugin_help.install(module: str, /, *modules: str, upgrade: bool = False, index_url: str | None = None, trusted_host: str | None = None, other_args: Iterable[str] = (), new_process: bool = True)#

Use the pip install command with the same arguments as the command line.

plugin_help.load_script(path: str, globals: dict | None = None, include_single: bool = False, include__dunder: bool = False, include__special__: bool = False, _cre=re.compile('^(?P<special>__.+__)|(?P<dunder>__.*)|(?P<single>_.*)|(?P<normal>.*)$', re.DOTALL)) dict | None[source]#

To execute or register some script.

Parameters:
  • path – Path of a script (a file or folder).

  • globals – The global namespace used to execute the script.

  • include_single – Determine whether to include these key-value pairs that their keys are like _var.

  • include__dunder – Determine whether to include these key-value pairs that their keys are like __var.

  • include__special__ – Determine whether to include these key-value pairs that their keys are like __var__.

Returns:

dict (that is for updating) means that the script has been executed, None means that the script (as a package) has been appended to sys.path.

TIPS: It will deal with the following situations separately:
  1. A file (e.g., suffixed by .py or .pyz), or a folder (or a .zip file) with __main__.py, will be executed directly.

  2. A folder (or .zip file) without __main__.py will be appended to sys.path.

Tips: In the result dictionary of the script (result is the return value of runpy.run_path),

all the key-value pairs, their keys are not excluded and their values are different from those of the same key in globals, were updated to globals.

plugin_help.load_wrapper() Wrapper[source]#

Load wrapper from file.

plugin_help.register_console(func_or_key: K | Callable, /, key: K | None = None)#

Register a console with a specified name.

You can register a function with the name “console_name” through these ways

@register_console("console_name")
def start_specific_console():
    ...

OR

@register_console
def console_name():
    ...
plugin_help.run_env(forcible_execution: bool = False, /) None[source]#

Run env.py, to inject some configuration and global variables

plugin_help.run_plugin(file_or_dir: str, bc: BookContainer | None = None, run_in_process: bool = False, executable: str = '/home/docs/checkouts/readthedocs.org/user_builds/sigil-console/envs/latest/bin/python')[source]#

Running a Sigil plug-in

Parameters:
  • file_or_dir – Path of Sigil plug-in folder or script file.

  • bcBookContainer object. If it is None (the default), will be found in caller’s globals(). BookContainer object is an object of ePub book content provided by Sigil, which can be used to access and operate the files in ePub.

  • run_in_process – Determine whether to run the program in a child process.

Returns:

If run_in_process is True, return subprocess.CompletedProcess, else return the return value of the plugin function.

plugin_help.start_console(name: str, /)[source]#

Run a console with a specified name.

plugin_help.start_embedded_python_shell(shell: str | None = None, namespace: dict | None = None, banner: str = '')[source]#

Start the specified embedded Python shell.

plugin_help.uninstall(module: str, /, *modules: str, other_args: Iterable[str] = ('--yes',), new_process: bool = False)#

Use the pip uninstall command with the same arguments as the command line.