44import hashlib
55import json
66import logging
7- from typing import Dict , List , Union
7+ from typing import Dict , List , Optional , Union
88from pathlib import Path
99
1010from typing_extensions import deprecated
1111
1212from . import jasyncio , model , tag , utils
1313from .annotationhelper import _get_annotations , _set_annotations
1414from .bundle import get_charm_series , is_local_charm
15- from .client import client
15+ from .client import client , _definitions
1616from .errors import JujuApplicationConfigError , JujuError
1717from .origin import Channel
1818from .placement import parse as parse_placement
@@ -706,20 +706,28 @@ async def set_constraints(self, constraints):
706706 return await app_facade .SetConstraints (application = self .name , constraints = constraints )
707707
708708 async def refresh (
709- self , channel = None , force = False , force_series = False , force_units = False ,
710- path = None , resources = None , revision = None , switch = None ):
709+ self ,
710+ channel : Optional [str ] = None ,
711+ force : bool = False ,
712+ force_series : bool = False ,
713+ force_units : bool = False ,
714+ path : Optional [Union [Path , str ]] = None ,
715+ resources : Optional [Dict [str , str ]] = None ,
716+ revision : Optional [int ] = None ,
717+ switch : Optional [str ] = None ,
718+ ):
711719 """Refresh the charm for this application.
712720
713- :param str channel: Channel to use when getting the charm from the
721+ :param str|None channel: Channel to use when getting the charm from the
714722 charm store, e.g. 'development'
715723 :param bool force_series: Refresh even if series of deployed
716724 application is not supported by the new charm
717725 :param bool force_units: Refresh all units immediately, even if in
718726 error state
719- :param str path: Refresh to a charm located at path
720- :param dict resources: Dictionary of resource name/filepath pairs
721- :param int revision: Explicit refresh revision
722- :param str switch: Crossgrade charm url
727+ :param Path| str|None path: Refresh to a charm located at path
728+ :param dict[str,str]|None resources: Dictionary of resource name/filepath pairs
729+ :param int|None revision: Explicit refresh revision
730+ :param str|None switch: URL of a different charm to cross-grade to
723731
724732 """
725733 if switch is not None and path is not None :
@@ -743,8 +751,17 @@ async def refresh(
743751
744752 current_origin = charm_url_origin_result .charm_origin
745753 if path is not None or (switch is not None and is_local_charm (switch )):
746- await self .local_refresh (current_origin , force , force_series ,
747- force_units , path or switch , resources )
754+ local_path = path or switch
755+ assert local_path
756+
757+ await self .local_refresh (
758+ charm_origin = current_origin ,
759+ force = force ,
760+ force_series = force_series ,
761+ force_units = force_units ,
762+ path = local_path ,
763+ resources = resources ,
764+ )
748765 return
749766
750767 origin = _refresh_origin (current_origin , channel , revision )
@@ -870,9 +887,15 @@ async def refresh(
870887 upgrade_charm = refresh
871888
872889 async def local_refresh (
873- self , charm_origin = None , force = False , force_series = False ,
874- force_units = False ,
875- path = None , resources = None ):
890+ self ,
891+ * ,
892+ charm_origin : _definitions .CharmOrigin ,
893+ force : bool ,
894+ force_series : bool ,
895+ force_units : bool ,
896+ path : Union [Path , str ],
897+ resources : Optional [Dict [str , str ]],
898+ ):
876899 """Refresh the charm for this application with a local charm.
877900
878901 :param dict charm_origin: The charm origin of the destination charm
@@ -882,16 +905,16 @@ async def local_refresh(
882905 application is not supported by the new charm
883906 :param bool force_units: Refresh all units immediately, even if in
884907 error state
885- :param str path: Refresh to a charm located at path
908+ :param Path| str path: Refresh to a charm located at path
886909 :param dict resources: Dictionary of resource name/filepath pairs
887910
888911 """
889912 app_facade = self ._facade ()
890913
891914 if isinstance (path , str ) and path .startswith ("local:" ):
892915 path = path [6 :]
893- path = Path (path )
894- charm_dir = path .expanduser ().resolve ()
916+ local_path = Path (path )
917+ charm_dir = local_path .expanduser ().resolve ()
895918 model_config = await self .get_config ()
896919
897920 series = (
@@ -907,7 +930,7 @@ async def local_refresh(
907930 if default_series :
908931 series = default_series .value
909932 charm_url = await self .model .add_local_charm_dir (charm_dir , series )
910- metadata = utils .get_local_charm_metadata (path )
933+ metadata = utils .get_local_charm_metadata (local_path )
911934 if resources is not None :
912935 resources = await self .model .add_local_resources (self .entity_id ,
913936 charm_url ,
@@ -956,14 +979,17 @@ async def get_metrics(self):
956979 return await self .model .get_metrics (self .tag )
957980
958981
959- def _refresh_origin (current_origin : client .CharmOrigin , channel = None , revision = None ) -> client .CharmOrigin :
960- if channel is not None :
961- channel = Channel .parse (channel ).normalize ()
982+ def _refresh_origin (
983+ current_origin : client .CharmOrigin ,
984+ channel : Optional [str ] = None ,
985+ revision : Optional [int ] = None ,
986+ ) -> client .CharmOrigin :
987+ chan = None if channel is None else Channel .parse (channel ).normalize ()
962988
963989 return client .CharmOrigin (
964990 source = current_origin .source ,
965- track = channel .track if channel else current_origin .track ,
966- risk = channel .risk if channel else current_origin .risk ,
991+ track = chan .track if chan else current_origin .track ,
992+ risk = chan .risk if chan else current_origin .risk ,
967993 revision = revision if revision is not None else current_origin .revision ,
968994 base = current_origin .base ,
969995 architecture = current_origin .get ('architecture' , DEFAULT_ARCHITECTURE ),
0 commit comments