Skip to content

Commit

Permalink
Improve Extensions documentation (#362)
Browse files Browse the repository at this point in the history
Co-authored-by: eskild <[email protected]>
  • Loading branch information
pavithraes and iameskild authored Sep 19, 2023
1 parent 9350d19 commit 28c7a9b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
16 changes: 16 additions & 0 deletions docs/docs/community/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
id: plugins
title: Plugins (Extensions)
description: List of Nebari plugins
---

Nebari plugins (sometimes referred to as extensions) allow developers to add new features relatively easily without the need to modify the core Nebari code base. At the moment, there are two types of plugins `stages` and `subcommands`. Stage plugins allow users to deploy new features alongside the existing the Nebari features whereas subcommand plugins allow users to extend or modify the existing Nebari CLI.

You can learn to use and create Nebari extensions in the [extension mechanism documentation](/docs/how-tos/nebari-extension-system).

## Verified community extensions

The following community-developed extensions are recognized and verified by the Nebari development team.

* [nebari-mlflow-aws](https://github.com/MetroStar/nebari-mlflow-aws)
* [nebari-label-studio](https://github.com/MetroStar/nebari-label-studio)
37 changes: 24 additions & 13 deletions docs/docs/how-tos/nebari-extension-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ title: Nebari Extension System
description: An overview of the pluggy extension system for Nebari
---

:::warning
The Extension System was added recently in release 2023.9.1. It's in active development and might be unstable.

We don't recommend using it in productions systems yet, but we'll appreciate your explorations, testing, and feedback. You can share your comments in [this GitHub Issue](https://github.com/nebari-dev/nebari/issues/1894).
:::

## Introduction

This guide is to help developers extend and modify the behavior of
nebari. We leverage the plugin system
Nebari. We leverage the plugin system
[pluggy](https://pluggy.readthedocs.io/en/stable/) to enable easy
extensibility. Currently Nebari supports:
extensibility. Currently, Nebari supports:

- overriding a given stages in a deployment
- adding additional stages before, after and between existing stages
- adding additional stages before, after and between existing stages
- arbitrary subcommands

We maintain an [examples
Expand All @@ -21,7 +27,7 @@ which contains up to date usable examples.

## Installing a plugin

Registering a plugin should be easy for the end user. Pluggins are
Registering a plugin should be easy for the end user. Plugins are
either installed into your existing environment e.g.

```shell
Expand All @@ -30,7 +36,7 @@ pip install my-nebari-plugin

Alternatively if you only want to temporarily add an extension.

:::note
:::note
`--import-plugin` does not work for loading subcommands due to
cli already being constructed before plugin imports take place.
:::
Expand All @@ -40,30 +46,35 @@ nebari --import-plugin path/to/plugin.py <command> ...
nebari --import-plugin import.module.plugin.path <command> ...
```

:::note
Currently, Nebari does **not** support un-installing a plugin.
You will need to destroy and re-deploy Nebari to remove any installed plugins.
:::

## Developing an extension

The most important step to developing a plugin is ensuring that the
setuptools entrypoint is set.

```toml:pyproject.toml
<!-- Note: FormidableLabs/prism-react-renderer, tool used by Docusaurus to generate code blocks & highlight syntax does not support TOML, so we're using YAML highlighting below -->

```yaml title="pyproject.toml"
...

[project.entry-points.nebari]
my-subcommand = "path.to.subcommand.module"

...

```

Adding this one line to your `pyproject.toml` will ensure that upon
installation of the package the nebari plugins are registered.
installation of the package the Nebari plugins are registered.

### Subcommands

Nebari exposes a hook `nebari_subcommand` which exposes the
[typer](https://github.com/tiangolo/typer) cli instance. This allows
the developer to attach and arbitrary number of subcommands.
[typer](https://github.com/tiangolo/typer) CLI instance. This allows
the developer to attach any arbitrary number of subcommands.

```python
from nebari.hookspecs import hookimpl
Expand All @@ -87,14 +98,14 @@ There is a dedicated working example in [nebari-plugin-examples](https://github.
### Stages

Nebari exposes a hook `nebari_stage` which uses the `NebariStage`
class. The `NebriStage` exposes `render`, `deploy`, `destroy` as
arbitrary functions called. See below for a complete example.
class. `NebriStage` exposes `render`, `deploy`, `destroy` as
arbitrary functions calls. See below for a complete example.

Nebari decides the order of stages based on two things the `name: str`
attribute and `priority: int` attribute. The rules are as follows:
- stages are ordered by `priority`
- stages which have the same `name` the one with highest priority
number is chosen.
number is chosen

```python
import contextlib
Expand Down
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ module.exports = {
"community/doc-contributions",
"community/style-guide",
"community/team-structure",
"community/plugins",
{
type: "category",
label: "Maintainers",
Expand Down

0 comments on commit 28c7a9b

Please sign in to comment.