Ejemplo n.º 1
0
def jupyter_lab(
    metadata: ProjectMetadata,
    ip_address,
    all_kernels,
    env,
    idle_timeout,
    args,
    **kwargs,
):  # pylint: disable=unused-argument,too-many-arguments
    """Open Jupyter Lab with project specific variables loaded."""
    _check_module_importable("jupyter_core")

    validate_settings()

    if "-h" not in args and "--help" not in args:
        ipython_message(all_kernels)

    _update_ipython_dir(metadata.project_path)
    arguments = _build_jupyter_command(
        "lab",
        ip_address=ip_address,
        all_kernels=all_kernels,
        args=args,
        idle_timeout=idle_timeout,
        project_name=metadata.project_name,
    )

    python_call_kwargs = _build_jupyter_env(env)
    python_call("jupyter", arguments, **python_call_kwargs)
Ejemplo n.º 2
0
    def create(  # pylint: disable=too-many-arguments
        cls,
        package_name: str = None,
        project_path: Union[Path, str] = None,
        save_on_close: bool = True,
        env: str = None,
        extra_params: Dict[str, Any] = None,
    ) -> "KedroSession":
        """Create a new instance of ``KedroSession`` with the session data.

        Args:
            package_name: Package name for the Kedro project the session is
                created for.
            project_path: Path to the project root directory. Default is
                current working directory Path.cwd().
            save_on_close: Whether or not to save the session when it's closed.
            env: Environment for the KedroContext.
            extra_params: 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:
            A new ``KedroSession`` instance.
        """

        # This is to make sure that for workflows that manually create session
        # without going through one of our known entrypoints, e.g. some plugins
        # like kedro-airflow, the project is still properly configured. This
        # is for backward compatibility and should be removed in 0.18.
        if package_name is not None:
            configure_project(package_name)

        validate_settings()

        session = cls(
            package_name=package_name,
            project_path=project_path,
            session_id=generate_timestamp(),
            save_on_close=save_on_close,
        )

        # have to explicitly type session_data otherwise mypy will complain
        # possibly related to this: https://github.com/python/mypy/issues/1430
        session_data: Dict[str, Any] = {
            "package_name": session._package_name,
            "project_path": session._project_path,
            "session_id": session.session_id,
            **_describe_git(session._project_path),
        }

        ctx = click.get_current_context(silent=True)
        if ctx:
            session_data["cli"] = _jsonify_cli_context(ctx)

        env = env or os.getenv("KEDRO_ENV")
        if env:
            session_data["env"] = env

        if extra_params:
            session_data["extra_params"] = extra_params

        session._store.update(session_data)

        # we need a ConfigLoader registered in order to be able to set up logging
        session._setup_logging()
        return session