예제 #1
0
파일: loader.py 프로젝트: ploomber/ploomber
def lazily_load_entry_point(starting_dir=None, reload=False):
    """
    Lazily loads entry point by recursively looking in starting_dir directory
    and parent directories.
    """

    starting_dir = starting_dir or '.'

    entry_point = os.environ.get('ENTRY_POINT')

    type_ = try_to_find_entry_point_type(entry_point)

    if type_ == EntryPoint.Directory:
        spec = DAGSpec.from_directory(entry_point)
        path = Path(entry_point)
    elif type_ == EntryPoint.DottedPath:
        entry = load_callable_dotted_path(str(entry_point), raise_=True)
        dag = entry()
        spec = dict(meta=dict(jupyter_hot_reload=False,
                              jupyter_functions_as_notebooks=False))
        # potential issue: dag defines sources as relative paths
        path = Path().resolve()
        return spec, dag, path
    else:
        spec, path = _default_spec_load(starting_dir=starting_dir,
                                        reload=reload,
                                        lazy_import=True)

    # chain exception to provide more context
    dag = spec.to_dag()

    return spec, dag, path
예제 #2
0
파일: loader.py 프로젝트: cxz/ploomber
def lazily_load_entry_point(starting_dir=None, reload=False):
    """
    Lazily loads entry point by recursively looking in starting_dir directory
    and parent directories.
    """

    starting_dir = starting_dir or '.'

    entry_point = os.environ.get('ENTRY_POINT')

    type_ = try_to_find_entry_point_type(entry_point)

    if type_ == EntryPoint.Directory:
        spec = DAGSpec.from_directory(entry_point)
        path = Path(entry_point)
    elif type_ == EntryPoint.DottedPath:
        entry = load_callable_dotted_path(str(entry_point), raise_=True)
        dag = entry()
        spec = dict(meta=dict(jupyter_hot_reload=False,
                              jupyter_functions_as_notebooks=False))
        # potential issue: dag defines sources as relative paths
        path = Path().resolve()
        return spec, dag, path
    else:
        spec, path, _ = _default_spec_load(starting_dir=starting_dir,
                                           reload=reload,
                                           lazy_import=True)

    # chain exception to provide more context
    dag = spec.to_dag()

    # we remove the on_render hook because this is a lazy load, if we don't do
    # it, calling the hook will cause an error since the function never loads
    dag.on_render = None

    # same with task-level hooks
    # also disable static_analysis since we don't want to break cell injection
    # because of some issues in te code
    for name in dag._iter():
        task = dag[name]
        task._on_render = None

        if hasattr(task, 'static_analysis'):
            task.static_analysis = False

    return spec, dag, path