Esempio n. 1
0
def _run_node_synchronization(node: Node,
                              catalog: DataCatalog,
                              is_async: bool = False,
                              run_id: str = None) -> Node:
    """Run a single `Node` with inputs from and outputs to the `catalog`.
    `KedroContext` class is initialized in every subprocess because of Windows
    (latest OSX with Python 3.8) limitation.
    Windows has no "fork", so every subprocess is a brand new process created via "spawn",
    and KedroContext needs to be created in every subprocess in order to make
    KedroContext logging setup and hook manager work.

    Args:
        node: The ``Node`` to run.
        catalog: A ``DataCatalog`` containing the node's inputs and outputs.
        is_async: If True, the node inputs and outputs are loaded and saved
            asynchronously with threads. Defaults to False.
        run_id: The id of the pipeline run.

    Returns:
        The node argument.

    """

    if multiprocessing.get_start_method() == "spawn":  # type: ignore
        # pylint: disable=import-outside-toplevel
        import kedro.framework.context.context as context  # pragma: no cover

        context.load_context(Path.cwd())  # pragma: no cover
    # The hard-coded current working directory causes
    # parallel runner to not work in notebook environment,
    # but we will revisit this when we work on access `project_path`
    # from within the runner and data in KedroContext
    # See https://github.com/quantumblacklabs/private-kedro/issues/701.
    return run_node(node, catalog, is_async, run_id)
Esempio n. 2
0
def get_project_context(
    key: str = "context", project_path: Path = None, **kwargs
) -> Any:
    """Gets the context value from context associated with the key.

    Args:
        key: Optional key to get associated value from Kedro context.
            Supported keys are "verbose" and "context", and it defaults to "context".
        project_path: Optional path to where the project root is to load the context.
            If omitted, the current working directory will be used.
        kwargs: Optional custom arguments defined by users, which will be passed into
            the constructor of the projects KedroContext subclass.

    Returns:
        Requested value from Kedro context dictionary or the default if the key
            was not found.

    Raises:
        KedroCliError: When the key is not found and the default value was not
            specified.
    """
    warnings.warn(
        "`get_project_context` is now deprecated and will be removed in Kedro 0.18.0. "
        "Please use `KedroSession.load_context()` to access the "
        "`KedroContext` object. For more information, please visit "
        "https://kedro.readthedocs.io/en/stable/04_kedro_project_setup/03_session.html",
        DeprecationWarning,
    )
    project_path = project_path or Path.cwd()
    context = load_context(project_path, **kwargs)
    # Dictionary to be compatible with existing Plugins. Future plugins should
    # retrieve necessary Kedro project properties from context
    value = {"context": context, "verbose": KedroCliError.VERBOSE_ERROR}[key]

    return deepcopy(value)