This is a collection of worked code examples that use Bacalhau. For ease of access, they are rendered in the docs at https://docs.bacalhau.org/examples/
All example ideas are tracked as issues in the Bacalhau Core Repository with a label of example
.
- If you have an idea for an example, please add an issue.
- If you'd like to work on a example, please find an issue that has not been assigned, then assign the issue to yourself.
- David and Luke will prioritize the examples that are most useful to the community.
In summary, the process of developing an example is as follows:
- Create a new branch and create an
index.ipynb
file in an appropriate directory. - Develop the notebook and make sure
make test path/to/your/notebook.ipynb
passes - Merge into master
- The CI will then render the notebook and push it to the docs.bacalhau.org repository
- The tests run on a cron basis to ensure examples continue to work
Please see the basic-template example for a guide on how to create a new example.
The following guidelines aim to maintain the quality of the examples.
- The example should be useful, try to avoid toy datasets
- Don't repeat yourself, if there is an example of something already available, redirect to that. For example, don't show people how to ingest data into IPFS, there's an example for that.
- The text should be in English and be free of grammatical mistakes.
- Use good headings and (probably) use numbered top-level headings to show significantly different sections or steps. Use your judgement.
- Remove all formatting other than standard markdown. Examples include rogue page breaks, extra bold formatting in headings (
**
), quotation marks around monospaced code, etc.
- If you have prerequisites, place these at the top of the file just after the introduction at a third level heading (
###
). - If you install anything, use a tagged version. Examples include Docker containers,
pip
installs. Etc.
- All examples must be ipynb files
- Any file named
README.ipynb
orindex.ipynb
will be rendered as the index page for the directory (see the current examples and the docs website) - Prefer fewer cells, they are easier to edit.
- No spaces in directory names
- Every rendered directory requires an index.ipynb file, so the HTML index.html file is not empty.
- All rendered notebooks must have the required Docusaurus YAML at the top of the file (see the current examples and templates)
- Try to avoid using HTML in markdown, it will likely break. If you need to, use IPython's HTML class and hide the code cell.
- Make sure
make convert
andmake test
succeeds and runs in a reasonable time. - Only commit to the examples repo, the CI will take care of committing to the docs site.
Whenever you push to the main branch on this repository, a github action will automatically render your ipynb's into markdown, test it, and push them to the docs repository.
If you want to render your docs locally, then run make convert
. You can also look at the CI script to see the setup.
To test whether your rendered docs will work on the docs site, run make docs
.
This code is slightly different to the test in the CI, but achieves the same result.
Cells can be ignored (or inputs -- remove_input, or outputs -- remove_output) by adding the following to the cell metadata:
...
"metadata": {
"tags": [
"remove_cell"
]
},
...
The top most cell of every notebook must have a raw cell with a bit of yaml in it:
---
sidebar_label: "Basic Template"
sidebar_position: 1
---
sidebar_label
is the label shown in the Docusaurus sidebarsidebar_position
sets the ordering of the labels in the sidebar. Lower values appear at the top.
See the template for an example.
Depending on what editor you are using, you might need to open the file in raw "text" mode to see it. It looks something like this:
...
{
"cell_type": "raw",
"metadata": {},
"source": [
"---\n",
"sidebar_label: \"Basic Template\"\n",
"sidebar_position: 1\n",
"---"
]
},
...
All ipynb files (except those in the todo directory) are tested by a Github action using pytest
and nbmake
.
Please try to keep cell execution time to a minimum.
You can ignore cells, allow exceptions, and more, by adding tags to that cell.
You can run test all notebooks with make test
. If you want to test an individual notebook, you can run something like make test miscellaneous/Gromacs/index.ipynb
.
If you have any questions or spot anything missing, please reach out to philwinder
or enricorotundo
on the #bacalhau channel in Filecoin Slack.