|
13 | 13 | from collections import defaultdict |
14 | 14 | from glob import glob |
15 | 15 | from pathlib import Path |
16 | | -from typing import Any, Dict, List, Mapping, Sequence, Tuple, TypeVar |
| 16 | +from typing import Any, Dict, List, Mapping, Sequence |
17 | 17 |
|
| 18 | +import packaging.version |
18 | 19 | import typing_inspect |
19 | 20 |
|
20 | 21 | from . import codegen |
@@ -150,7 +151,7 @@ def get(self, name): |
150 | 151 | # Two way mapping |
151 | 152 | refname = self.schema.referenceName(name) |
152 | 153 | if refname not in self: |
153 | | - result = TypeVar(refname) |
| 154 | + result = typing.TypeVar(refname) |
154 | 155 | self[refname] = result |
155 | 156 | self[result] = refname |
156 | 157 |
|
@@ -926,22 +927,11 @@ def generate_definitions(schemas): |
926 | 927 | return definitions |
927 | 928 |
|
928 | 929 |
|
929 | | -def sortable_schema_version(version_string: str) -> Tuple[int, int, int]: |
930 | | - """Return a sorting key in the form (major, minor, micro) from a version string.""" |
931 | | - # 'latest' is special cased in load_schemas and should come last |
932 | | - if version_string == 'latest': |
933 | | - return (9000, 9000, 9000) |
934 | | - # raise ValueError if string isn't in the format A.B.C |
935 | | - major, minor, micro = version_string.split('.') |
936 | | - # raise ValueError if major, minor, and micro aren't int strings |
937 | | - return (int(major), int(minor), int(micro)) |
938 | | - |
939 | | - |
940 | 930 | def generate_facades(schemas: Dict[str, List[Schema]]) -> Dict[str, Dict[int, codegen.Capture]]: |
941 | 931 | captures = defaultdict(codegen.Capture) |
942 | 932 |
|
943 | 933 | # Build the Facade classes |
944 | | - for juju_version in sorted(schemas.keys(), key=sortable_schema_version): |
| 934 | + for juju_version in sorted(schemas.keys(), key=packaging.version.parse): |
945 | 935 | for schema in schemas[juju_version]: |
946 | 936 | cls, source = buildFacade(schema) |
947 | 937 | cls_name = "{}Facade".format(schema.name) |
|
0 commit comments