Skip to content

Commit 7ae3858

Browse files
committed
chore: fix up arg that's not optional
1 parent 04e6446 commit 7ae3858

5 files changed

Lines changed: 63 additions & 51 deletions

File tree

juju/utils.py

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ async def execute_process(*cmd, log=None):
3737

3838

3939
def juju_config_dir():
40-
"""Resolves and returns the path string to the juju configuration
41-
folder for the juju CLI tool. Of the following items, returns the
42-
first option that works (top to bottom):
40+
"""Resolves and returns the path string to the juju configuration folder
41+
for the juju CLI tool. Of the following items, returns the first option
42+
that works (top to bottom):
4343
4444
* $JUJU_DATA
4545
* $XDG_DATA_HOME/juju
4646
* ~/.local/share/juju
47-
4847
"""
4948
# Set it to ~/.local/share/juju as default
5049
config_dir = Path("~/.local/share/juju")
@@ -60,9 +59,8 @@ def juju_config_dir():
6059

6160

6261
def juju_ssh_key_paths():
63-
"""Resolves and returns the path strings for public and private ssh
64-
keys for juju CLI.
65-
62+
"""Resolves and returns the path strings for public and private ssh keys
63+
for juju CLI.
6664
"""
6765
config_dir = juju_config_dir()
6866
public_key_path = os.path.join(config_dir, "ssh", "juju_id_rsa.pub")
@@ -74,7 +72,6 @@ def juju_ssh_key_paths():
7472
def _read_ssh_key():
7573
"""Inner function for read_ssh_key, suitable for passing to our
7674
Executor.
77-
7875
"""
7976
public_key_path_str, _ = juju_ssh_key_paths()
8077
ssh_key_path = Path(public_key_path_str)
@@ -84,16 +81,17 @@ def _read_ssh_key():
8481

8582

8683
async def read_ssh_key():
87-
"""Attempt to read the local juju admin's public ssh key, so that it
88-
can be passed on to a model.
89-
84+
"""Attempt to read the local juju admin's public ssh key, so that it can be
85+
passed on to a model.
9086
"""
9187
loop = jasyncio.get_running_loop()
9288
return await loop.run_in_executor(None, _read_ssh_key)
9389

9490

9591
class IdQueue:
96-
"""Wrapper around asyncio.Queue that maintains a separate queue for each ID."""
92+
"""Wrapper around asyncio.Queue that maintains a separate queue for each
93+
ID.
94+
"""
9795

9896
def __init__(self, maxsize=0):
9997
self._queues = defaultdict(partial(jasyncio.Queue, maxsize))
@@ -115,9 +113,9 @@ async def put_all(self, value):
115113

116114
async def block_until(*conditions, timeout=None, wait_period=0.5):
117115
"""Return only after all conditions are true.
116+
118117
If a timeout occurs, it cancels the task and raises
119118
asyncio.TimeoutError.
120-
121119
"""
122120

123121
async def _block():
@@ -131,6 +129,7 @@ async def block_until_with_coroutine(
131129
condition_coroutine, timeout=None, wait_period=0.5
132130
):
133131
"""Return only after the given coroutine returns True.
132+
134133
If a timeout occurs, it cancels the task and raises
135134
asyncio.TimeoutError.
136135
"""
@@ -201,15 +200,13 @@ class Addrs(univ.SequenceOf):
201200
class RegistrationInfo(univ.Sequence):
202201
"""ASN.1 representation of:
203202
204-
type RegistrationInfo struct {
205-
User string
203+
type RegistrationInfo struct { User string
206204
207-
Addrs []string
205+
Addrs []string
208206
209-
SecretKey []byte
207+
SecretKey []byte
210208
211-
ControllerName string
212-
}
209+
ControllerName string }
213210
"""
214211

215212
pass
@@ -219,7 +216,7 @@ def generate_user_controller_access_token(
219216
username, controller_endpoints, secret_key, controller_name
220217
):
221218
""" " Implement in python what is currently done in GO
222-
https://github.com/juju/juju/blob/a5ab92ec9b7f5da3678d9ac603fe52d45af24412/cmd/juju/user/utils.go#L16
219+
https://github.com/juju/juju/blob/a5ab92e/cmd/juju/user/utils.go#L16
223220
224221
:param username: name of the user to register
225222
:param controller_endpoints: juju controller endpoints list in the format <ip>:<port>
@@ -246,11 +243,13 @@ def generate_user_controller_access_token(
246243

247244

248245
def get_local_charm_data(path, yaml_file):
249-
"""Retrieve Metadata of a Charm from its path
246+
"""Retrieve Metadata of a Charm from its path.
250247
251-
:patam str path: Path of charm directory or .charm file
252-
:patam str yaml_file: name of the yaml file, can be either
253-
"metadata.yaml", or "manifest.yaml", or "charmcraft.yaml"
248+
:patam str path: Path of charm directory or .charm file :patam str
249+
yaml_
250+
file:
251+
name of the yaml file, can be either "metadata.yaml", or
252+
"manifest.yaml", or "charmcraft.yaml"
254253
255254
:return: Object of charm metadata
256255
"""
@@ -340,8 +339,8 @@ def get_local_charm_charmcraft_yaml(path):
340339

341340

342341
def get_series_version(series_name):
343-
"""get_series_version outputs the version of the OS based on the given series
344-
e.g. jammy -> 22.04, kubernetes -> kubernetes
342+
"""get_series_version outputs the version of the OS based on the given
343+
series e.g. jammy -> 22.04, kubernetes -> kubernetes.
345344
346345
:param str series_name: name of the series
347346
:return str: os version
@@ -352,8 +351,8 @@ def get_series_version(series_name):
352351

353352

354353
def get_version_series(version):
355-
"""get_version_series is the opposite of the get_series_version. It outputs the series based
356-
on given OS version
354+
"""get_version_series is the opposite of the get_series_version. It outputs
355+
the series based on given OS version.
357356
358357
:param str version: version of the OS
359358
return str: name of the series corresponding to the given version
@@ -364,10 +363,11 @@ def get_version_series(version):
364363

365364

366365
def get_local_charm_base(series, charm_path, base_class):
367-
"""Deduce the base [channel/osname] of a local charm based on what we
368-
know already
366+
"""Deduce the base [channel/osname] of a local charm based on what we know
367+
already.
369368
370-
:param str series: This may come from the argument or the metadata.yaml
369+
:param str series: This may come from the argument or the
370+
metadata.yaml
371371
:param str charm_path: Path of charm directory/.charm file
372372
:param class base_class:
373373
:return: Instance of the baseCls with channel/osname information
@@ -413,7 +413,7 @@ def get_local_charm_base(series, charm_path, base_class):
413413

414414

415415
def base_channel_to_series(channel):
416-
"""Returns the series string using the track inside the base channel
416+
"""Returns the series string using the track inside the base channel.
417417
418418
:param str channel: is track/risk (e.g. 20.04/stable)
419419
:return: str series (e.g. focal)
@@ -422,8 +422,8 @@ def base_channel_to_series(channel):
422422

423423

424424
def parse_base_arg(base):
425-
"""Parses a given base into a Client.Base object
426-
:param base str : The base to deploy a charm (e.g. ubuntu@22.04)
425+
"""Parses a given base into a Client.Base object :param base str : The base
426+
to deploy a charm (e.g. ubuntu@22.04)
427427
"""
428428
client.CharmBase()
429429
if not (isinstance(base, str) and "@" in base):
@@ -464,10 +464,12 @@ def get_base_from_origin_or_channel(origin_or_channel, series=None):
464464

465465

466466
def series_for_charm(requested_series, supported_series):
467-
"""series_for_charm takes a requested series and a list of series supported by a
468-
charm and returns the series which is relevant.
469-
If the requested series is empty, then the first supported series is used,
470-
otherwise the requested series is validated against the supported series.
467+
"""series_for_charm takes a requested series and a list of series supported
468+
by a charm and returns the series which is relevant.
469+
470+
If the requested series is empty, then the first supported series is
471+
used, otherwise the requested series is validated against the
472+
supported series.
471473
"""
472474
if len(supported_series) == 1 and supported_series[0] == "":
473475
raise JujuError("invalid supported series reported by charm : ['']")
@@ -492,7 +494,8 @@ def user_requested(series_arg, supported_series, force):
492494
series = series_for_charm(series_arg, supported_series)
493495
if force:
494496
series = series_arg
495-
# Todo (cderici): validate the series with workload_series to see if juju is supporting that
497+
# Todo (cderici): validate the series with workload_series to see if juju is
498+
# supporting that
496499
return series
497500

498501

@@ -542,15 +545,19 @@ def series_selector(
542545
return DEFAULT_SUPPORTED_LTS
543546

544547

545-
def should_upgrade_resource(available_resource, existing_resources, arg_resources={}):
546-
"""Called in the context of upgrade_charm. Given a resource R, takes a look at the resources we
547-
already have and decides if we need to refresh R.
548+
def should_upgrade_resource(available_resource, existing_resources, arg_resources):
549+
"""Determine if the given resource should be upgraded.
550+
551+
Called in the context of upgrade_charm. Given a resource R, takes a look
552+
at the resources we already have and decides if we need to refresh R.
548553
549-
:param dict[str] available_resource: The dict representing the client.Resource coming from the
550-
charmhub api. We're considering if we need to refresh this during upgrade_charm.
551-
:param dict[str] existing_resources: The dict coming from resources_facade.ListResources
552-
representing the resources of the currently deployed charm.
553-
:param dict[str] arg_resources: user provided resources to be refreshed
554+
:param dict[str] available_resource: The dict representing the
555+
client.Resource coming from the charmhub api. We're considering if
556+
we need to refresh this during upgrade_charm. :param dict[str]
557+
existing_resources: The dict coming from
558+
resources_facade.ListResources representing the resources of the
559+
currently deployed charm. :param dict[str] arg_resources: user
560+
provided resources to be refreshed
554561
555562
:result bool: The decision to refresh the given resource
556563
"""
@@ -565,7 +572,8 @@ def should_upgrade_resource(available_resource, existing_resources, arg_resource
565572
# no upgrade, if it's upload
566573
if existing_resources[res_name].origin == "upload":
567574
return False
568-
# no upgrade, if upstream doesn't have a newer revision of the resource available
575+
# no upgrade, if upstream doesn't have a newer revision of the resource
576+
# available
569577
available_rev = available_resource.get(
570578
"Revision", available_resource.get("revision", -1)
571579
)

juju/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2023 Canonical Ltd.
22
# Licensed under the Apache V2, see LICENCE file for details.
3+
"""Client version definitions."""
34

45
LTS_RELEASES = ["jammy", "focal", "bionic", "xenial", "trusty", "precise"]
56

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ ignore = [
8787
"RUF012",
8888
# FIXME: change the codegen to insert a period at the end of the docstring
8989
"D415",
90+
# FIXME: manually rewrite docstring headlines to git on one line
91+
"D400",
9092
]
9193

9294
[tool.ruff.lint.per-file-ignores]

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2023 Canonical Ltd.
22
# Licensed under the Apache V2, see LICENCE file for details.
3+
"""Building this package."""
34

45
from pathlib import Path
56

tests/unit/test_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def test_should_upgrade_resource_no_same_rev(self):
137137
size=0,
138138
)
139139
}
140-
assert not utils.should_upgrade_resource(res, existing)
140+
assert not utils.should_upgrade_resource(res, existing, {})
141141

142142
def test_should_upgrade_resource_no_local_upload(self):
143143
# fields are trimmed for readability
@@ -176,7 +176,7 @@ def test_should_upgrade_resource_no_local_upload(self):
176176
size=0,
177177
)
178178
}
179-
assert not utils.should_upgrade_resource(res, existing)
179+
assert not utils.should_upgrade_resource(res, existing, {})
180180

181181
def test_should_upgrade_resource_yes_new_revision(self):
182182
# fields are trimmed for readability
@@ -215,4 +215,4 @@ def test_should_upgrade_resource_yes_new_revision(self):
215215
size=0,
216216
)
217217
}
218-
assert utils.should_upgrade_resource(res, existing)
218+
assert utils.should_upgrade_resource(res, existing, {})

0 commit comments

Comments
 (0)