From 0fecf52bae1d6d6726cb567536d99632249d6518 Mon Sep 17 00:00:00 2001 From: Michele Mancioppi Date: Tue, 5 Apr 2022 15:28:41 +0200 Subject: [PATCH] Document ingress_per_unit lib dependencies Document the dependency of ingress_per_unit on the jsonschema package (which was transitively imported by SDI with LIBPATCH 6 and below). Provide more informative error message on the missing jsonschema dependency for charms using the ingress_per_unit library. Some housekeeping on requirements.txt. --- lib/charms/traefik_k8s/v0/ingress_per_unit.py | 15 ++++++++++++--- requirements.txt | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/charms/traefik_k8s/v0/ingress_per_unit.py b/lib/charms/traefik_k8s/v0/ingress_per_unit.py index 087fe23b..75171fec 100644 --- a/lib/charms/traefik_k8s/v0/ingress_per_unit.py +++ b/lib/charms/traefik_k8s/v0/ingress_per_unit.py @@ -17,6 +17,8 @@ charmcraft fetch-lib charms.traefik_k8s.v0.ingress_per_unit ``` +Add the `jsonschema` dependency to the `requirements.txt` of your charm. + ```yaml requires: ingress: @@ -50,7 +52,14 @@ def _handle_ingress_per_unit(self, event): import warnings from typing import Dict, Optional, Tuple, TypeVar, Union -import jsonschema +try: + import jsonschema +except ModuleNotFoundError: + raise Exception( + "The ingress_per_unit library needs the jsonschema package as dependency; " + "add 'jsonschema' to the 'requirements.txt' of your charm." + ) + import yaml from ops.charm import CharmBase, RelationBrokenEvent, RelationEvent from ops.framework import EventSource, Object, ObjectEvents @@ -65,14 +74,14 @@ def _handle_ingress_per_unit(self, event): ) # The unique Charmhub library identifier, never change it -LIBID = "7ef06111da2945ed84f4f5d4eb5b353a" # can't register a library until the charm is in the store 9_9 +LIBID = "7ef06111da2945ed84f4f5d4eb5b353a" # Increment this major API version when introducing breaking changes LIBAPI = 0 # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 7 +LIBPATCH = 8 log = logging.getLogger(__name__) diff --git a/requirements.txt b/requirements.txt index 2203760d..58cf484f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,7 @@ ops == 1.3.0 # 1.4.0 breaks SDI-based tests deepmerge lightkube >= 0.8.1 lightkube-models >= 1.22.0.4 -serialized-data-interface>=0.4.0 \ No newline at end of file +# The following is needed by lib/charms/traefik_k8s/v0/ingress_per_unit.py +jsonschema +# The following is needed by lib/charms/traefik_k8s/v0/ingress.py +serialized-data-interface==0.4.0 # Pin to avoid incompatible changes until dropped \ No newline at end of file