Skip to content

Commit ffcc640

Browse files
committed
Fix circular imports
1 parent db6be93 commit ffcc640

4 files changed

Lines changed: 22 additions & 26 deletions

File tree

juju/application.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
import logging
1818
import os
1919

20-
from . import model, tag
20+
from . import model, tag, utils
2121
from .status import derive_status
2222
from .annotationhelper import _get_annotations, _set_annotations
2323
from .client import client
2424
from .errors import JujuError
2525
from .bundle import get_charm_series
2626
from .placement import parse as parse_placement
27-
from .charm import get_local_charm_metadata
2827

2928
log = logging.getLogger(__name__)
3029

@@ -718,7 +717,7 @@ async def local_refresh(
718717
if default_series:
719718
series = default_series.value
720719
charm_url = await self.model.add_local_charm_dir(charm_dir, series)
721-
metadata = get_local_charm_metadata(path)
720+
metadata = utils.get_local_charm_metadata(path)
722721
if resources is not None:
723722
resources = await self.model.add_local_resources(self.entity_id,
724723
charm_url,

juju/charm.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,10 @@
1313
# limitations under the License.
1414

1515
import logging
16-
import zipfile
17-
import yaml
18-
from pathlib import Path
1916
from . import model
2017

2118
log = logging.getLogger(__name__)
2219

2320

24-
def get_local_charm_metadata(path):
25-
"""Retrieve Metadata of a Charm from its path
26-
27-
:patam str path: Path of charm directory or .charm file
28-
29-
:return: Object of charm metadata
30-
"""
31-
if str(path).endswith('.charm'):
32-
with zipfile.ZipFile(path, 'r') as charm_file:
33-
metadata = yaml.load(charm_file.read('metadata.yaml'), Loader=yaml.FullLoader)
34-
else:
35-
entity_path = Path(path)
36-
metadata_path = entity_path / 'metadata.yaml'
37-
metadata = yaml.load(metadata_path.read_text(), Loader=yaml.FullLoader)
38-
39-
return metadata
40-
41-
4221
class Charm(model.ModelEntity):
4322
pass

juju/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from . import provisioner, tag, utils
2222
from .annotationhelper import _get_annotations, _set_annotations
2323
from .bundle import BundleHandler, get_charm_series
24-
from .charm import get_local_charm_metadata
2524
from .charmhub import CharmHub
2625
from .charmstore import CharmStore
2726
from .client import client, connector
@@ -1470,7 +1469,7 @@ async def deploy(
14701469
entity_id,
14711470
entity=entity)
14721471
else:
1473-
metadata = get_local_charm_metadata(entity_path)
1472+
metadata = utils.get_local_charm_metadata(entity_path)
14741473
if not application_name:
14751474
application_name = metadata['name']
14761475
# We have a local charm dir that needs to be uploaded

juju/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pyasn1.type import univ, char
99
from pyasn1.codec.der.encoder import encode
1010
import yaml
11+
import zipfile
1112

1213

1314
async def execute_process(*cmd, log=None, loop=None):
@@ -185,3 +186,21 @@ def generate_user_controller_access_token(username, controller_endpoints, secret
185186
remainder = len(registration_string) % 3
186187
registration_string += b"\0" * (3 - remainder)
187188
return base64.urlsafe_b64encode(registration_string)
189+
190+
191+
def get_local_charm_metadata(path):
192+
"""Retrieve Metadata of a Charm from its path
193+
194+
:patam str path: Path of charm directory or .charm file
195+
196+
:return: Object of charm metadata
197+
"""
198+
if str(path).endswith('.charm'):
199+
with zipfile.ZipFile(path, 'r') as charm_file:
200+
metadata = yaml.load(charm_file.read('metadata.yaml'), Loader=yaml.FullLoader)
201+
else:
202+
entity_path = Path(path)
203+
metadata_path = entity_path / 'metadata.yaml'
204+
metadata = yaml.load(metadata_path.read_text(), Loader=yaml.FullLoader)
205+
206+
return metadata

0 commit comments

Comments
 (0)