Fix NetBox string path compatibility
CI / php-store (push) Waiting to run
CI / python-components (push) Waiting to run

This commit is contained in:
2026-08-24 22:36:28 +02:00
parent 2063d9ca3c
commit 3028bf522c
6 changed files with 36 additions and 6 deletions
+1 -1
View File
@@ -232,7 +232,7 @@ Das Plugin unter `netbox_plugin/` ist auf NetBox 4.6.54.6.8 begrenzt. Zuerst
```text ```text
cd netbox_plugin cd netbox_plugin
python -m build python -m build
/opt/netbox/venv/bin/pip install dist/netbox_plugin_store-0.1.0-py3-none-any.whl /opt/netbox/venv/bin/pip install dist/netbox_plugin_store-0.1.1-py3-none-any.whl
``` ```
Das Paket muss außerdem in `/opt/netbox/local_requirements.txt` festgehalten werden. In `configuration.py` wird es zunächst sicher im Dry-run-Modus eingerichtet: Das Paket muss außerdem in `/opt/netbox/local_requirements.txt` festgehalten werden. In `configuration.py` wird es zunächst sicher im Dry-run-Modus eingerichtet:
+1 -1
View File
@@ -22,7 +22,7 @@ The safe default is intentionally non-mutating. Installing the UI alone never gr
Install the wheel into NetBox's virtual environment and persist it in `/opt/netbox/local_requirements.txt`: Install the wheel into NetBox's virtual environment and persist it in `/opt/netbox/local_requirements.txt`:
```text ```text
netbox-plugin-store==0.1.0 netbox-plugin-store==0.1.1
``` ```
Add the plugin to `configuration.py`: Add the plugin to `configuration.py`:
+9 -2
View File
@@ -11,6 +11,12 @@ class RuntimeConfigurationError(RuntimeError):
pass pass
def _netbox_root(django_settings: object) -> Path:
"""Return NETBOX_ROOT while supporting NetBox settings that expose paths as strings."""
base_dir = Path(getattr(django_settings, "BASE_DIR"))
return Path(getattr(django_settings, "NETBOX_ROOT", base_dir.parent))
def _argv_list(value: object, setting: str) -> tuple[tuple[str, ...], ...]: def _argv_list(value: object, setting: str) -> tuple[tuple[str, ...], ...]:
if not isinstance(value, (list, tuple)): if not isinstance(value, (list, tuple)):
raise RuntimeConfigurationError(f"{setting} must be a list of argv lists.") raise RuntimeConfigurationError(f"{setting} must be a list of argv lists.")
@@ -160,11 +166,12 @@ class RuntimeSettings:
defaults.update(plugin_settings) defaults.update(plugin_settings)
release = getattr(django_settings, "RELEASE", None) release = getattr(django_settings, "RELEASE", None)
version = getattr(release, "version", None) or django_settings.VERSION version = getattr(release, "version", None) or django_settings.VERSION
base_dir = Path(django_settings.BASE_DIR)
return cls.from_mapping( return cls.from_mapping(
defaults, defaults,
configuration_dir=django_settings.CONFIGURATION_DIR, configuration_dir=django_settings.CONFIGURATION_DIR,
netbox_root=getattr(django_settings, "NETBOX_ROOT", django_settings.BASE_DIR.parent), netbox_root=_netbox_root(django_settings),
base_dir=django_settings.BASE_DIR, base_dir=base_dir,
netbox_version=version, netbox_version=version,
) )
+1 -1
View File
@@ -1 +1 @@
__version__ = "0.1.0" __version__ = "0.1.1"
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "netbox-plugin-store" name = "netbox-plugin-store"
version = "0.1.0" version = "0.1.1"
description = "A secure NetBox 4.6 plugin lifecycle client for the MrBlake Plugin Store" description = "A secure NetBox 4.6 plugin lifecycle client for the MrBlake Plugin Store"
readme = "README.md" readme = "README.md"
requires-python = ">=3.12" requires-python = ">=3.12"
+23
View File
@@ -0,0 +1,23 @@
import unittest
from pathlib import Path
from types import SimpleNamespace
import _bootstrap # noqa: F401
from netbox_plugin_store.runtime import _netbox_root
class RuntimePathTests(unittest.TestCase):
def test_netbox_root_falls_back_from_string_base_dir(self):
settings = SimpleNamespace(BASE_DIR="/opt/netbox/netbox")
self.assertEqual(_netbox_root(settings), Path("/opt/netbox"))
def test_explicit_netbox_root_accepts_string_paths(self):
settings = SimpleNamespace(BASE_DIR="/srv/netbox/app", NETBOX_ROOT="/opt/netbox")
self.assertEqual(_netbox_root(settings), Path("/opt/netbox"))
if __name__ == "__main__":
unittest.main()