def _secret(): ...
for i in range(3):
print(i)0
1
2
Directives are special comments that are preceded by #| that control:
nbdev augments Quarto by providing additional directives than what are available in Quarto. All Quarto directives can be used in nbdev notebooks.
This cheat sheet lists all nbdev directives in addition to some Quarto directives we believe are important. We recommend consulting the quarto docs to see all of the directives available to you.
To clarify the origin of directives we use the following emojis:
The following directives control cell visibility in rendered documentation:
#|hideHide cell input and output.
The following will result in the contents of the cell and itβs output from being hidden:
Note that using #|hide is equivalent to using the Quarto directive #|include: false:
See the quarto docs for more information about #|include.
#|echo: <true|false>Toggle the visibility of code-cell inputs.
#|output: <true|false|asis>Setting this to false hides the output of a cell. Setting this to asis renders the output as raw markdown.
#|hide_lineHide a specific line of code in an input cell.
#|filter_stream <keyword> ...Filter lines containing specific keywords in cell outputs.
#|code-fold: <show|true>The #|code-fold directive allows you to collapse code cells. When set to true, the element is collapsed by default, when set to show show the element is shown by default.
When you set #|code-fold: true, the input cell is collapsed:
this is
output
that takes
lots of vertical space
When you set #|code-fold: show the input cell is shown but still in a collapsible element:
The following directives control how source code is exported from code cells.
#|default_exp <name>Names the module where cells with the #|export directive will be exported to by default.
#|exportExports the items in the cell into the generated module and documentation.
The above cell will get exported to the module specified by #|default_exp. These exports are automatically included in __all__ for the module. To learn how export without inclusion in __all__, see the #|exporti directive.
Furthermore, the documentation for this function will automatically be rendered like this:
say_hello (to:str)
Say hello to somebody
| Type | Details | |
|---|---|---|
| to | str | name of person to say hello to |
The docs are generated from this export using show_doc. See these docs for a detailed discussion of show_doc.
#|exportiAn internal export. Not included in __all__ or the docs. Useful for a function that is called by other functions in this module but is not part of the public API.
Equivalently, you can prefix your function or method with _ e.g. def _private(): pass.
#|exportsA source export. Like #|export but in addition to showing docs via showdoc.show_doc, it also shows the source code.
The following directives allow you to control how cells are executed during docs rendering and testing.
#|exec_docEnsures that a cell is executed each time before generating docs. When a cell does not have this annotation, it is run according to the default rules described here.
#|eval: <true|false>When set to false, the cell is ignored during testing.
When a cell has no directives, cells are run by nbdev according to the behavior described here.