fastai / nbdev

Create delightful software with Jupyter Notebooks
https://nbdev.fast.ai/
Apache License 2.0
4.94k stars 489 forks source link

`nbdev_export` exports notebooks in arbitrary order #1190

Open omlnaut opened 2 years ago

omlnaut commented 2 years ago

In my project I can't get the build-pipeline to work again. It fails with the error, that my notebooks and the library are not in sync. I already tried:

To no avail. It seems that whatever version the gitlab runner pulls is different than what I see in the repo.

Here is the pipeline in question:

https://github.com/omlnaut/pymoq/actions/runs/3356523622/jobs/5561653458

Any help is appreciated :)

Update: I figured out how to ssh into the github runner while it's executing the workflow. The issue is not that the repository is checked out incorrectly. Instead, it seems that nbdev_export doesn't handle the case that I have one notebook (04_...) with a default_export and another notebook (06_....) that has specific cells exporting to the same target. On my local machine this works as intended, but when I run nbdev_export via ssh on the runner, only the code from the 04_... notebook gets copied to the target file.

omlnaut commented 2 years ago

I think I figured out the error here.

The notebook that generates the initial mocking/functions.py file (via default_exp) has to be exported before the notebook that adds to mocking/functions.py via individual export mocking.funcions tags. nbdev_export uses globtastic to get a list of notebook paths, then iterates over the list, exporting them in the order they were returned by globtastic. It seems that this order is different on my local machine than on the github runner.

I fixed the issue for now by explicitly adding a nbdev_export --path nbs/06_verify.ipynb call right below the nbdev_export call in test.yaml. This fixes the issue for now.

For a longterm fix I think it might be useful to sort the notebook-paths alphabetically ascending by filename. This would make the export order deterministic (and probably in line with what one would expect when naming the notebooks 00.. 01.... and such.

I'll see how I can submit a PR to nbdev. Never done that before, so it might take a while.