CLI
kedro.framework.cli ¶
kedro.framework.cli implements commands available from Kedro's CLI.
| Submodule | Description |
|---|---|
kedro.framework.cli.catalog |
A collection of CLI commands for working with Kedro catalog. |
kedro.framework.cli.cli |
kedro is a CLI for managing Kedro projects. |
kedro.framework.cli.hooks |
Provides primitives to use hooks to extend KedroCLI's behavior. |
kedro.framework.cli.jupyter |
A collection of helper functions to integrate with Jupyter/IPython. |
kedro.framework.cli.pipeline |
A collection of CLI commands for working with Kedro pipelines. |
kedro.framework.cli.project |
A collection of CLI commands for working with Kedro projects. |
kedro.framework.cli.registry |
A collection of CLI commands for working with registered Kedro pipelines. |
kedro.framework.cli.starters |
kedro is a CLI for managing Kedro projects. |
kedro.framework.cli.utils |
Utilities for use with click. |
kedro.framework.cli.catalog ¶
A collection of CLI commands for working with Kedro catalog.
KedroSession ¶
KedroSession(session_id, package_name=None, project_path=None, save_on_close=False, conf_source=None)
KedroSession is the object that is responsible for managing the lifecycle
of a Kedro run. Use KedroSession.create() as
a context manager to construct a new KedroSession with session data
provided (see the example below).
Example:
from kedro.framework.session import KedroSession
from kedro.framework.startup import bootstrap_project
from pathlib import Path
# If you are creating a session outside of a Kedro project (i.e. not using
# `kedro run` or `kedro jupyter`), you need to run `bootstrap_project` to
# let Kedro find your configuration.
bootstrap_project(Path("<project_root>"))
with KedroSession.create() as session:
session.run()
Source code in kedro/framework/session/session.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
close ¶
close()
Close the current session and save its store to disk
if save_on_close attribute is True.
Source code in kedro/framework/session/session.py
265 266 267 268 269 270 | |
create
classmethod
¶
create(project_path=None, save_on_close=True, env=None, runtime_params=None, conf_source=None)
Create a new instance of KedroSession with the session data.
Parameters:
-
project_path(Path | str | None, default:None) –Path to the project root directory. Default is current working directory Path.cwd().
-
save_on_close(bool, default:True) –Whether or not to save the session when it's closed.
-
conf_source(str | None, default:None) –Path to a directory containing configuration
-
env(str | None, default:None) –Environment for the KedroContext.
-
runtime_params(dict[str, Any] | None, default:None) –Optional dictionary containing extra project parameters for underlying KedroContext. If specified, will update (and therefore take precedence over) the parameters retrieved from the project configuration.
Returns:
-
KedroSession–A new
KedroSessioninstance.
Source code in kedro/framework/session/session.py
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 | |
load_context ¶
load_context()
An instance of the project context.
Source code in kedro/framework/session/session.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
run ¶
run(pipeline_name=None, tags=None, runner=None, node_names=None, from_nodes=None, to_nodes=None, from_inputs=None, to_outputs=None, load_versions=None, namespaces=None, only_missing_outputs=False)
Runs the pipeline with a specified runner.
Parameters:
-
pipeline_name(str | None, default:None) –Name of the pipeline that is being run.
-
tags(Iterable[str] | None, default:None) –An optional list of node tags which should be used to filter the nodes of the
Pipeline. If specified, only the nodes containing any of these tags will be run. -
runner(AbstractRunner | None, default:None) –An optional parameter specifying the runner that you want to run the pipeline with.
-
node_names(Iterable[str] | None, default:None) –An optional list of node names which should be used to filter the nodes of the
Pipeline. If specified, only the nodes with these names will be run. -
from_nodes(Iterable[str] | None, default:None) –An optional list of node names which should be used as a starting point of the new
Pipeline. -
to_nodes(Iterable[str] | None, default:None) –An optional list of node names which should be used as an end point of the new
Pipeline. -
from_inputs(Iterable[str] | None, default:None) –An optional list of input datasets which should be used as a starting point of the new
Pipeline. -
to_outputs(Iterable[str] | None, default:None) –An optional list of output datasets which should be used as an end point of the new
Pipeline. -
load_versions(dict[str, str] | None, default:None) –An optional flag to specify a particular dataset version timestamp to load.
-
namespaces(Iterable[str] | None, default:None) –The namespaces of the nodes that are being run.
-
only_missing_outputs(bool, default:False) –Run only nodes with missing outputs.
Raises:
ValueError: If the named or __default__ pipeline is not
defined by register_pipelines.
Exception: Any uncaught exception during the run will be re-raised
after being passed to on_pipeline_error hook.
KedroSessionError: If more than one run is attempted to be executed during
a single session.
Returns:
Dictionary with pipeline outputs, where keys are dataset names
and values are dataset objects.
Source code in kedro/framework/session/session.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
ProjectMetadata ¶
Bases: NamedTuple
Structure holding project metadata derived from pyproject.toml
_create_session ¶
_create_session(package_name, **kwargs)
Source code in kedro/framework/cli/catalog.py
18 19 20 | |
catalog ¶
catalog()
Commands for working with catalog.
Source code in kedro/framework/cli/catalog.py
28 29 30 | |
catalog_cli ¶
catalog_cli()
Source code in kedro/framework/cli/catalog.py
23 24 25 | |
describe_datasets ¶
describe_datasets(metadata, pipeline, env)
Describe datasets used in the specified pipelines, grouped by type.
This command provides a structured overview of datasets used in the selected pipelines, categorizing them into three groups:
-
datasets: Datasets explicitly defined in the catalog. -
factories: Datasets resolved from dataset factory patterns. -
defaults: Datasets that do not match any pattern or explicit definition.
Source code in kedro/framework/cli/catalog.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
env_option ¶
env_option(func_=None, **kwargs)
Add --env CLI option to a function.
Source code in kedro/framework/cli/utils.py
314 315 316 317 318 319 | |
list_patterns ¶
list_patterns(metadata, env)
List all dataset factory patterns in the catalog, ranked by priority.
This method retrieves all dataset factory patterns defined in the catalog, ordered by the priority in which they are matched.
Source code in kedro/framework/cli/catalog.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
resolve_patterns ¶
resolve_patterns(metadata, pipeline, env)
Resolve dataset factory patterns against pipeline datasets.
This method resolves dataset factory patterns for datasets used in the specified pipelines. It includes datasets explicitly defined in the catalog as well as those resolved from dataset factory patterns.
Source code in kedro/framework/cli/catalog.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
split_string ¶
split_string(ctx, param, value)
Split string by comma.
Source code in kedro/framework/cli/utils.py
274 275 276 | |
kedro.framework.cli.cli ¶
kedro is a CLI for managing Kedro projects.
This module implements commands available from the kedro CLI.
ENTRY_POINT_GROUPS
module-attribute
¶
ENTRY_POINT_GROUPS = {'global': 'kedro.global_commands', 'project': 'kedro.project_commands', 'init': 'kedro.init', 'line_magic': 'kedro.line_magic', 'hooks': 'kedro.hooks', 'cli_hooks': 'kedro.cli_hooks', 'starters': 'kedro.starters'}
LOGO
module-attribute
¶
LOGO = f'
_ _
| | _____ __| |_ __ ___
| |/ / _ \/ _` | '__/ _ \
| < __/ (_| | | | (_) |
|_|\_\___|\__,_|_| \___/
v{__version__}
'
CommandCollection ¶
CommandCollection(*groups)
Bases: CommandCollection
Modified from the Click one to still run the source groups function.
Source code in kedro/framework/cli/utils.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
KedroCLI ¶
KedroCLI(project_path)
Bases: CommandCollection
A CommandCollection class to encapsulate the KedroCLI command loading.
Source code in kedro/framework/cli/cli.py
131 132 133 134 135 136 137 138 139 140 | |
global_groups
property
¶
global_groups
Property which loads all global command groups from plugins and combines them with the built-in ones (eventually overriding the built-in ones if they are redefined by plugins).
project_groups
property
¶
project_groups
Property which loads all project command groups from the project and the plugins, then combines them with the built-in ones. Built-in commands can be overridden by plugins, which can be overridden by a custom project cli.py. See https://docs.kedro.org/en/stable/extend_kedro/common_use_cases.html#use-case-3-how-to-add-or-modify-cli-commands on how to add this.
KedroCliError ¶
Bases: ClickException
Exceptions generated from the Kedro CLI.
Users should pass an appropriate message at the constructor.
LazyGroup ¶
LazyGroup(*args, lazy_subcommands=None, **kwargs)
Bases: Group
A click Group that supports lazy loading of subcommands.
Source code in kedro/framework/cli/utils.py
513 514 515 516 517 518 519 520 521 522 523 524 | |
_get_entry_points ¶
_get_entry_points(name)
Get all kedro related entry points
Source code in kedro/framework/cli/utils.py
332 333 334 335 336 | |
_init_plugins ¶
_init_plugins()
Source code in kedro/framework/cli/cli.py
120 121 122 123 | |
bootstrap_project ¶
bootstrap_project(project_path)
Run setup required at the beginning of the workflow when running in project mode, and return project metadata.
Source code in kedro/framework/startup.py
152 153 154 155 156 157 158 159 160 161 | |
cli ¶
cli()
Kedro is a CLI for creating and using Kedro projects. For more
information, type kedro info.
NOTE: If a command from a plugin conflicts with a built-in command from Kedro, the command from the plugin will take precedence.
Source code in kedro/framework/cli/cli.py
46 47 48 49 50 51 52 53 54 55 56 | |
find_kedro_project ¶
find_kedro_project(current_dir)
Given a path, find a Kedro project associated with it.
Can be
- Itself, if a path is a root directory of a Kedro project.
- One of its parents, if self is not a Kedro project but one of the parent path is.
- None, if neither self nor any parent path is a Kedro project.
Returns:
-
Any–Kedro project associated with a given path,
-
Any–or None if no relevant Kedro project is found.
Source code in kedro/utils.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_cli_hook_manager ¶
get_cli_hook_manager()
Create or return the global _hook_manager singleton instance.
Source code in kedro/framework/cli/hooks/manager.py
17 18 19 20 21 22 23 24 25 26 | |
global_commands ¶
global_commands()
Source code in kedro/framework/cli/cli.py
107 108 109 110 111 112 113 114 115 116 117 | |
info ¶
info()
Get more information about kedro.
Source code in kedro/framework/cli/cli.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
is_kedro_project ¶
is_kedro_project(project_path)
Evaluate if a given path is a root directory of a Kedro project or not.
Parameters:
-
project_path(Union[str, Path]) –Path to be tested for being a root of a Kedro project.
Returns:
-
bool–True if a given path is a root directory of a Kedro project, otherwise False.
Source code in kedro/utils.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
load_entry_points ¶
load_entry_points(name)
Load package entry point commands.
Parameters:
-
name(str) –The key value specified in ENTRY_POINT_GROUPS.
Raises:
-
KedroCliError–If loading an entry point failed.
Returns:
-
Sequence[MultiCommand]–List of entry point commands.
Source code in kedro/framework/cli/utils.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
main ¶
main()
Main entry point. Look for a cli.py, and, if found, add its
commands to kedro's before invoking the CLI.
Source code in kedro/framework/cli/cli.py
254 255 256 257 258 259 260 | |
project_commands ¶
project_commands()
Source code in kedro/framework/cli/cli.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
kedro.framework.cli.hooks ¶
kedro.framework.cli.hooks provides primitives to use hooks to extend KedroCLI's behaviour
CLIHooksManager ¶
CLIHooksManager()
Bases: PluginManager
Hooks manager to manage CLI hooks
Source code in kedro/framework/cli/hooks/manager.py
32 33 34 35 | |
get_cli_hook_manager ¶
get_cli_hook_manager()
Create or return the global _hook_manager singleton instance.
Source code in kedro/framework/cli/hooks/manager.py
17 18 19 20 21 22 23 24 25 26 | |
kedro.framework.cli.jupyter ¶
A collection of helper functions to integrate with Jupyter/IPython and CLI commands for working with Kedro catalog.
KedroCliError ¶
Bases: ClickException
Exceptions generated from the Kedro CLI.
Users should pass an appropriate message at the constructor.
ProjectMetadata ¶
Bases: NamedTuple
Structure holding project metadata derived from pyproject.toml
_check_module_importable ¶
_check_module_importable(module_name)
Source code in kedro/framework/cli/utils.py
322 323 324 325 326 327 328 329 | |
_create_kernel ¶
_create_kernel(kernel_name, display_name)
Creates an IPython kernel for the kedro project. If one with the same kernel_name exists already it will be replaced.
Installs the default IPython kernel (which points towards sys.executable)
and customises it to make the launch command load the kedro extension.
This is equivalent to the method recommended for creating a custom IPython kernel
on the CLI: https://ipython.readthedocs.io/en/stable/install/kernel_install.html.
On linux this creates a directory ~/.local/share/jupyter/kernels/{kernel_name} containing kernel.json, logo-32x32.png, logo-64x64.png and logo-svg.svg. An example kernel.json looks as follows:
{ "argv": [ "/Users/antony_milne/miniconda3/envs/spaceflights/bin/python", "-m", "ipykernel_launcher", "-f", "{connection_file}", "--ext", "kedro.ipython" ], "display_name": "Kedro (spaceflights)", "language": "python", "metadata": { "debugger": false } }
Parameters:
-
kernel_name(str) –Name of the kernel to create.
-
display_name(str) –Kernel name as it is displayed in the UI.
Returns:
-
str–String of the path of the created kernel.
Raises:
-
KedroCliError–When kernel cannot be setup.
Source code in kedro/framework/cli/jupyter.py
106 107 108 109 110 111 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 | |
env_option ¶
env_option(func_=None, **kwargs)
Add --env CLI option to a function.
Source code in kedro/framework/cli/utils.py
314 315 316 317 318 319 | |
forward_command ¶
forward_command(group, name=None, forward_help=False)
A command that receives the rest of the command line as 'args'.
Source code in kedro/framework/cli/utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
jupyter ¶
jupyter()
Open Jupyter Notebook / Lab with project specific variables loaded.
Source code in kedro/framework/cli/jupyter.py
33 34 35 | |
jupyter_cli ¶
jupyter_cli()
Source code in kedro/framework/cli/jupyter.py
28 29 30 | |
jupyter_lab ¶
jupyter_lab(metadata, /, env, args, **kwargs)
Open Jupyter Lab with project specific variables loaded.
Source code in kedro/framework/cli/jupyter.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
jupyter_notebook ¶
jupyter_notebook(metadata, /, env, args, **kwargs)
Open Jupyter Notebook with project specific variables loaded.
Source code in kedro/framework/cli/jupyter.py
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 | |
python_call ¶
python_call(module, arguments, **kwargs)
Run a subprocess command that invokes a Python module.
Source code in kedro/framework/cli/utils.py
64 65 66 67 68 | |
setup ¶
setup(metadata, /, args, **kwargs)
Initialise the Jupyter Kernel for a kedro project.
Source code in kedro/framework/cli/jupyter.py
38 39 40 41 42 43 44 45 46 47 | |
validate_settings ¶
validate_settings()
Eagerly validate that the settings module is importable if it exists. This is desirable to
surface any syntax or import errors early. In particular, without eagerly importing
the settings module, dynaconf would silence any import error (e.g. missing
dependency, missing/mislabelled pipeline), and users would instead get a cryptic
error message Expected an instance of `ConfigLoader`, got `NoneType` instead.
More info on the dynaconf issue: https://github.com/dynaconf/dynaconf/issues/460
Source code in kedro/framework/project/__init__.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
kedro.framework.cli.pipeline ¶
A collection of CLI commands for working with Kedro pipelines.
_SETUP_PY_TEMPLATE
module-attribute
¶
_SETUP_PY_TEMPLATE = '# -*- coding: utf-8 -*-\nfrom setuptools import setup, find_packages\n\nsetup(\n name="{name}",\n version="{version}",\n description="Modular pipeline `{name}`",\n packages=find_packages(),\n include_package_data=True,\n install_requires={install_requires},\n)\n'
KedroCliError ¶
Bases: ClickException
Exceptions generated from the Kedro CLI.
Users should pass an appropriate message at the constructor.
PipelineArtifacts ¶
Bases: NamedTuple
An ordered collection of source_path, tests_path, config_paths
ProjectMetadata ¶
Bases: NamedTuple
Structure holding project metadata derived from pyproject.toml
_assert_pkg_name_ok ¶
_assert_pkg_name_ok(pkg_name)
Check that python package name is in line with PEP8 requirements.
Parameters:
-
pkg_name(str) –Candidate Python package name.
Raises:
-
KedroCliError–If package name violates the requirements.
Source code in kedro/framework/cli/pipeline.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
_check_pipeline_name ¶
_check_pipeline_name(ctx, param, value)
Source code in kedro/framework/cli/pipeline.py
71 72 73 74 | |
_clean_pycache ¶
_clean_pycache(path)
Recursively clean all pycache folders from path.
Parameters:
-
path(Path) –Existing local directory to clean pycache folders from.
Source code in kedro/framework/cli/utils.py
262 263 264 265 266 267 268 269 270 271 | |
_copy_pipeline_configs ¶
_copy_pipeline_configs(result_path, conf_path, skip_config, env)
Source code in kedro/framework/cli/pipeline.py
344 345 346 347 348 349 350 351 352 353 | |
_copy_pipeline_tests ¶
_copy_pipeline_tests(pipeline_name, result_path, project_root)
Source code in kedro/framework/cli/pipeline.py
333 334 335 336 337 338 339 340 341 | |
_create_pipeline ¶
_create_pipeline(name, template_path, output_dir)
Source code in kedro/framework/cli/pipeline.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
_delete_artifacts ¶
_delete_artifacts(*artifacts)
Source code in kedro/framework/cli/pipeline.py
356 357 358 359 360 361 362 363 364 365 366 367 368 | |
_echo_deletion_warning ¶
_echo_deletion_warning(message, **paths)
Source code in kedro/framework/cli/pipeline.py
213 214 215 216 217 218 219 220 221 222 | |
_ensure_pipelines_init_file ¶
_ensure_pipelines_init_file(pipelines_dir)
Source code in kedro/framework/cli/pipeline.py
371 372 373 374 375 376 377 378 379 380 | |
_get_artifacts_to_package ¶
_get_artifacts_to_package(project_metadata, module_path, env)
From existing project, returns in order: source_path, tests_path, config_paths
Source code in kedro/framework/cli/pipeline.py
318 319 320 321 322 323 324 325 326 327 328 329 330 | |
_get_pipeline_artifacts ¶
_get_pipeline_artifacts(project_metadata, pipeline_name, env)
Source code in kedro/framework/cli/pipeline.py
309 310 311 312 313 314 315 | |
_sync_dirs ¶
_sync_dirs(source, target, prefix='', overwrite=False)
Recursively copies source directory (or file) into target directory without
overwriting any existing files/directories in the target using the following
rules:
1) Skip any files/directories which names match with files in target,
unless overwrite=True.
2) Copy all files from source to target.
3) Recursively copy all directories from source to target.
Parameters:
-
source(Path) –A local directory to copy from, must exist.
-
target(Path) –A local directory to copy to, will be created if doesn't exist yet.
-
prefix(str, default:'') –Prefix for CLI message indentation.
Source code in kedro/framework/cli/pipeline.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
command_with_verbosity ¶
command_with_verbosity(group, *args, **kwargs)
Custom command decorator with verbose flag added.
Source code in kedro/framework/cli/utils.py
217 218 219 220 221 222 223 224 225 | |
create_pipeline ¶
create_pipeline(metadata, /, name, template_path, skip_config, env, **kwargs)
Create a new modular pipeline by providing a name.
Source code in kedro/framework/cli/pipeline.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | |
delete_pipeline ¶
delete_pipeline(metadata, /, name, env, yes, **kwargs)
Delete a modular pipeline by providing a name.
Source code in kedro/framework/cli/pipeline.py
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 | |
env_option ¶
env_option(func_=None, **kwargs)
Add --env CLI option to a function.
Source code in kedro/framework/cli/utils.py
314 315 316 317 318 319 | |
pipeline ¶
pipeline()
Commands for working with pipelines.
Source code in kedro/framework/cli/pipeline.py
82 83 84 | |
pipeline_cli ¶
pipeline_cli()
Source code in kedro/framework/cli/pipeline.py
77 78 79 | |
kedro.framework.cli.project ¶
A collection of CLI commands for working with Kedro project.
ASYNC_ARG_HELP
module-attribute
¶
ASYNC_ARG_HELP = 'Load and save node inputs and outputs asynchronously\nwith threads. If not specified, load and save datasets synchronously.'
CONFIG_FILE_HELP
module-attribute
¶
CONFIG_FILE_HELP = 'Specify a YAML configuration file to load the run\ncommand arguments from. If command line arguments are provided, they will\noverride the loaded ones.'
CONF_SOURCE_HELP
module-attribute
¶
CONF_SOURCE_HELP = 'Path of a directory where project configuration is stored.'
FROM_INPUTS_HELP
module-attribute
¶
FROM_INPUTS_HELP = 'A list of dataset names which should be used as a starting point.'
FROM_NODES_HELP
module-attribute
¶
FROM_NODES_HELP = 'A list of node names which should be used as a starting point.'
LINT_CHECK_ONLY_HELP
module-attribute
¶
LINT_CHECK_ONLY_HELP = 'Check the files for style guide violations, unsorted /\nunformatted imports, and unblackened Python code without modifying the files.'
LOAD_VERSION_HELP
module-attribute
¶
LOAD_VERSION_HELP = 'Specify a particular dataset version (timestamp) for loading.'
NAMESPACES_ARG_HELP
module-attribute
¶
NAMESPACES_ARG_HELP = 'Run only node namespaces with specified names.'
NO_DEPENDENCY_MESSAGE
module-attribute
¶
NO_DEPENDENCY_MESSAGE = "{module} is not installed. Please make sure {module} is in\nrequirements.txt and run 'pip install -r requirements.txt'."
ONLY_MISSING_OUTPUTS_HELP
module-attribute
¶
ONLY_MISSING_OUTPUTS_HELP = 'Run only nodes with missing outputs.\nIf all outputs of a node exist and are persisted, skip the node execution.'
OPEN_ARG_HELP
module-attribute
¶
OPEN_ARG_HELP = 'Open the documentation in your default browser after building.'
OUTPUT_FILE_HELP
module-attribute
¶
OUTPUT_FILE_HELP = 'Name of the file where compiled requirements should be stored.'
PARAMS_ARG_HELP
module-attribute
¶
PARAMS_ARG_HELP = "Specify extra parameters that you want to pass\nto the context initialiser. Items must be separated by comma, keys - by colon or equals sign,\nexample: param1=value1,param2=value2. Each parameter is split by the first comma,\nso parameter values are allowed to contain colons, parameter keys are not.\nTo pass a nested dictionary as parameter, separate keys by '.', example:\nparam_group.param1:value1."
PIPELINE_ARG_HELP
module-attribute
¶
PIPELINE_ARG_HELP = "Name of the registered pipeline to run.\nIf not set, the '__default__' pipeline is run."
RUNNER_ARG_HELP
module-attribute
¶
RUNNER_ARG_HELP = "Specify a runner that you want to run the pipeline with.\nAvailable runners: 'SequentialRunner', 'ParallelRunner' and 'ThreadRunner'."
TAG_ARG_HELP
module-attribute
¶
TAG_ARG_HELP = 'Construct the pipeline using only nodes which have this tag\nattached. Option can be used multiple times, what results in a\npipeline constructed from nodes having any of those tags.'
TO_NODES_HELP
module-attribute
¶
TO_NODES_HELP = 'A list of node names which should be used as an end point.'
TO_OUTPUTS_HELP
module-attribute
¶
TO_OUTPUTS_HELP = 'A list of dataset names which should be used as an end point.'
KedroSession ¶
KedroSession(session_id, package_name=None, project_path=None, save_on_close=False, conf_source=None)
KedroSession is the object that is responsible for managing the lifecycle
of a Kedro run. Use KedroSession.create() as
a context manager to construct a new KedroSession with session data
provided (see the example below).
Example:
from kedro.framework.session import KedroSession
from kedro.framework.startup import bootstrap_project
from pathlib import Path
# If you are creating a session outside of a Kedro project (i.e. not using
# `kedro run` or `kedro jupyter`), you need to run `bootstrap_project` to
# let Kedro find your configuration.
bootstrap_project(Path("<project_root>"))
with KedroSession.create() as session:
session.run()
Source code in kedro/framework/session/session.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
close ¶
close()
Close the current session and save its store to disk
if save_on_close attribute is True.
Source code in kedro/framework/session/session.py
265 266 267 268 269 270 | |
create
classmethod
¶
create(project_path=None, save_on_close=True, env=None, runtime_params=None, conf_source=None)
Create a new instance of KedroSession with the session data.
Parameters:
-
project_path(Path | str | None, default:None) –Path to the project root directory. Default is current working directory Path.cwd().
-
save_on_close(bool, default:True) –Whether or not to save the session when it's closed.
-
conf_source(str | None, default:None) –Path to a directory containing configuration
-
env(str | None, default:None) –Environment for the KedroContext.
-
runtime_params(dict[str, Any] | None, default:None) –Optional dictionary containing extra project parameters for underlying KedroContext. If specified, will update (and therefore take precedence over) the parameters retrieved from the project configuration.
Returns:
-
KedroSession–A new
KedroSessioninstance.
Source code in kedro/framework/session/session.py
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 | |
load_context ¶
load_context()
An instance of the project context.
Source code in kedro/framework/session/session.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
run ¶
run(pipeline_name=None, tags=None, runner=None, node_names=None, from_nodes=None, to_nodes=None, from_inputs=None, to_outputs=None, load_versions=None, namespaces=None, only_missing_outputs=False)
Runs the pipeline with a specified runner.
Parameters:
-
pipeline_name(str | None, default:None) –Name of the pipeline that is being run.
-
tags(Iterable[str] | None, default:None) –An optional list of node tags which should be used to filter the nodes of the
Pipeline. If specified, only the nodes containing any of these tags will be run. -
runner(AbstractRunner | None, default:None) –An optional parameter specifying the runner that you want to run the pipeline with.
-
node_names(Iterable[str] | None, default:None) –An optional list of node names which should be used to filter the nodes of the
Pipeline. If specified, only the nodes with these names will be run. -
from_nodes(Iterable[str] | None, default:None) –An optional list of node names which should be used as a starting point of the new
Pipeline. -
to_nodes(Iterable[str] | None, default:None) –An optional list of node names which should be used as an end point of the new
Pipeline. -
from_inputs(Iterable[str] | None, default:None) –An optional list of input datasets which should be used as a starting point of the new
Pipeline. -
to_outputs(Iterable[str] | None, default:None) –An optional list of output datasets which should be used as an end point of the new
Pipeline. -
load_versions(dict[str, str] | None, default:None) –An optional flag to specify a particular dataset version timestamp to load.
-
namespaces(Iterable[str] | None, default:None) –The namespaces of the nodes that are being run.
-
only_missing_outputs(bool, default:False) –Run only nodes with missing outputs.
Raises:
ValueError: If the named or __default__ pipeline is not
defined by register_pipelines.
Exception: Any uncaught exception during the run will be re-raised
after being passed to on_pipeline_error hook.
KedroSessionError: If more than one run is attempted to be executed during
a single session.
Returns:
Dictionary with pipeline outputs, where keys are dataset names
and values are dataset objects.
Source code in kedro/framework/session/session.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
ProjectMetadata ¶
Bases: NamedTuple
Structure holding project metadata derived from pyproject.toml
_check_module_importable ¶
_check_module_importable(module_name)
Source code in kedro/framework/cli/utils.py
322 323 324 325 326 327 328 329 | |
_config_file_callback ¶
_config_file_callback(ctx, param, value)
CLI callback that replaces command line options with values specified in a config file. If command line options are passed, they override config file values.
Source code in kedro/framework/cli/utils.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
_split_load_versions ¶
_split_load_versions(ctx, param, value)
Split and format the string coming from the --load-versions flag in kedro run, e.g.: "dataset1:time1,dataset2:time2" -> {"dataset1": "time1", "dataset2": "time2"}
Parameters:
-
value(str) –the string with the contents of the --load-versions flag.
Returns:
-
dict[str, str]–A dictionary with the formatted load versions data.
Source code in kedro/framework/cli/utils.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
_split_params ¶
_split_params(ctx, param, value)
Source code in kedro/framework/cli/utils.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
call ¶
call(cmd, **kwargs)
Run a subprocess command and raise if it fails.
Parameters:
-
cmd(list[str]) –List of command parts.
-
**kwargs(Any, default:{}) –Optional keyword arguments passed to
subprocess.run.
Raises:
-
Exit–If
subprocess.runreturns non-zero code.
Source code in kedro/framework/cli/utils.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
env_option ¶
env_option(func_=None, **kwargs)
Add --env CLI option to a function.
Source code in kedro/framework/cli/utils.py
314 315 316 317 318 319 | |
forward_command ¶
forward_command(group, name=None, forward_help=False)
A command that receives the rest of the command line as 'args'.
Source code in kedro/framework/cli/utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
ipython ¶
ipython(metadata, /, env, args, **kwargs)
Open IPython with project specific variables loaded.
Makes the following variables available in your IPython or Jupyter session:
-
catalog: catalog instance that contains all defined datasets; this is a shortcut forcontext.catalog. -
context: Kedro project context that provides access to Kedro's library components. -
pipelines: Pipelines defined in your pipeline registry. -
session: Kedro session that orchestrates a pipeline run.
To reload these variables (e.g. if you updated catalog.yml) use the %reload_kedro line magic,
which can also be used to see the error message if any of the variables above are undefined.
Source code in kedro/framework/cli/project.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
load_obj ¶
load_obj(obj_path, default_obj_path='')
Extract an object from a given path.
Parameters:
-
obj_path(str) –Path to an object to be extracted, including the object name.
-
default_obj_path(str, default:'') –Default object path.
Returns:
-
Any–Extracted object.
Raises:
-
AttributeError–When the object does not have the given named attribute.
Source code in kedro/utils.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
package ¶
package(metadata)
Package the Kedro project as a Python wheel and export the configuration.
This command builds a .whl file for the project and saves it to the dist/ directory.
It also packages the project's configuration (excluding any local/*.yml files)
into a separate tar.gz archive for deployment or sharing.
Both artifacts will appear in the dist/ folder, unless an older project layout is detected.
Source code in kedro/framework/cli/project.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | |
project_group ¶
project_group()
Source code in kedro/framework/cli/project.py
70 71 72 | |
run ¶
run(tags, env, runner, is_async, node_names, to_nodes, from_nodes, from_inputs, to_outputs, load_versions, pipeline, config, conf_source, params, namespaces, only_missing_outputs)
Run the pipeline.
Source code in kedro/framework/cli/project.py
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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
split_node_names ¶
split_node_names(ctx, param, to_split)
Split string by comma, ignoring commas enclosed by square parentheses.
This avoids splitting the string of nodes names on commas included in
default node names, which have the pattern
Note
to_splitwill have such commas if and only if it includes a default node name. User-defined node names cannot include commas or square brackets.- This function will no longer be necessary from Kedro 0.19.*, in which default node names will no longer contain commas
Parameters:
-
to_split(str) –the string to split safely
Returns:
-
list[str]–A list containing the result of safe-splitting the string.
Source code in kedro/framework/cli/utils.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
split_string ¶
split_string(ctx, param, value)
Split string by comma.
Source code in kedro/framework/cli/utils.py
274 275 276 | |
validate_conf_source ¶
validate_conf_source(ctx, param, value)
Validate the conf_source, only checking existence for local paths.
Source code in kedro/framework/cli/utils.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
kedro.framework.cli.registry ¶
A collection of CLI commands for working with registered Kedro pipelines.
KedroCliError ¶
Bases: ClickException
Exceptions generated from the Kedro CLI.
Users should pass an appropriate message at the constructor.
ProjectMetadata ¶
Bases: NamedTuple
Structure holding project metadata derived from pyproject.toml
command_with_verbosity ¶
command_with_verbosity(group, *args, **kwargs)
Custom command decorator with verbose flag added.
Source code in kedro/framework/cli/utils.py
217 218 219 220 221 222 223 224 225 | |
describe_registered_pipeline ¶
describe_registered_pipeline(metadata, /, name, **kwargs)
Describe a registered pipeline by providing a pipeline name.
Defaults to the __default__ pipeline.
Source code in kedro/framework/cli/registry.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
list_registered_pipelines ¶
list_registered_pipelines()
List all pipelines defined in your pipeline_registry.py file.
Source code in kedro/framework/cli/registry.py
23 24 25 26 | |
registry ¶
registry()
Commands for working with registered pipelines.
Source code in kedro/framework/cli/registry.py
18 19 20 | |
registry_cli ¶
registry_cli()
Source code in kedro/framework/cli/registry.py
13 14 15 | |
kedro.framework.cli.starters ¶
kedro is a CLI for managing Kedro projects.
This module implements commands available from the kedro CLI for creating projects.
CHECKOUT_ARG_HELP
module-attribute
¶
CHECKOUT_ARG_HELP = 'An optional tag, branch or commit to checkout in the starter repository.'
CONFIG_ARG_HELP
module-attribute
¶
CONFIG_ARG_HELP = "Non-interactive mode, using a configuration yaml file. This file\nmust supply the keys required by the template's prompts.yml. When not using a starter,\nthese are `project_name`, `repo_name` and `python_package`."
DIRECTORY_ARG_HELP
module-attribute
¶
DIRECTORY_ARG_HELP = 'An optional directory inside the repository where the starter resides.'
EXAMPLE_ARG_HELP
module-attribute
¶
EXAMPLE_ARG_HELP = 'Enter y to enable, n to disable the example pipeline.'
NUMBER_TO_TOOLS_NAME
module-attribute
¶
NUMBER_TO_TOOLS_NAME = {'1': 'Linting', '2': 'Testing', '3': 'Custom Logging', '4': 'Documentation', '5': 'Data Structure', '6': 'PySpark'}
STARTER_ARG_HELP
module-attribute
¶
STARTER_ARG_HELP = 'Specify the starter template to use when creating the project.\nThis can be the path to a local directory, a URL to a remote VCS repository supported\nby `cookiecutter` or one of the aliases listed in ``kedro starter list``.\n'
TELEMETRY_ARG_HELP
module-attribute
¶
TELEMETRY_ARG_HELP = 'Allow or not allow Kedro to collect usage analytics.\nWe cannot see nor store information contained into a Kedro project. Opt in with "yes"\nand out with "no".\n'
TOOLS_ARG_HELP
module-attribute
¶
TOOLS_ARG_HELP = "\nSelect which tools you'd like to include. By default, none are included.\n\n\nTools\n\n1) Linting: Provides a basic linting setup with Ruff\n\n2) Testing: Provides basic testing setup with pytest\n\n3) Custom Logging: Provides more logging options\n\n4) Documentation: Basic documentation setup with Sphinx\n\n5) Data Structure: Provides a directory structure for storing data\n\n6) PySpark: Provides set up configuration for working with PySpark\n\n\nExample usage:\n\nkedro new --tools=lint,test,log,docs,data,pyspark (or any subset of these options)\n\nkedro new --tools=all\n\nkedro new --tools=none\n\nFor more information on using tools, see https://docs.kedro.org/en/stable/starters/new_project_tools.html\n"
TOOLS_SHORTNAME_TO_NUMBER
module-attribute
¶
TOOLS_SHORTNAME_TO_NUMBER = {'lint': '1', 'test': '2', 'tests': '2', 'log': '3', 'logs': '3', 'docs': '4', 'doc': '4', 'data': '5', 'pyspark': '6'}
_OFFICIAL_STARTER_SPECS
module-attribute
¶
_OFFICIAL_STARTER_SPECS = [KedroStarterSpec('astro-airflow-iris', _STARTERS_REPO, 'astro-airflow-iris'), KedroStarterSpec('spaceflights-pandas', _STARTERS_REPO, 'spaceflights-pandas'), KedroStarterSpec('spaceflights-pyspark', _STARTERS_REPO, 'spaceflights-pyspark'), KedroStarterSpec('databricks-iris', _STARTERS_REPO, 'databricks-iris')]
_OFFICIAL_STARTER_SPECS_DICT
module-attribute
¶
_OFFICIAL_STARTER_SPECS_DICT = {(alias): specfor spec in _OFFICIAL_STARTER_SPECS}
_STARTERS_REPO
module-attribute
¶
_STARTERS_REPO = 'git+https://github.com/kedro-org/kedro-starters.git'
KedroCliError ¶
Bases: ClickException
Exceptions generated from the Kedro CLI.
Users should pass an appropriate message at the constructor.
KedroStarterSpec ¶
Specification of custom kedro starter template
Args:
alias: alias of the starter which shows up on kedro starter list and is used
by the starter argument of kedro new
template_path: path to a directory or a URL to a remote VCS repository supported
by cookiecutter
directory: optional directory inside the repository where the starter resides.
origin: reserved field used by kedro internally to determine where the starter
comes from, users do not need to provide this field.
_Prompt ¶
_Prompt(*args, **kwargs)
Represent a single CLI prompt for kedro new
Source code in kedro/framework/cli/starters.py
969 970 971 972 973 974 975 976 977 978 979 | |
validate ¶
validate(user_input)
Validate a given prompt value against the regex validator
Source code in kedro/framework/cli/starters.py
996 997 998 999 1000 1001 1002 | |
_clean_pycache ¶
_clean_pycache(path)
Recursively clean all pycache folders from path.
Parameters:
-
path(Path) –Existing local directory to clean pycache folders from.
Source code in kedro/framework/cli/utils.py
262 263 264 265 266 267 268 269 270 271 | |
_convert_tool_numbers_to_readable_names ¶
_convert_tool_numbers_to_readable_names(tools_numbers)
Transform the list of tool numbers into a list of readable names, using 'None' for empty lists. Then, convert the result into a string format to prevent issues with Cookiecutter.
Source code in kedro/framework/cli/starters.py
643 644 645 646 647 648 649 650 | |
_convert_tool_short_names_to_numbers ¶
_convert_tool_short_names_to_numbers(selected_tools)
Prepares tools selection from the CLI or config input to the correct format to be put in the project configuration, if it exists. Replaces tool strings with the corresponding prompt number.
Parameters:
-
selected_tools(str) –a string containing the value for the --tools flag or config file, or None in case none were provided, i.e. lint,docs.
Returns:
-
list–String with the numbers corresponding to the desired tools, or
-
list–None in case the --tools flag was not used.
Source code in kedro/framework/cli/starters.py
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 | |
_create_project ¶
_create_project(template_path, cookiecutter_args, telemetry_consent)
Creates a new kedro project using cookiecutter.
Parameters:
-
template_path(str) –The path to the cookiecutter template to create the project. It could either be a local directory or a remote VCS repository supported by cookiecutter. For more details, please see: https://cookiecutter.readthedocs.io/en/stable/usage.html#generate-your-project
-
cookiecutter_args(dict[str, Any]) –Arguments to pass to cookiecutter.
Raises:
-
KedroCliError–If it fails to generate a project.
Source code in kedro/framework/cli/starters.py
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 | |
_fetch_validate_parse_config_from_file ¶
_fetch_validate_parse_config_from_file(config_path, prompts_required, starter_alias)
Obtains configuration for a new kedro project non-interactively from a file. Validates that: 1. All keys specified in prompts_required are retrieved from the configuration. 2. The options 'tools' and 'example_pipeline' are not used in the configuration when any starter option is selected. 3. Variables sourced from the configuration file adhere to the expected format.
Parse tools from short names to list of numbers
Parameters:
-
config_path(str) –The path of the config.yml which should contain the data required by
prompts.yml.
Returns:
-
dict[str, str]–Configuration for starting a new project. This is passed as
extra_contextto cookiecutter and will overwrite the cookiecutter.json defaults.
Raises:
-
KedroCliError–If the file cannot be parsed.
Source code in kedro/framework/cli/starters.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
_fetch_validate_parse_config_from_user_prompts ¶
_fetch_validate_parse_config_from_user_prompts(prompts, cookiecutter_context)
Interactively obtains information from user prompts.
Parameters:
-
prompts(dict[str, Any]) –Prompts from prompts.yml.
-
cookiecutter_context(OrderedDict | None) –Cookiecutter context generated from cookiecutter.json.
Returns:
-
dict[str, str]–Configuration for starting a new project. This is passed as
extra_contextto cookiecutter and will overwrite the cookiecutter.json defaults.
Source code in kedro/framework/cli/starters.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | |
_get_available_tags ¶
_get_available_tags(template_path)
Source code in kedro/framework/cli/starters.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | |
_get_cookiecutter_dir ¶
_get_cookiecutter_dir(template_path, checkout, directory, tmpdir)
Gives a path to the cookiecutter directory. If template_path is a repo then
clones it to tmpdir; if template_path is a file path then directly uses that
path without copying anything.
Source code in kedro/framework/cli/starters.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
_get_entry_points ¶
_get_entry_points(name)
Get all kedro related entry points
Source code in kedro/framework/cli/utils.py
332 333 334 335 336 | |
_get_extra_context ¶
_get_extra_context(prompts_required, config_path, cookiecutter_context, selected_tools, project_name, example_pipeline, starter_alias)
Generates a config dictionary that will be passed to cookiecutter as extra_context, based
on CLI flags, user prompts, configuration file or Default values.
It is crucial to return a dictionary with string values, otherwise, there will be issues with Cookiecutter.
Parameters:
-
prompts_required(dict) –a dictionary of all the prompts that will be shown to the user on project creation.
-
config_path(str) –a string containing the value for the --config flag, or None in case the flag wasn't used.
-
cookiecutter_context(OrderedDict | None) –the context for Cookiecutter templates.
-
selected_tools(str | None) –a string containing the value for the --tools flag, or None in case the flag wasn't used.
-
project_name(str | None) –a string containing the value for the --name flag, or None in case the flag wasn't used.
-
example_pipeline(str | None) –a string containing the value for the --example flag, or None in case the flag wasn't used
-
starter_alias(str | None) –a string containing the value for the --starter flag, or None in case the flag wasn't used
Returns:
-
dict[str, str]–Config dictionary, passed the necessary processing, with default values if needed.
Source code in kedro/framework/cli/starters.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
_get_prompts_required_and_clear_from_CLI_provided ¶
_get_prompts_required_and_clear_from_CLI_provided(cookiecutter_dir, selected_tools, project_name, example_pipeline)
Finds the information a user must supply according to prompts.yml, and clear it from what has already been provided via the CLI(validate it before)
Source code in kedro/framework/cli/starters.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
_get_starters_dict ¶
_get_starters_dict()
This function lists all the starter aliases declared in the core repo and in plugins entry points.
For example, the output for official kedro starters looks like: {"astro-airflow-iris": KedroStarterSpec( name="astro-airflow-iris", template_path="git+https://github.com/kedro-org/kedro-starters.git", directory="astro-airflow-iris", origin="kedro" ), }
Source code in kedro/framework/cli/starters.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | |
_make_cookiecutter_args_and_fetch_template ¶
_make_cookiecutter_args_and_fetch_template(config, checkout, directory, template_path)
Creates a dictionary of arguments to pass to cookiecutter and returns project template path.
Parameters:
-
config(dict[str, str]) –Configuration for starting a new project. This is passed as
extra_contextto cookiecutter and will overwrite the cookiecutter.json defaults. -
checkout(str) –The tag, branch or commit in the starter repository to checkout. Maps directly to cookiecutter's
checkoutargument. -
directory(str) –The directory of a specific starter inside a repository containing multiple starters. Maps directly to cookiecutter's
directoryargument. Relevant only when using a starter. https://cookiecutter.readthedocs.io/en/1.7.2/advanced/directories.html -
template_path(str) –Starter path or kedro template path
Returns:
-
tuple[dict[str, object], str]–Arguments to pass to cookiecutter, project template path
Source code in kedro/framework/cli/starters.py
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 | |
_make_cookiecutter_context_for_prompts ¶
_make_cookiecutter_context_for_prompts(cookiecutter_dir)
Source code in kedro/framework/cli/starters.py
760 761 762 763 764 | |
_parse_tools_input ¶
_parse_tools_input(tools_str)
Parse the tools input string.
Parameters:
-
tools_str(str | None) –Input string from prompts.yml.
Returns:
-
list–List of selected tools as strings.
Source code in kedro/framework/cli/starters.py
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 | |
_parse_yes_no_to_bool ¶
_parse_yes_no_to_bool(value)
Source code in kedro/framework/cli/starters.py
186 187 | |
_print_selection_and_prompt_info ¶
_print_selection_and_prompt_info(selected_tools, example_pipeline, interactive)
Source code in kedro/framework/cli/starters.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
_remove_readonly ¶
_remove_readonly(func, path, excinfo)
Remove readonly files on Windows See: https://docs.python.org/3/library/shutil.html?highlight=shutil#rmtree-example
Source code in kedro/framework/cli/starters.py
1005 1006 1007 1008 1009 1010 1011 1012 | |
_safe_load_entry_point ¶
_safe_load_entry_point(entry_point)
Load entrypoint safely, if fails it will just skip the entrypoint.
Source code in kedro/framework/cli/utils.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
_select_checkout_branch_for_cookiecutter ¶
_select_checkout_branch_for_cookiecutter(checkout)
Source code in kedro/framework/cli/starters.py
767 768 769 770 771 | |
_starter_spec_to_dict ¶
_starter_spec_to_dict(starter_specs)
Convert a dictionary of starters spec to a nicely formatted dictionary
Source code in kedro/framework/cli/starters.py
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | |
_validate_config_file_against_prompts ¶
_validate_config_file_against_prompts(config, prompts)
Checks that the configuration file contains all needed variables.
Parameters:
-
config(dict[str, str]) –The config as a dictionary.
-
prompts(dict[str, Any]) –Prompts from prompts.yml.
Raises:
-
KedroCliError–If the config file is empty or does not contain all the keys required in prompts, or if the output_dir specified does not exist.
Source code in kedro/framework/cli/starters.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 | |
_validate_flag_inputs ¶
_validate_flag_inputs(flag_inputs)
Source code in kedro/framework/cli/starters.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
_validate_input_with_regex_pattern ¶
_validate_input_with_regex_pattern(pattern_name, input)
Source code in kedro/framework/cli/starters.py
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 | |
_validate_selected_tools ¶
_validate_selected_tools(selected_tools)
Source code in kedro/framework/cli/starters.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
_validate_tool_selection ¶
_validate_tool_selection(tools)
Source code in kedro/framework/cli/starters.py
868 869 870 871 872 873 874 875 876 877 | |
command_with_verbosity ¶
command_with_verbosity(group, *args, **kwargs)
Custom command decorator with verbose flag added.
Source code in kedro/framework/cli/utils.py
217 218 219 220 221 222 223 224 225 | |
create_cli ¶
create_cli()
Source code in kedro/framework/cli/starters.py
253 254 255 | |
list_starters ¶
list_starters()
List all official project starters available.
Source code in kedro/framework/cli/starters.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
new ¶
new(config_path, starter_alias, selected_tools, project_name, checkout, directory, example_pipeline, telemetry_consent, **kwargs)
Create a new kedro project.
Source code in kedro/framework/cli/starters.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
starter ¶
starter()
Commands for working with project starters.
Source code in kedro/framework/cli/starters.py
258 259 260 | |
kedro.framework.cli.utils ¶
Utilities for use with click.
ENTRY_POINT_GROUPS
module-attribute
¶
ENTRY_POINT_GROUPS = {'global': 'kedro.global_commands', 'project': 'kedro.project_commands', 'init': 'kedro.init', 'line_magic': 'kedro.line_magic', 'hooks': 'kedro.hooks', 'cli_hooks': 'kedro.cli_hooks', 'starters': 'kedro.starters'}
CommandCollection ¶
CommandCollection(*groups)
Bases: CommandCollection
Modified from the Click one to still run the source groups function.
Source code in kedro/framework/cli/utils.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
KedroCliError ¶
Bases: ClickException
Exceptions generated from the Kedro CLI.
Users should pass an appropriate message at the constructor.
LazyGroup ¶
LazyGroup(*args, lazy_subcommands=None, **kwargs)
Bases: Group
A click Group that supports lazy loading of subcommands.
Source code in kedro/framework/cli/utils.py
513 514 515 516 517 518 519 520 521 522 523 524 | |
_check_module_importable ¶
_check_module_importable(module_name)
Source code in kedro/framework/cli/utils.py
322 323 324 325 326 327 328 329 | |
_clean_pycache ¶
_clean_pycache(path)
Recursively clean all pycache folders from path.
Parameters:
-
path(Path) –Existing local directory to clean pycache folders from.
Source code in kedro/framework/cli/utils.py
262 263 264 265 266 267 268 269 270 271 | |
_click_verbose ¶
_click_verbose(func)
Click option for enabling verbose mode.
Source code in kedro/framework/cli/utils.py
206 207 208 209 210 211 212 213 214 | |
_config_file_callback ¶
_config_file_callback(ctx, param, value)
CLI callback that replaces command line options with values specified in a config file. If command line options are passed, they override config file values.
Source code in kedro/framework/cli/utils.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
_find_run_command_in_plugins ¶
_find_run_command_in_plugins(plugins)
Source code in kedro/framework/cli/utils.py
412 413 414 415 | |
_get_entry_points ¶
_get_entry_points(name)
Get all kedro related entry points
Source code in kedro/framework/cli/utils.py
332 333 334 335 336 | |
_safe_load_entry_point ¶
_safe_load_entry_point(entry_point)
Load entrypoint safely, if fails it will just skip the entrypoint.
Source code in kedro/framework/cli/utils.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
_split_load_versions ¶
_split_load_versions(ctx, param, value)
Split and format the string coming from the --load-versions flag in kedro run, e.g.: "dataset1:time1,dataset2:time2" -> {"dataset1": "time1", "dataset2": "time2"}
Parameters:
-
value(str) –the string with the contents of the --load-versions flag.
Returns:
-
dict[str, str]–A dictionary with the formatted load versions data.
Source code in kedro/framework/cli/utils.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
_split_params ¶
_split_params(ctx, param, value)
Source code in kedro/framework/cli/utils.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
_suggest_cli_command ¶
_suggest_cli_command(original_command_name, existing_command_names)
Source code in kedro/framework/cli/utils.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
_update_verbose_flag ¶
_update_verbose_flag(ctx, param, value)
Source code in kedro/framework/cli/utils.py
202 203 | |
_validate_config_file ¶
_validate_config_file(key)
Validate the keys provided in the config file against the accepted keys.
Source code in kedro/framework/cli/utils.py
437 438 439 440 441 442 443 444 445 446 447 448 | |
call ¶
call(cmd, **kwargs)
Run a subprocess command and raise if it fails.
Parameters:
-
cmd(list[str]) –List of command parts.
-
**kwargs(Any, default:{}) –Optional keyword arguments passed to
subprocess.run.
Raises:
-
Exit–If
subprocess.runreturns non-zero code.
Source code in kedro/framework/cli/utils.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
command_with_verbosity ¶
command_with_verbosity(group, *args, **kwargs)
Custom command decorator with verbose flag added.
Source code in kedro/framework/cli/utils.py
217 218 219 220 221 222 223 224 225 | |
env_option ¶
env_option(func_=None, **kwargs)
Add --env CLI option to a function.
Source code in kedro/framework/cli/utils.py
314 315 316 317 318 319 | |
find_run_command ¶
find_run_command(package_name)
Find the run command to be executed. This is either the default run command defined in the Kedro framework or a run command defined by an installed plugin.
Parameters:
-
package_name(str) –The name of the package being run.
Raises:
-
KedroCliError–If the run command is not found.
Returns:
-
Callable–Run command to be executed.
Source code in kedro/framework/cli/utils.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
forward_command ¶
forward_command(group, name=None, forward_help=False)
A command that receives the rest of the command line as 'args'.
Source code in kedro/framework/cli/utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
load_entry_points ¶
load_entry_points(name)
Load package entry point commands.
Parameters:
-
name(str) –The key value specified in ENTRY_POINT_GROUPS.
Raises:
-
KedroCliError–If loading an entry point failed.
Returns:
-
Sequence[MultiCommand]–List of entry point commands.
Source code in kedro/framework/cli/utils.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
python_call ¶
python_call(module, arguments, **kwargs)
Run a subprocess command that invokes a Python module.
Source code in kedro/framework/cli/utils.py
64 65 66 67 68 | |
split_node_names ¶
split_node_names(ctx, param, to_split)
Split string by comma, ignoring commas enclosed by square parentheses.
This avoids splitting the string of nodes names on commas included in
default node names, which have the pattern
Note
to_splitwill have such commas if and only if it includes a default node name. User-defined node names cannot include commas or square brackets.- This function will no longer be necessary from Kedro 0.19.*, in which default node names will no longer contain commas
Parameters:
-
to_split(str) –the string to split safely
Returns:
-
list[str]–A list containing the result of safe-splitting the string.
Source code in kedro/framework/cli/utils.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
split_string ¶
split_string(ctx, param, value)
Split string by comma.
Source code in kedro/framework/cli/utils.py
274 275 276 | |
validate_conf_source ¶
validate_conf_source(ctx, param, value)
Validate the conf_source, only checking existence for local paths.
Source code in kedro/framework/cli/utils.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |