Skip to content

Commit

Permalink
cleanup🧼
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Sep 26, 2024
1 parent 56724b2 commit 50ad991
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
36 changes: 18 additions & 18 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
async def main() -> None:
m = Model()
await m.connect(model_name="testm")
#from juju.client._client import ApplicationFacade
#f = ApplicationFacade.from_connection(m.connection())
#rv = await f.Get("database")
#print(rv)
#print()
# from juju.client._client import CharmsFacade
# f = CharmsFacade.from_connection(m.connection())
# rv = await f.CharmInfo("local:noble/fake-ingress-0")
# print(rv)
# print()

#rv = await f.ApplicationsInfo(entities=[{"tag": "application-database"}])
#print(rv)
#print()

for app_name, app in m.applications.items():
print([
app.name,
app.charm_name,
app.exposed,
app.charm_url,
app.owner_tag,
app.life,
app.min_units,
app.constraints["arch"],
app.subordinate,
app.status,
app.workload_version,
])
print(f"""{app_name}:
name............... {app.name!r}
charm_name......... {app.charm_name!r}
exposed............ {app.exposed!r}
charm_url.......... {app.charm_url!r}
owner_tag.......... {app.owner_tag!r}
life............... {app.life!r}
min_units.......... {app.min_units!r}
constraints["arch"] {app.constraints["arch"]!r}
subordinate........ {app.subordinate!r}
status............. {app.status!r}
workload_version... {app.workload_version!r}
""")

await m.disconnect()

Expand Down
21 changes: 16 additions & 5 deletions juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
class Application(model.ModelEntity):
@property
def name(self) -> str:
# FIXME is .name stable?
# if it's not, what to get it by?
# if it's stable, let's set it at creation
# FIXME .name is stable, set it on some internal attribute instead
# we need a self.name to call facades
rv = self.safe_data["name"]
return rv

Expand Down Expand Up @@ -75,11 +74,20 @@ def min_units(self) -> int:
@property
def constraints(self) -> dict[str, str|int|bool]:
rv = self.safe_data["constraints"]
# FIXME raw data needs to be normalised and coerced, see juju/constraints.py
# FIXME old code returned a sparse dict
# new code returns a filled-in dict-like
#
# behaviour is the same for user code app.constraints["arch"]
# but is different for app.constraints == expected
if (new := self._application_get().constraints) != rv:
warnings.warn(f"Mismatch in Application.constraints {(new, rv)}")
return rv

@property
def subordinate(self) -> bool:
# FIXME can be got from Charms.CharmInfo(charm_url).meta.subordinate
# Would it be easier to deprecate this?
warnings.warn("Deprecated", DeprecationWarning)
rv = self.safe_data["subordinate"]
return rv

Expand Down Expand Up @@ -700,7 +708,9 @@ def charm_name(self) -> str:
:return str: The name of the charm
"""
rv = URL.parse(self.charm_url).name
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
rv = URL.parse(self.charm_url).name
if (new := self._application_get().charm) != rv:
warnings.warn(f"Mismatch in .charm_name {(new, rv)}")
return rv
Expand All @@ -711,6 +721,7 @@ def charm_url(self) -> str:
:return str: The charm url
"""
warnings.warn("Deprecated (FIXME: most likely)", DeprecationWarning)
rv = self.safe_data["charm-url"]
return rv

Expand Down

0 comments on commit 50ad991

Please sign in to comment.