kernelspec
Add and remove kernel specifications for Jupyter.
Functions:
-
make_argv–Returns an argument vector (argv) that can be used to start a
Kernel. -
get_kernel_dir–The path to where kernel specs are stored for Jupyter.
-
write_kernel_spec–Write a kernel spec for launching a kernel ref.
-
validate_name–Check the name is a valid kernel name.
-
get_kernel_info–Get a dic of kernels installed in kernel_dir.
-
expand_path–Make the path absolute returning a new path object.
-
import_launcher–Import a custom launcher or the default launcher.
Attributes:
-
PROTOCOL_VERSION(str) –The protocol that is supported by the kernel.
-
DEFAULT_LAUNCHER(str) –An importable path to the default interface to start the kernel.
-
DEFAULT_COMMAND(tuple[str, ...]) –
PROTOCOL_VERSION
module-attribute
¶
PROTOCOL_VERSION: str = '5.5'
The protocol that is supported by the kernel.
DEFAULT_LAUNCHER
module-attribute
¶
DEFAULT_LAUNCHER: str = 'launch_interface'
An importable path to the default interface to start the kernel.
DEFAULT_COMMAND
module-attribute
¶
DEFAULT_COMMAND: tuple[str, ...] = (sys.executable, '-m', 'async_kernel', 'start')
- Reference kernelspec
make_argv
¶
make_argv(
*,
connection_file: str = "{connection_file}",
name: str = "async",
launcher: str | InterfaceStartType = "",
command: tuple[str, ...] = DEFAULT_COMMAND,
flags: Iterable[str] = (),
**kwargs: Any,
) -> list[str]
Returns an argument vector (argv) that can be used to start a Kernel.
This function returns a list of arguments can be used directly start a kernel with subprocess.Popen. It will always call command.command_line as a python module.
Parameters:
-
(connection_file¶str, default:'{connection_file}') –The path to the connection file.
-
(launcher¶str | InterfaceStartType, default:'') –A self-contained function that accepts a dict of settings. Or as string import path to a callable responsible for launching the interface.
-
(name¶str, default:'async') –The name to use for the kernel.
-
(command¶tuple[str, ...], default:DEFAULT_COMMAND) –The command line command to call.
-
(flags¶Iterable[str], default:()) –Any number of flags to insert in argv. Flags will be prefixed with '--'.
-
(**kwargs¶Any, default:{}) –Additional settings to pass when creating the kernel passed to
launcher.
Returns:
-
Reference
interface
start_kernel_callable_interface
Source code in src/async_kernel/kernelspec.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
get_kernel_dir
¶
The path to where kernel specs are stored for Jupyter.
If folder is passed, it is assumed to be the full path ending in 'kernels', prefix is ignored.
Parameters:
-
(folder¶str, default:'') –The path to 'kernels' (must end with 'kernels').
-
(prefix¶str, default:'') –Defaults to sys.prefix (installable for a particular environment).
-
(user¶bool, default:False) –Install for the user.
Search locations: https://jupyter-client.readthedocs.io/en/latest/kernels.html#kernel-specs
Source code in src/async_kernel/kernelspec.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
write_kernel_spec
¶
write_kernel_spec(
*,
path: Path | str | None = None,
name: str = "async",
display_name: str = "",
user: bool = False,
prefix: str = "",
folder: str = "",
launcher: str | InterfaceStartType = "",
command: tuple[str, ...] = DEFAULT_COMMAND,
connection_file: str = "{connection_file}",
env: dict | None = None,
metadata: dict | None = None,
language="python",
resources: Path | None = RESOURCES,
flags: Iterable[str] = (),
**kwargs: Any,
) -> Path
Write a kernel spec for launching a kernel ref.
Parameters:
-
(path¶Path | str | None, default:None) –The path where to write the spec.
-
(name¶str, default:'async') –The name of the kernel to use.
-
(display_name¶str, default:'') –The display name for Jupyter to use for the kernel. The default is
"Python ({name})". -
(user¶bool, default:False) –To work with the user profile directory.
-
(prefix¶str, default:'') –When provided the kernelspec will be installed to PREFIX/share/jupyter/kernels/KERNEL_NAME. This can be sys.prefix for installation inside virtual or conda envs.
-
(folder¶str, default:'') –A direct path the the kernel spec folder (must end with a folder named 'kernels').
-
(launcher¶str | InterfaceStartType, default:'') –The string import path to a callable that creates the Kernel or, a self-contained function that returns an instance of a
Kernel. -
(command¶tuple[str, ...], default:DEFAULT_COMMAND) –The command to execute to invoke the launcher.
-
(connection_file¶str, default:'{connection_file}') –The path to the connection file.
-
(env¶dict | None, default:None) –A mapping environment variables for the kernel to set prior to starting.
-
(metadata¶dict | None, default:None) –A mapping of additional attributes to aid the client in kernel selection.
-
(resources¶Path | None, default:RESOURCES) –The path to the resources folder to include with the kernel spec.
-
(flags¶Iterable[str], default:()) –Flags to insert directly into the argv string.
-
(**kwargs¶Any, default:{}) –Pass additional settings to set on the instance of the
Kernelwhen it is instantiated. Each setting should correspond to the dotted path to the attribute relative to the kernel. For example..., **{'timeout'=0.1}).
Source code in src/async_kernel/kernelspec.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
validate_name
¶
validate_name(name: str) -> None
Check the name is a valid kernel name.
Raises:
-
ValueError–If the name is not valid.
Source code in src/async_kernel/kernelspec.py
220 221 222 223 224 225 226 227 228 229 | |
get_kernel_info
¶
Get a dic of kernels installed in kernel_dir.
Source code in src/async_kernel/kernelspec.py
246 247 248 249 250 251 252 253 | |
expand_path
¶
Make the path absolute returning a new path object.
Parameters:
Substitutions
- Windows environment variables are accepted such as
%APPDATA%and%PROGRAMDATA%. -~is also substituted with pathlib.Path.expanduser.
Source code in src/async_kernel/kernelspec.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
import_launcher
¶
Import a custom launcher or the default launcher.
Parameters:
Returns:
-
callable(InterfaceStartType) –The imported function responsible for launching the interface.
- Reference interface
Source code in src/async_kernel/kernelspec.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |