nbdev icon indicating copy to clipboard operation
nbdev copied to clipboard

[Feature Requests] What about making `nbdev_separate` to automatically separate imports and codes?

Open 2catycm opened this issue 1 year ago • 1 comments

https://nbdev.fast.ai/getting_started.html#q-what-is-the-warning-found-a-cell-containing-mix-of-imports-and-computations.-please-use-separate-cells

This is a strong limitations to the usability of nbdev.

Every time I try to export docs, I spend hours cleaning up my code to sepearte imports and codes, reading tedious and annoying error messages from nbdev_docs.

We definitely have the ability to do this automatically. (since nbdev can produce warning messages about the situation)

Why not provide a simple tool like nbdev_separate, to automatically detect import lines in a cell and reformat them to a new cell above the original cell.

2catycm avatar Nov 18 '24 11:11 2catycm

I've written a nbscholar lib to extend nbdev, and I made a nbscholar_separate command to help with this issue. If anyone has a similar need to my issue, feel free to try my solution.

nbscholar means "new-big scholar", and it is included as a part of my library here https://github.com/THU-CVML/ScholarlyInfrastructure.git .

just pip install scholarly_infrastructure, and then you can use the command nbscholar_separate. It is recommended to use nbscholar_separate before nbdev_docs.

2catycm avatar Mar 10 '25 14:03 2catycm