Skip to content

Commit

Permalink
chore: simpler code
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Oct 22, 2024
1 parent 364082b commit 84ccfe8
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions juju/client/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
from collections import defaultdict
from glob import glob
from pathlib import Path
from typing import Any, Dict, List, Mapping, Sequence, Tuple, TypeVar
from typing import Any, Dict, List, Mapping, Sequence

import packaging.version
import typing_inspect

from . import codegen
Expand Down Expand Up @@ -150,7 +151,7 @@ def get(self, name):
# Two way mapping
refname = self.schema.referenceName(name)
if refname not in self:
result = TypeVar(refname)
result = typing.TypeVar(refname)
self[refname] = result
self[result] = refname

Expand Down Expand Up @@ -926,22 +927,11 @@ def generate_definitions(schemas):
return definitions


def sortable_schema_version(version_string: str) -> Tuple[int, int, int]:
"""Return a sorting key in the form (major, minor, micro) from a version string."""
# 'latest' is special cased in load_schemas and should come last
if version_string == 'latest':
return (9000, 9000, 9000)
# raise ValueError if string isn't in the format A.B.C
major, minor, micro = version_string.split('.')
# raise ValueError if major, minor, and micro aren't int strings
return (int(major), int(minor), int(micro))


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

# Build the Facade classes
for juju_version in sorted(schemas.keys(), key=sortable_schema_version):
for juju_version in sorted(schemas.keys(), key=packaging.version.parse):
for schema in schemas[juju_version]:
cls, source = buildFacade(schema)
cls_name = "{}Facade".format(schema.name)
Expand Down

0 comments on commit 84ccfe8

Please sign in to comment.