[Help] Nbdev_build_lib modify many python files even I didn't change anything

Hi all,
I would like to make some pr to fastai2 recently.

But I found even do nbdev_build_lib to the newly cloned fastai2 repo (and hook installed), it sill product lots of modifications.

~/nbdev % git pull
Already up-to-date.
~/nbdev % pip install -e .
~ % git clone https://github.com/richarddwang/fastai2.git
~/fastai2 % pip install -e ".[dev]"
~/fastai2 % nbdev_install_git_hooks
~/fastai2 % nbdev_build_lib
~/fastai2 % git status

Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   fastai2/callback/captum.py
	modified:   fastai2/callback/core.py
	modified:   fastai2/callback/schedule.py
	modified:   fastai2/medical/imaging.py
	modified:   fastai2/text/core.py
	modified:   fastai2/text/data.py
	modified:   fastai2/text/learner.py
	modified:   fastai2/vision/core.py

no changes added to commit (use "git add" and/or "git commit -a")

~/fastai2 % nbdev_clean_nbs
~/fastai2 % git status

Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   fastai2/callback/captum.py
	modified:   fastai2/callback/core.py
	modified:   fastai2/callback/schedule.py
	modified:   fastai2/medical/imaging.py
	modified:   fastai2/text/core.py
	modified:   fastai2/text/data.py
	modified:   fastai2/text/learner.py
	modified:   fastai2/vision/core.py

no changes added to commit (use "git add" and/or "git commit -a")

You might be using a different version of nbdev?

I’m using the latest editable build of nbdev and see a few differences to some comments etc:

diff --git a/fastai2/callback/core.py b/fastai2/callback/core.py
index a763fd6..86a0aef 100644
--- a/fastai2/callback/core.py
+++ b/fastai2/callback/core.py
@@ -63,6 +63,7 @@ class TrainEvalCallback(Callback):
 if not hasattr(defaults, 'callbacks'): defaults.callbacks = [TrainEvalCallback]
 
 # Cell
+#TODO: save_targs and save_preds only handle preds/targets that have one tensor, not tuples of tensors.
 class GatherPredsCallback(Callback):

Think we might need @sgugger to say

  • we should all use the same nbdev version (probably a specific pypi release)
    OR
  • it’s OK to use the latest nbdev (I think I’d pick this option :o)
    • in which case, PRs might contain changes to library files without changing notebooks

Maybe the fastai2 contributing section could call this out?

I use the latest nbdev and install the editable version, I also install git hooks for fastai2 repository following the contribution section. But I still get nbdev change many library files that I didn’t modify the nb counterpart…
Can you build_lib without create extra modifications?

I pretty sure that fastai2 is using the latest nbdev - but was last built with a version of nbdev that had a bug. Now that that bug has been fixed, nbdev_build_lib adds a few more comments to .py files.

I’ve added a comment to https://github.com/fastai/nbdev/issues/189 - hope this helps

1 Like

Thank you Pete, it did help :blush: