nbdev_trust fails - assuming notebooks are in "nbs" directory?
Hi,
I'm new to nbdev, and trying to use just the hooks to have notebooks play nice with Git.
I wanted to check out the merge-conflict handling so I generated a conflict and did a pull, but nbdev_trust fails as shown here:
dlang@cn002:~/psychic-fiesta$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
Unpacking objects: 100% (3/3), 4.52 KiB | 231.00 KiB/s, done.
From github.com:dstndstn/psychic-fiesta
f76b915..a6fe989 main -> origin/main
Successfully merged conflicts!
Auto-merging Untitled190.ipynb
Merge made by the 'recursive' strategy.
Untitled190.ipynb | 290 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 244 insertions(+), 46 deletions(-)
Traceback (most recent call last):
File "/cm/shared/apps/conda-environments/jupyterhub3/bin/nbdev_trust", line 8, in <module>
sys.exit(nbdev_trust())
File "/cm/shared/apps/conda-environments/jupyterhub3/lib/python3.8/site-packages/fastcore/script.py", line 119, in _f
return tfunc(**merge(args, args_from_prog(func, xtra)))
File "/cm/shared/apps/conda-environments/jupyterhub3/lib/python3.8/site-packages/nbdev/clean.py", line 43, in nbdev_trust
nb = read_nb(fn)
File "/cm/shared/apps/conda-environments/jupyterhub3/lib/python3.8/site-packages/execnb/nbio.py", line 57, in read_nb
res = dict2nb(_read_json(path, encoding='utf-8'))
File "/cm/shared/apps/conda-environments/jupyterhub3/lib/python3.8/site-packages/execnb/nbio.py", line 16, in _read_json
return loads(Path(self).read_text(encoding=encoding, errors=errors))
File "/cm/shared/apps/conda-environments/jupyterhub3/lib/python3.8/pathlib.py", line 1235, in read_text
with self.open(mode='r', encoding=encoding, errors=errors) as f:
File "/cm/shared/apps/conda-environments/jupyterhub3/lib/python3.8/pathlib.py", line 1221, in open
return io.open(self, mode, buffering, encoding, errors, newline,
File "/cm/shared/apps/conda-environments/jupyterhub3/lib/python3.8/pathlib.py", line 1077, in _opener
return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/home/dlang/psychic-fiesta/nbs'
dlang@cn002:~/psychic-fiesta$
where my repository contains just:
dlang@mn003:~/psychic-fiesta$ ls -1
hello.txt
README.md
Untitled190.ipynb
This seems to be coming from the default config; running nbdev_trust in pdb, I see:
> /cm/shared/apps/conda-environments/jupyterhub3/lib/python3.8/site-packages/nbdev/clean.py(34)nbdev_trust()
-> fname = Path(fname if fname else get_config().nbs_path)
(Pdb) p get_config().nbs_path
Path('/home/dlang/psychic-fiesta/nbs')
I don't even have a ~/.config/nbdev/ directory, so it's not immediately obvious where to change this. (Yeah,
This web page suggests that the nbdev hooks are supposed to be usable for "any git repo, including those that don’t use the broader nbdev system.".... but this config default seems to break that promise, and isn't mentioned in the "Configuring nbdev hooks" section.
https://nbdev.fast.ai/tutorials/git_friendly_jupyter.html
I did eventually figure out that I can create the directory & file
~/.config/nbdev/settings.ini
with contents
[DEFAULT]
nbs_path =
to change this setting. But if the goal is to be broadly useful, I would argue this should already be the default. And if that's not desired in your broader nbdev context, then I feel the git-friendly-Jupyter page ought to be updated to mention this. Thanks.
Worth noting that the current versions of nb_test shows a similar issue. I was able to solve another way by just placing an empty nbs folder in the top directory of my project. Regardless, as it stands right now, at least some of the functions listed in modular_nbdev don't seem to work on a non-nbdev project without additional steps that aren't listed in the documentation.