treebeardtech / nbmake

📝 Pytest plugin for testing notebooks
https://pypi.org/project/nbmake/
Apache License 2.0
184 stars 18 forks source link

Error when importing 'secure_write' from 'jupyter_core.paths' #22

Closed jvanhoefer closed 2 years ago

jvanhoefer commented 3 years ago

Describe the bug As suggested in https://github.com/yaml2sbml-dev/yaml2sbml/issues/34, I tried to use nbmake to add the notebooks in the repo, to the unit tests. I received the error message:

NBMAKE` INTERNAL ERROR
cannot import name 'secure_write' from 'jupyter_core.paths' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jupyter_core/paths.py)

To Reproduce Run pytest --nbmake in yaml2sbml. (I guess)

Desktop (please complete the following information):

Additional context If you need any further information or anything, that I can help to identify the problem, please let me know :)

jvanhoefer commented 3 years ago

Here comes a full Error Log:

NBMAKE INTERNAL ERROR
cannot import name 'secure_write' from 'jupyter_core.paths' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jupyter_core/paths.py)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/_pytest/runner.py", line 244, in from_call
    result = func()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/_pytest/runner.py", line 217, in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/_pytest/runner.py", line 143, in pytest_runtest_call
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/_pytest/runner.py", line 135, in pytest_runtest_call
    item.runtest()
  File "/Users/jvanhoefer/Library/Python/3.7/lib/python/site-packages/nbmake/pytest_items.py", line 50, in runtest
    res: NotebookResult = run.execute()
  File "/Users/jvanhoefer/Library/Python/3.7/lib/python/site-packages/nbmake/nb_run.py", line 73, in execute
    raise err
  File "/Users/jvanhoefer/Library/Python/3.7/lib/python/site-packages/nbmake/nb_run.py", line 55, in execute
    c.execute(cwd=self.filename.parent)
  File "/Users/jvanhoefer/Library/Python/3.7/lib/python/site-packages/nbclient/util.py", line 37, in wrapped
    result = loop.run_until_complete(coro(self, *args, **kwargs))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 573, in run_until_complete
    return future.result()
  File "/Users/jvanhoefer/Library/Python/3.7/lib/python/site-packages/nbclient/client.py", line 474, in async_execute
    async with self.async_setup_kernel(**kwargs):
  File "/Users/jvanhoefer/Library/Python/3.7/lib/python/site-packages/async_generator/_util.py", line 34, in __aenter__
    return await self._agen.asend(None)
  File "/Users/jvanhoefer/Library/Python/3.7/lib/python/site-packages/nbclient/client.py", line 440, in async_setup_kernel
    self.start_kernel_manager()
  File "/Users/jvanhoefer/Library/Python/3.7/lib/python/site-packages/nbclient/client.py", line 327, in start_kernel_manager
    self.km = self.kernel_manager_class(kernel_name=self.kernel_name, config=self.config)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/traitlets/traitlets.py", line 556, in __get__
    return self.get(obj, cls)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/traitlets/traitlets.py", line 535, in get
    value = self._validate(obj, dynamic_default())
  File "/Users/jvanhoefer/Library/Python/3.7/lib/python/site-packages/nbclient/client.py", line 240, in _kernel_manager_class_default
    from jupyter_client import AsyncKernelManager
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jupyter_client/__init__.py", line 4, in <module>
    from .connect import *
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jupyter_client/connect.py", line 32, in <module>
    from jupyter_core.paths import jupyter_data_dir, jupyter_runtime_dir, secure_write
jvanhoefer commented 3 years ago

This happens consistently over all three notebooks in the repository... :)

jvanhoefer commented 3 years ago

When googling, I found this answer to a related question

https://github.com/jupyter/notebook/issues/5014#issuecomment-581556926

Generally speaking, ensure that jupyter_client >= 5.3.4 and jupyter_core >= 4.6.1 for issues surrounding secure_write().

Updating both repositories solved my problem, so it might be a good idea to have them as requirement in setup.py? :)

jvanhoefer commented 3 years ago

Thank you for providing this anyhow! Looks awesome and I will definitely use this in future projects :)

alex-treebeard commented 3 years ago

@jvanhoefer thanks for the report! My notifications are all messed up so I missed this unfortunately.

I'm glad you managed to solve this and get things running. The dependency tree around nbclient has been a little painful for me and I'd rather not touch it until I get a bit more feedback.

Best to just pin this issue/fix for now.

alex-treebeard commented 2 years ago

closing this one as stale, nbclient has gone through a few updates since, so likely this is solved.