python-project-template icon indicating copy to clipboard operation
python-project-template copied to clipboard

`pre_executed` directory is not excluded from pre-commit's `sphinx-build`

Open hombit opened this issue 4 months ago • 1 comments

Reproducible example, it uses v2.0.7 because of #542

# Initialize a new project
copier copy gh:lincc-frameworks/python-project-template -r v2.0.7 new_project
## Select simple and and answer other questions 
cd new_project
python3 -mvenv ~/.virtualenvs/new_project && source ~/.virtualenvs/new_project/bin/activate
bash .initialize_new_project.sh

# Create a notebook which creates Hello.text file on run
python -m pip install jupytext
echo 'print("Hello, world!")' > hello_world.py
python -m jupytext --to ipynb --output docs/pre_executed/hello_world.ipynb hello_world.py
# Test that the does NOT exist
test -f Hello.text && exit 1
test -f docs/pre_executed/Hello.text && exit 1

# Commit and see that notebook has been run
git switch -c new-branch
git add docs/pre_executed/hello_world.ipynb
git commit -m "Hello"

# Fail appeared 
test -f docs/pre_executed/Hello.text && exit 1  # FAILS

hombit avatar Oct 08 '25 15:10 hombit

As I understand, the notebook rendering tool will try to run a notebook if it doesn't have any output cells already. So the notebooks we'd typically have that are really pre-executed will have output cells. Those notebooks may also contain the following metadata block:

   "nbsphinx": {
    "execute": "never"
   },

If you execute the notebook outside the pre-commit, delete the canary file, then attempt to run the pre-commit, will the notebook still be run and file created?

delucchi-cmu avatar Oct 08 '25 18:10 delucchi-cmu