Sphinx-gallery offers the option to create .py
files that can be generated into .ipynb
files and directly execute them for documentation.
I have the following file structure:
Project/
|--doc
| |--Makefile
|
|--examples
| |--data
| |--plot_example_1.py
|
|--tests
| |--test_run_examples.py
In plot_example_1.py
I now want to read the example data stored in data
, and therefore require the path of the current directory.
When first generating the documentation I can resolve it with
from pathlib import Path
Path().resolve()
I want to test the examples however additionally using pytest
. This fails when calling pytest tests
from the root directory.
Instead I could succesfully test it when adapting the path call to Path(__file__).absolute()
, but the __file__
option is not available in the ipynb
as explained here
So I need an option that can resolve the path for both the python file and ipynb. Is there any option for that?