fw snippet publish
snippet publish
Publish one cell of an executed notebook as a code snippet
Added in 0.7.0.
Publishes one cell of a saved Jupyter notebook as a code_snippet artifact: its code and the text outputs saved with it. Nothing is run. Run the notebook and save it first.
--cell names the cell by a tag, a Quarto "#| label:" line, or the label on its %%fw_snippet line. Quarto option lines and a leading %%fw_snippet line are left out of the code. Outputs keep their order: stdout as output, stderr as a message, the text/plain form of results and displays, and errors with their traceback. An output that carries an image is left out whole.
The snippet records the notebook's path in its git repository and the commit checked out. It names a repository only when --repository or publish.repository in settings.yml gives one.
Publishing goes through fw publish, to the same destinations. The slug defaults to the label. Framework Cloud keeps the version when the snippet has not changed.
Usage
fw snippet publish NOTEBOOK.ipynb --cell LABEL [flags]
Options
| Name | Type | Default | Description |
|---|---|---|---|
| NOTEBOOK.ipynb required | string | ||
| LABEL required | string | ||
| --cell | string |
the cell's tag or label |
|
| --collection | string |
existing project collection ID or slug |
|
| --description | string |
the artifact description |
|
| --display | stringArray | "[]" |
what embeds show, NAME=on|off; repeatable (Cloud: title, description, author, credit, details, variable_tips, column_summaries, output, links, legend, analysis, dagitty, code, notes, ignored, interactive) |
| --folded | bool |
fold the output blocks |
|
| --include-private | bool |
publish from a notebook whose path contains "private" without asking |
|
| --json | bool |
print JSON on stdout, for scripts and agents |
|
| --link | stringArray | "[]" |
notebook=URL or model=SLUG|URL; repeatable |
| --no-output | bool |
publish the code only |
|
| --password | string |
password required to view the artifact |
|
| --repository | string |
the https repository URL to name (default: publish.repository in settings.yml) |
|
| --share-unlisted | bool |
allow collection readers to access this unlisted artifact |
|
| --slug | string |
the artifact's name in the project (default: from the label) |
|
| --title | string |
the artifact's title (default: the label) |
|
| --to | string |
named publishing destination (default: publish.default, then cloud) |
|
| --unfolded | bool |
never fold the output blocks |
|
| --url | string |
Framework Cloud server (default: the project's FW_CLOUD_URL) Environment variable: |
|
| --visibility | string |
artifact visibility (Cloud: public, unlisted, or private) |
|
| -y, --yes | bool |
upload without asking |
Value
Like fw publish: with --json, the document, with unchanged: true when the snippet matched its newest version.
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Failure |
| 2 | Bad flags or arguments |
| 3 | Not logged in, or the server rejected the token |
| 4 | The server has no such project or resource |
| 5 | Browser login was denied, or its code expired |
| 6 | An upload has "private" in a path; rerun with --include-private if you mean to send it |
With --json, a failure also prints one JSON line on stderr: {"error": "...", "exit_code": 4}. Exit code 6 adds "reason": "private_path".
Examples
Not run
fw snippet publish analysis.ipynb --cell fit-ols
fw snippet publish notebooks/models.ipynb --cell fit-ols --folded --yes
fw snippet publish analysis.ipynb --cell fit-ols --link notebook=https://example.org/analysis --link model=ols-model