def say_hello(to):
"Say hello to somebody"
return f'Hello {to}!'Nbdev
Installation
- Python
- A Python package manager: we recommend conda or pip - download anaconda
- Jupyter Notebook - see below
- nbdev - see below
- Quarto - see quarto setup
To get Jupyter labs
pip install jupyterlabmamba install -c conda-forge jupyterlabTo launch jupyter labs
jupyter labTo install nbdev
pip install nbdevmamba install -c fastai nbdevget instructin for quarto with
nbdev_install_quartoInstall the extension by entering:
pip install jupyterlab-quartoCreate an empty GitHub repo
make it public
add a gitignore file
clone it into project location
git clone https://github.com/PROEJECT_NAME.gitRUN Nbdev
Initialise your nbdev repo by entering:
nbdev_newIt may ask you to enter information that it couldn’t infer from git or GitHub.
- Do a git push to make sure everything is working
git add .
git commit -m'Initial commit'
git pushGo to settings on Github, go to pages, Change Branch to gh-pages
- Then check on Actions
Useful commands
The next step is to install your package by entering this into your terminal:
pip install -e '.[dev]'This is the recommended way to make a Python package importable from anywhere in your current environment:
- -e – short for “editable”, lets you immediately use changes made to your package without having to reinstall, which is convenient for development.
- . – refers to the current directory.
- [dev] – includes “development” requirements: other packages that your notebooks use solely for documentation or testing.
Start the preview by entering this into your terminal:
nbdev_previewBefore every git push, run :
nbdev_prepareWhich is the combination of:
nbdev_exportBuilds the .py modules from Jupyter notebooks
nbdev_testTests your notebooks
nbdev_cleanCleans your notebooks to get rid of extreanous output for git
nbdev_readmeUpdates your repo’s README.md file from your index notebook.
Directives for documentation:
#|hideHide cell input and output.
#|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.
#|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.
Exports
#|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.
#|exportsA source export. Like #|export but in addition to showing docs via showdoc.show_doc, it also shows the source code.
#|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.
Testing
say_hello("Isaac")'Hello Isaac!'
This is a test too! When you run nbdev_test it will execute this cell (and all other test cells) and fail if they raise any exceptions.
For tests, it’s preferred to use more explicit asserts:
assert say_hello("Hamel") == "Hello Hamel!"from fastcore.test import *test_eq(say_hello("Hamel"), "Hello Hamel!")Using
$$\sum_{i=1}^{k+1}i$$Which is rendered as: \[\sum_{i=1}^{k+1}i\]
This version is displayed inline: $\sum_{i=1}^{k+1}i$ . You can include text before and after.Becomes: This version is displayed inline: \(\sum_{i=1}^{k+1}i\) . You can include text before and after.