Skip to content

Commit

Permalink
Closes #17587: Add release_track attribute to PluginConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Feb 3, 2025
1 parent 5d10707 commit 94ee64e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/plugins/development/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ NetBox looks for the `config` variable within a plugin's `__init__.py` to load i
| `name` | Raw plugin name; same as the plugin's source directory |
| `verbose_name` | Human-friendly name for the plugin |
| `version` | Current release ([semantic versioning](https://semver.org/) is encouraged) |
| `release_track` | An alternate release track (e.g. `dev` or `beta`) to which a release belongs |
| `description` | Brief description of the plugin's purpose |
| `author` | Name of plugin's author |
| `author_email` | Author's public email address |
Expand Down
5 changes: 4 additions & 1 deletion netbox/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def get_local_plugins(plugins=None):
for plugin_name in settings.PLUGINS:
plugin = importlib.import_module(plugin_name)
plugin_config: PluginConfig = plugin.config
installed_version = plugin_config.version
if plugin_config.release_track:
installed_version = f'{installed_version}-{plugin_config.release_track}'

local_plugins[plugin_config.name] = Plugin(
config_name=plugin_config.name,
Expand All @@ -88,7 +91,7 @@ def get_local_plugins(plugins=None):
description_short=plugin_config.description,
is_local=True,
is_installed=True,
installed_version=plugin_config.version,
installed_version=installed_version,
)

# Update catalog entries for local plugins, or add them to the list if not listed
Expand Down
1 change: 1 addition & 0 deletions netbox/netbox/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PluginConfig(AppConfig):
author_email = ''
description = ''
version = ''
release_track = ''

# Root URL path under /plugins. If not set, the plugin's label will be used.
base_url = None
Expand Down
5 changes: 4 additions & 1 deletion netbox/netbox/plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def get_installed_plugins():
for plugin_name in settings.PLUGINS:
plugin_name = plugin_name.rsplit('.', 1)[-1]
plugin_config = apps.get_app_config(plugin_name)
plugins[plugin_name] = getattr(plugin_config, 'version', None)
if plugin_config.release_track:
plugins[plugin_name] = f'{plugin_config.version}-{plugin_config.release_track}'
else:
plugins[plugin_name] = plugin_config.version or None

return dict(sorted(plugins.items()))

Expand Down
3 changes: 2 additions & 1 deletion netbox/netbox/plugins/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def _get_plugin_data(plugin_app_config):
'author': plugin_app_config.author,
'author_email': plugin_app_config.author_email,
'description': plugin_app_config.description,
'version': plugin_app_config.version
'version': plugin_app_config.version,
'release_track': plugin_app_config.release_track,
}

def get(self, request, format=None):
Expand Down

0 comments on commit 94ee64e

Please sign in to comment.