@@ -124,11 +124,10 @@ async def _handle_local_charms(self, bundle, bundle_dir):
124124 pass
125125 except FileNotFoundError :
126126 continue
127- series = (
128- app_dict .get ('series' ) or
129- default_series or
130- await get_charm_series (charm_dir , self .model )
131- )
127+ series = (app_dict .get ('series' ) or default_series )
128+ if not series :
129+ metadata = utils .get_local_charm_metadata (charm_dir )
130+ series = await get_charm_series (metadata , self .model )
132131 if not self .model .connection ().is_using_old_client and not series :
133132 raise JujuError (
134133 "Couldn't determine series for charm at {}. "
@@ -430,32 +429,17 @@ def is_local_charm(charm_url):
430429 return charm_url .startswith ('.' ) or charm_url .startswith ('local:' ) or os .path .isabs (charm_url )
431430
432431
433- async def get_charm_series (path , model ):
434- """Inspects the charm directory at ``path`` and returns a default
435- series from its metadata.yaml (the first item in the 'series' list).
432+ async def get_charm_series (metadata , model ):
433+ """Inspects the given metadata and returns a default series from its
434+ metadata.yaml (the first item in the 'series' list).
436435
437- Tries to extract the informiation from the given model if no
438- series is determined from the path .
436+ Tries to extract the information from the given model if no
437+ series is determined from the given metadata .
439438 Returns None if no series can be determined.
440439
441440 """
442- path = Path (path )
443- try :
444- if path .suffix == '.charm' :
445- md = "metadata.yaml in %s" % path
446- with zipfile .ZipFile (str (path ), 'r' ) as charm_file :
447- data = yaml .safe_load (charm_file .read ('metadata.yaml' ))
448- else :
449- md = path / "metadata.yaml"
450- if not md .exists ():
451- return None
452- data = yaml .safe_load (md .open ())
453- except yaml .YAMLError as exc :
454- if hasattr (exc , "problem_mark" ):
455- mark = exc .problem_mark
456- log .error ("Error parsing YAML file {}, line {}, column: {}" .format (md , mark .line , mark .column ))
457- raise
458- _series = data .get ('series' )
441+
442+ _series = metadata .get ('series' )
459443 series = _series [0 ] if _series else None
460444
461445 if series is None :
0 commit comments