I’m running into an issue that’s related to
file dunder attribute works in .py, not in notebook, but different. I think it shows some differences between
nbdev_readme that I don’t understand.
I have created a minimal reproducible example here. The details (also written in the README there):
Copy some data from the library itself (the
assets folder) into the user’s current working directory.
from shutil import copytree from pathlib import Path
__file__ when run in a script gives the script’s path. In a notebook, we can use the current working directory (cwd).
#| hide __file__ = (Path().cwd() / "00_core.ipynb").as_posix()
Cell 3: Copy the folder
src = Path(__file__).parents / "assets" dest = Path().cwd() / "output" copytree(src, dest, dirs_exist_ok=True)
- the script
nbdev_readmefails with an error referencing
NameError: name '__file__' is not defined
- If I set
__file__to cwd without the
nbdev_readmefails because it cannot find the
assetsfolder. This happens because
cwdgives the root of my repo (where I ran
nbdev_readme) rather than the
It looks like
nbdev_readme runs notebooks besides
index.ipynb, in this case
00_core.ipynb, in iPython.
- How is this iPython run different from
- What’s the best way to execute stuff in
nbdev_readmethat we need in iPython context but don’t want to run in the script, such as setting