Skip to content

Commit 74ab0f6

Browse files
authored
Merge pull request #1174 from dimaqq/avoid-lexical-sorting-versions-rebased
#1174 Cherry-picked from #1168 and simplified. Rationale Juju micro versions can get larger than 9, e.g. 2.9.51. When 3.5.10 comes around, we want it to take precedence over 3.5.9 and not get wedged between 3.5.1 and 3.5.2 Keeping the current codegen mode of operation where it starts with the oldest version and whacks some internal state on encountering a latter version. (We'll deal with that in a separate PR)
2 parents c58ec9d + b2f118b commit 74ab0f6

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

juju/client/facade.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
from collections import defaultdict
1414
from glob import glob
1515
from pathlib import Path
16-
from typing import Any, Mapping, Sequence, TypeVar
16+
from typing import Any, Dict, List, Mapping, Sequence
1717

18+
import packaging.version
1819
import typing_inspect
1920

2021
from . import codegen
@@ -150,7 +151,7 @@ def get(self, name):
150151
# Two way mapping
151152
refname = self.schema.referenceName(name)
152153
if refname not in self:
153-
result = TypeVar(refname)
154+
result = typing.TypeVar(refname)
154155
self[refname] = result
155156
self[result] = refname
156157

@@ -926,11 +927,11 @@ def generate_definitions(schemas):
926927
return definitions
927928

928929

929-
def generate_facades(schemas):
930+
def generate_facades(schemas: Dict[str, List[Schema]]) -> Dict[str, Dict[int, codegen.Capture]]:
930931
captures = defaultdict(codegen.Capture)
931932

932933
# Build the Facade classes
933-
for juju_version in sorted(schemas.keys()):
934+
for juju_version in sorted(schemas.keys(), key=packaging.version.parse):
934935
for schema in schemas[juju_version]:
935936
cls, source = buildFacade(schema)
936937
cls_name = "{}Facade".format(schema.name)
@@ -953,18 +954,13 @@ def generate_facades(schemas):
953954

954955
def load_schemas(options):
955956
schemas = {}
956-
957957
for p in sorted(glob(options.schema)):
958-
if 'latest' in p:
959-
juju_version = 'latest'
960-
else:
961-
try:
962-
juju_version = re.search(JUJU_VERSION, p).group()
963-
except AttributeError:
964-
print("Cannot extract a juju version from {}".format(p))
965-
print("Schemas must include a juju version in the filename")
966-
raise SystemExit(1)
967-
958+
try:
959+
juju_version = re.search(JUJU_VERSION, p).group()
960+
except AttributeError:
961+
print("Cannot extract a juju version from {}".format(p))
962+
print("Schemas must include a juju version in the filename")
963+
raise SystemExit(1)
968964
new_schemas = json.loads(Path(p).read_text("utf-8"))
969965
schemas[juju_version] = [Schema(s) for s in new_schemas]
970966
return schemas

0 commit comments

Comments
 (0)