Skip to content

Commit 6464bff

Browse files
Merge pull request #685 from juanmanuel-tirado/JUJU-1353_assumes_directive_breaks
[JUJU-1353] Parse assume directives.
2 parents d6bafce + c29bea2 commit 6464bff

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

examples/charms/onos.charm

52 Bytes
Binary file not shown.

examples/charms/ubuntu/metadata.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ tags:
2020
# https://jujucharms.com/docs/stable/authors-charm-metadata
2121
- misc
2222
- application_development
23-
subordinate: false
23+
subordinate: false
24+
# check: https://juju.is/docs/sdk/assumes for more details
25+
assumes:
26+
- any_of:
27+
- juju >= 2.9
28+
- k8s-api

juju/client/facade.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import re
88
import textwrap
99
import typing
10-
import typing_inspect
1110
from collections import defaultdict
1211
from glob import glob
1312
from pathlib import Path
1413
from typing import Any, Mapping, Sequence, TypeVar
1514

15+
import typing_inspect
16+
1617
from . import codegen
1718

1819
_marker = object()
@@ -664,14 +665,30 @@ def from_json(cls, data):
664665
data = json.loads(data)
665666
except json.JSONDecodeError:
666667
raise
667-
d = {}
668-
for k, v in (data or {}).items():
669-
d[cls._toPy.get(k, k)] = v
670-
671-
try:
668+
if isinstance(data, dict):
669+
d = {}
670+
for k, v in (data or {}).items():
671+
d[cls._toPy.get(k, k)] = v
672+
try:
673+
return cls(**d)
674+
except TypeError:
675+
raise
676+
if isinstance(data, list):
677+
# check: https://juju.is/docs/sdk/assumes
678+
# assumes are in the form of a list
679+
d = {}
680+
for entry in data:
681+
if '>' or '>=' in entry:
682+
# something like juju >= 2.9.31
683+
i = entry.index('>')
684+
key = entry[:i].strip()
685+
value = entry[i:].strip()
686+
d[key] = value
687+
else:
688+
# something like k8s-api
689+
d[entry] = ''
672690
return cls(**d)
673-
except TypeError:
674-
raise
691+
return None
675692

676693
def serialize(self):
677694
d = {}

0 commit comments

Comments
 (0)