Skip to content

gather_sources_and_dependencies fails in notebooks with ipykernel 6.21.0 #909

@champialex

Description

@champialex

Jupyter released 6.21.0 on the 31st of Jan.
It includes ipython/ipykernel#1078 which adds a file variable. Sadly, that file doesn't actually exist....

Reproduce in a notebook with

pip install ipykernel==6.21.0
from sacred.dependencies import gather_sources_and_dependencies
gather_sources_and_dependencies(globals(), save_git_info=True)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
path/to/my/notebook/directory/3a203c6e-289c-4c4e-abf1-74450c51ac54 in <cell line: 1>()
----> 1 gather_sources_and_dependencies(globals(), save_git_info=True)

/opt/conda/envs/my_env/lib/python3.8/site-packages/sacred/dependencies.py in gather_sources_and_dependencies(globs, save_git_info, base_dir)
    726 def gather_sources_and_dependencies(globs, save_git_info, base_dir=None):
    727     """Scan the given globals for modules and return them as dependencies."""
--> 728     experiment_path, main = get_main_file(globs, save_git_info)
    729 
    730     base_dir = base_dir or experiment_path

/opt/conda/envs/my_env/lib/python3.8/site-packages/sacred/dependencies.py in get_main_file(globs, save_git_info)
    597         main = None
    598     else:
--> 599         main = Source.create(globs.get("__file__"), save_git_info)
    600         experiment_path = os.path.dirname(main.filename)
    601     return experiment_path, main

/opt/conda/envs/my_env/lib/python3.8/site-packages/sacred/dependencies.py in create(filename, save_git_info)
    455     def create(filename, save_git_info=True):
    456         if not filename or not os.path.exists(filename):
--> 457             raise ValueError('invalid filename or file not found "{}"'.format(filename))
    458 
    459         main_file = get_py_file_if_possible(os.path.abspath(filename))

ValueError: invalid filename or file not found "path/to/my/notebook/directory/3a203c6e-289c-4c4e-abf1-74450c51ac54"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions