AnswerDotAI / nbdev

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

Unwanted `show_doc` Documentation Automatically Added 3x to Rendered HTML #1446

Open nicomarr opened 2 months ago

nicomarr commented 2 months ago

Description

When using nbdev to write a Python package, I've encountered an issue possibly associated with the nbdev_export command:

Current Behavior

The show_doc documentation is automatically added three times to the end of the rendered HTML and markdown files.

Expected Behavior

The rendered HTML and markdown files should only contain documentation for the code actually present in the source notebook.

Attempted Solutions

Any suggestions to fix this would be greatly appreciated. Thank you!

nicomarr commented 1 month ago

Hi there!

I’ve been able to identify the cause for the issue #1446 described earlier. In brief, in my source code, I have defined a decorator function, named add_to_cass, that allows adding methods to an existing Assistantclass dynamically. For each method where this add_to_classdecorator is being used to extend the Assistantclass, the show_doc documentation is being added to my source code documentation page.

I have created a minimal reproduction of the affected repo, which can be found here. I was able to remove the unwanted show_doc documentation by commenting-out the respective methods; see commit 31ccd5d. Then I reproduced the issue by uncommenting one of the methods, see commit 77ecfcb.

Any suggestions how to avoid the show_doc documentation being automatically rendered while keeping my existing source code? I could certainly refactor my code so that all class methods are defined in one place as a workaround. However, ideally I would like to keep the option to dynamically add class methods using my existing add_to_classdecorator function.

Thank you in advance!