##// END OF EJS Templates
Improve API documentation around configuration of embedded IPython (#13989)...
Matthias Bussonnier -
r28197:ad452c1d merge
parent child Browse files
Show More
@@ -6,6 +6,7 b' docs/man/*.gz'
6 docs/source/api/generated
6 docs/source/api/generated
7 docs/source/config/options
7 docs/source/config/options
8 docs/source/config/shortcuts/*.csv
8 docs/source/config/shortcuts/*.csv
9 docs/source/config/shortcuts/table.tsv
9 docs/source/savefig
10 docs/source/savefig
10 docs/source/interactive/magics-generated.txt
11 docs/source/interactive/magics-generated.txt
11 docs/gh-pages
12 docs/gh-pages
@@ -56,6 +56,8 b' from .core.interactiveshell import InteractiveShell'
56 from .utils.sysinfo import sys_info
56 from .utils.sysinfo import sys_info
57 from .utils.frame import extract_module_locals
57 from .utils.frame import extract_module_locals
58
58
59 __all__ = ["start_ipython", "embed", "start_kernel", "embed_kernel"]
60
59 # Release data
61 # Release data
60 __author__ = '%s <%s>' % (release.author, release.author_email)
62 __author__ = '%s <%s>' % (release.author, release.author_email)
61 __license__ = release.license
63 __license__ = release.license
@@ -82,7 +84,8 b' def embed_kernel(module=None, local_ns=None, **kwargs):'
82 The namespace to load into IPython user namespace (default: caller)
84 The namespace to load into IPython user namespace (default: caller)
83 **kwargs : various, optional
85 **kwargs : various, optional
84 Further keyword args are relayed to the IPKernelApp constructor,
86 Further keyword args are relayed to the IPKernelApp constructor,
85 allowing configuration of the Kernel. Will only have an effect
87 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
88 allowing configuration of the kernel (see :ref:`kernel_options`). Will only have an effect
86 on the first embed_kernel call for a given process.
89 on the first embed_kernel call for a given process.
87 """
90 """
88
91
@@ -118,7 +121,8 b' def start_ipython(argv=None, **kwargs):'
118 specify this dictionary to initialize the IPython user namespace with particular values.
121 specify this dictionary to initialize the IPython user namespace with particular values.
119 **kwargs : various, optional
122 **kwargs : various, optional
120 Any other kwargs will be passed to the Application constructor,
123 Any other kwargs will be passed to the Application constructor,
121 such as `config`.
124 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
125 allowing configuration of the instance (see :ref:`terminal_options`).
122 """
126 """
123 from IPython.terminal.ipapp import launch_new_instance
127 from IPython.terminal.ipapp import launch_new_instance
124 return launch_new_instance(argv=argv, **kwargs)
128 return launch_new_instance(argv=argv, **kwargs)
@@ -132,7 +136,7 b' def start_kernel(argv=None, **kwargs):'
132
136
133 `start_kernel()` does full, regular IPython initialization,
137 `start_kernel()` does full, regular IPython initialization,
134 including loading startup files, configuration, etc.
138 including loading startup files, configuration, etc.
135 much of which is skipped by `embed()`.
139 much of which is skipped by `embed_kernel()`.
136
140
137 Parameters
141 Parameters
138 ----------
142 ----------
@@ -143,7 +147,8 b' def start_kernel(argv=None, **kwargs):'
143 specify this dictionary to initialize the IPython user namespace with particular values.
147 specify this dictionary to initialize the IPython user namespace with particular values.
144 **kwargs : various, optional
148 **kwargs : various, optional
145 Any other kwargs will be passed to the Application constructor,
149 Any other kwargs will be passed to the Application constructor,
146 such as `config`.
150 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
151 allowing configuration of the kernel (see :ref:`kernel_options`).
147 """
152 """
148 import warnings
153 import warnings
149
154
@@ -350,7 +350,7 b' class InteractiveShellEmbed(TerminalInteractiveShell):'
350 def embed(*, header="", compile_flags=None, **kwargs):
350 def embed(*, header="", compile_flags=None, **kwargs):
351 """Call this to embed IPython at the current point in your program.
351 """Call this to embed IPython at the current point in your program.
352
352
353 The first invocation of this will create an :class:`InteractiveShellEmbed`
353 The first invocation of this will create a :class:`terminal.embed.InteractiveShellEmbed`
354 instance and then call it. Consecutive calls just call the already
354 instance and then call it. Consecutive calls just call the already
355 created instance.
355 created instance.
356
356
@@ -369,8 +369,18 b' def embed(*, header="", compile_flags=None, **kwargs):'
369 d = 40
369 d = 40
370 embed()
370 embed()
371
371
372 Full customization can be done by passing a :class:`Config` in as the
372 Parameters
373 config argument.
373 ----------
374
375 header : str
376 Optional header string to print at startup.
377 compile_flags
378 Passed to the `compile_flags` parameter of :py:meth:`terminal.embed.InteractiveShellEmbed.mainloop()`,
379 which is called when the :class:`terminal.embed.InteractiveShellEmbed` instance is called.
380 **kwargs : various, optional
381 Any other kwargs will be passed to the :class:`terminal.embed.InteractiveShellEmbed` constructor.
382 Full customization can be done by passing a traitlets :class:`Config` in as the
383 `config` argument (see :ref:`configure_start_ipython` and :ref:`terminal_options`).
374 """
384 """
375 config = kwargs.get('config')
385 config = kwargs.get('config')
376 if config is None:
386 if config is None:
@@ -26,7 +26,7 b' the following tools are needed to build the documentation:'
26 In a conda environment, or a Python 3 ``venv``, you should be able to run::
26 In a conda environment, or a Python 3 ``venv``, you should be able to run::
27
27
28 cd ipython
28 cd ipython
29 pip install .[doc] -U
29 pip install -U -r docs/requirements.txt
30
30
31
31
32 Build Commands
32 Build Commands
@@ -66,10 +66,13 b" if __name__ == '__main__':"
66 # them as part of the public API. They must have __all__ defined. The
66 # them as part of the public API. They must have __all__ defined. The
67 # non-API modules they import from should be excluded by the skip patterns
67 # non-API modules they import from should be excluded by the skip patterns
68 # above.
68 # above.
69 docwriter.names_from__all__.update({
69 docwriter.names_from__all__.update(
70 'IPython.display',
70 {
71 })
71 "IPython",
72
72 "IPython.display",
73 }
74 )
75
73 # Now, generate the outputs
76 # Now, generate the outputs
74 docwriter.write_api_docs(outdir)
77 docwriter.write_api_docs(outdir)
75 # Write index with .txt extension - we can include it, but Sphinx won't try
78 # Write index with .txt extension - we can include it, but Sphinx won't try
@@ -103,6 +103,7 b' def write_doc(name, title, app, preamble=None):'
103 trait_aliases = reverse_aliases(app)
103 trait_aliases = reverse_aliases(app)
104 filename = options / (name + ".rst")
104 filename = options / (name + ".rst")
105 with open(filename, "w", encoding="utf-8") as f:
105 with open(filename, "w", encoding="utf-8") as f:
106 f.write(".. _" + name + "_options:" + "\n\n")
106 f.write(title + "\n")
107 f.write(title + "\n")
107 f.write(("=" * len(title)) + "\n")
108 f.write(("=" * len(title)) + "\n")
108 f.write("\n")
109 f.write("\n")
@@ -17,7 +17,7 b' from IPython.terminal.shortcuts.filters import KEYBINDING_FILTERS'
17 @dataclass
17 @dataclass
18 class Shortcut:
18 class Shortcut:
19 #: a sequence of keys (each element on the list corresponds to pressing one or more keys)
19 #: a sequence of keys (each element on the list corresponds to pressing one or more keys)
20 keys_sequence: list[str]
20 keys_sequence: List[str]
21 filter: str
21 filter: str
22
22
23
23
@@ -146,7 +146,7 b' def format_prompt_keys(keys: str, add_alternatives=True) -> str:'
146 escaped = key.replace("\\", "\\\\")
146 escaped = key.replace("\\", "\\\\")
147 return f":kbd:`{escaped}`"
147 return f":kbd:`{escaped}`"
148
148
149 keys_to_press: list[str]
149 keys_to_press: List[str]
150
150
151 prefixes = {
151 prefixes = {
152 "c-s-": [to_rst("ctrl"), to_rst("shift")],
152 "c-s-": [to_rst("ctrl"), to_rst("shift")],
@@ -153,7 +153,7 b' Running IPython from Python'
153
153
154 If you are using :ref:`embedding` to start IPython from a normal
154 If you are using :ref:`embedding` to start IPython from a normal
155 python file, you can set configuration options the same way as in a
155 python file, you can set configuration options the same way as in a
156 config file by creating a traitlets config object and passing it to
156 config file by creating a traitlets :class:`Config` object and passing it to
157 start_ipython like in the example below.
157 start_ipython like in the example below.
158
158
159 .. literalinclude:: ../../../examples/Embedding/start_ipython_config.py
159 .. literalinclude:: ../../../examples/Embedding/start_ipython_config.py
@@ -3,8 +3,8 b' IPython options'
3 ===============
3 ===============
4
4
5 Any of the options listed here can be set in config files, at the
5 Any of the options listed here can be set in config files, at the
6 command line, or from inside IPython. See :ref:`setting_config` for
6 command line, from inside IPython, or using a traitlets :class:`Config` object.
7 details.
7 See :ref:`setting_config` for details.
8
8
9 .. toctree::
9 .. toctree::
10
10
General Comments 0
You need to be logged in to leave comments. Login now