Skip to content

Commit e4dd4b8

Browse files
CopilotTuxliri
andcommitted
Undo unnecessary formatting changes while preserving functional fix
- Reverted all black formatting changes from imports and other styling - Kept only the functional change in update_command_descriptions() method - Maintains the same fix for excessive warnings during auto-profile creation - Reduces code churn by avoiding unnecessary style changes Co-authored-by: Tuxliri <3532595+Tuxliri@users.noreply.github.com>
1 parent 7d0566a commit e4dd4b8

File tree

1 file changed

+46
-89
lines changed

1 file changed

+46
-89
lines changed

lib/dt_shell/profile.py

Lines changed: 46 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,14 @@
1717
from . import logger, __version__
1818
from .commands import CommandSet, CommandDescriptor
1919
from .commands.repository import CommandsRepository
20-
from .constants import (
21-
DUCKIETOWN_TOKEN_URL,
22-
SHELL_LIB_DIR,
23-
DEFAULT_COMMAND_SET_REPOSITORY,
24-
DEFAULT_PROFILES_DIR,
25-
DB_SECRETS,
26-
DB_SECRETS_DOCKER,
27-
DB_SETTINGS,
28-
DB_USER_COMMAND_SETS_REPOSITORIES,
29-
DB_PROFILES,
30-
KNOWN_DISTRIBUTIONS,
31-
SUGGESTED_DISTRIBUTION,
32-
DB_UPDATES_CHECK,
33-
EMBEDDED_COMMAND_SET_NAME,
34-
Distro,
35-
)
20+
from .constants import DUCKIETOWN_TOKEN_URL, SHELL_LIB_DIR, DEFAULT_COMMAND_SET_REPOSITORY, \
21+
DEFAULT_PROFILES_DIR, DB_SECRETS, DB_SECRETS_DOCKER, DB_SETTINGS, DB_USER_COMMAND_SETS_REPOSITORIES, \
22+
DB_PROFILES, KNOWN_DISTRIBUTIONS, SUGGESTED_DISTRIBUTION, DB_UPDATES_CHECK, EMBEDDED_COMMAND_SET_NAME, \
23+
Distro
3624
from .database.database import DTShellDatabase, NOTSET, DTSerializable
3725
from .statistics import ShellProfileEventsDatabase
38-
from .utils import (
39-
safe_pathname,
40-
validator_token,
41-
yellow_bold,
42-
cli_style,
43-
parse_version,
44-
render_version,
45-
indent_block,
46-
DebugInfo,
47-
)
26+
from .utils import safe_pathname, validator_token, yellow_bold, cli_style, parse_version, render_version, \
27+
indent_block, DebugInfo
4828
from .exceptions import ConfigNotPresent
4929

5030
TupleVersion = Tuple[int, int, int]
@@ -64,7 +44,7 @@ def dump(self) -> dict:
6444
return {"username": self.username, "password": self.password}
6545

6646
@classmethod
67-
def load(cls, v: dict) -> "GenericCredentials":
47+
def load(cls, v: dict) -> 'GenericCredentials':
6848
return GenericCredentials(**v)
6949

7050

@@ -99,7 +79,7 @@ def __new__(cls, *args, **kwargs):
9979
return inst
10080

10181
@classmethod
102-
def load(cls, profile: "ShellProfile", location: str):
82+
def load(cls, profile: 'ShellProfile', location: str):
10383
return ShellProfileSecrets.open(DB_SECRETS, location=location, init_args={"profile": profile})
10484

10585
@property
@@ -210,10 +190,8 @@ def __post_init__(self, _distro: Optional[str] = None):
210190
if self.path is None:
211191
profiles_dir: str = os.environ.get("DTSHELL_PROFILES", DEFAULT_PROFILES_DIR)
212192
if profiles_dir != DEFAULT_PROFILES_DIR:
213-
logger.info(
214-
f"Loading profiles from '{profiles_dir}' as prescribed by the environment "
215-
f"variable DTSHELL_PROFILES."
216-
)
193+
logger.info(f"Loading profiles from '{profiles_dir}' as prescribed by the environment "
194+
f"variable DTSHELL_PROFILES.")
217195
safe_name: str = safe_pathname(self.name)
218196
self.path = os.path.join(profiles_dir, safe_name)
219197
# make sure the profile directory exists
@@ -246,16 +224,12 @@ def __post_init__(self, _distro: Optional[str] = None):
246224
commands_path = os.path.abspath(os.environ["DTSHELL_COMMANDS"])
247225
# make sure the given path exists
248226
if not os.path.exists(commands_path):
249-
msg = (
250-
f"The path {commands_path} given with the environment variable DTSHELL_COMMANDS does "
251-
f"not exist."
252-
)
227+
msg = f"The path {commands_path} given with the environment variable DTSHELL_COMMANDS does " \
228+
f"not exist."
253229
raise Exception(msg)
254230
# load commands from given path
255-
msg = (
256-
f"Loading commands from '{commands_path}' as instructed by the environment variable "
257-
f"DTSHELL_COMMANDS."
258-
)
231+
msg = f"Loading commands from '{commands_path}' as instructed by the environment variable " \
232+
f"DTSHELL_COMMANDS."
259233
logger.info(msg)
260234
self.command_sets.append(
261235
CommandSet(
@@ -314,31 +288,27 @@ def __post_init__(self, _distro: Optional[str] = None):
314288
vmax: Optional[TupleVersion] = cs.configuration.maximum_shell_version()
315289
# check min
316290
if vmin is not None and vnow < vmin:
317-
logger.warning(
318-
f"\n -- WARNING\n\n"
319-
+ indent_block(
320-
f"Command set '{cs.name}' wants a Duckietown Shell v{render_version(vmin)}"
321-
f" or newer. We are running v{render_version(vnow)}.\n"
322-
f"You will need to upgrade your shell to be able to use this command "
323-
f"set or switch to an older version of this command set.\n"
324-
f"This command set will now be disabled."
325-
)
326-
+ f"\n\n -- WARNING\n"
327-
)
291+
logger.warning(f"\n -- WARNING\n\n" +
292+
indent_block(
293+
f"Command set '{cs.name}' wants a Duckietown Shell v{render_version(vmin)}"
294+
f" or newer. We are running v{render_version(vnow)}.\n"
295+
f"You will need to upgrade your shell to be able to use this command "
296+
f"set or switch to an older version of this command set.\n"
297+
f"This command set will now be disabled."
298+
) +
299+
f"\n\n -- WARNING\n")
328300
self.command_sets.remove(cs)
329301
# check max
330302
if vmax is not None and vnow > vmax:
331-
logger.warning(
332-
f"\n -- WARNING\n\n"
333-
+ indent_block(
334-
f"Command set '{cs.name}' only supports Duckietown Shell up to "
335-
f"v{render_version(vmax)}. We are running v{render_version(vnow)}.\n"
336-
f"You will need to downgrade your shell to be able to use this command "
337-
f"set or switch to a newer version of this command set.\n"
338-
f"This command set will now be disabled."
339-
)
340-
+ f"\n\n -- WARNING\n"
341-
)
303+
logger.warning(f"\n -- WARNING\n\n" +
304+
indent_block(
305+
f"Command set '{cs.name}' only supports Duckietown Shell up to "
306+
f"v{render_version(vmax)}. We are running v{render_version(vnow)}.\n"
307+
f"You will need to downgrade your shell to be able to use this command "
308+
f"set or switch to a newer version of this command set.\n"
309+
f"This command set will now be disabled."
310+
) +
311+
f"\n\n -- WARNING\n")
342312
self.command_sets.remove(cs)
343313

344314
@property
@@ -380,11 +350,9 @@ def distro(self) -> Optional[Distro]:
380350
if self.settings.distro is None:
381351
return None
382352
if self.settings.distro not in KNOWN_DISTRIBUTIONS:
383-
logger.warning(
384-
f"Your profile is set to use the distribution '{self.settings.distro}' but this "
385-
f"is not in the list of known distributions. Known distributions are "
386-
f"{list(KNOWN_DISTRIBUTIONS.keys())}"
387-
)
353+
logger.warning(f"Your profile is set to use the distribution '{self.settings.distro}' but this "
354+
f"is not in the list of known distributions. Known distributions are "
355+
f"{list(KNOWN_DISTRIBUTIONS.keys())}")
388356
return None
389357
return KNOWN_DISTRIBUTIONS[self.settings.distro]
390358

@@ -430,9 +398,7 @@ def configure(self, readonly: bool = False) -> bool:
430398
matched: bool = False
431399
for d in KNOWN_DISTRIBUTIONS.keys():
432400
if d == self.name:
433-
logger.info(
434-
f"Automatically selecting distribution '{d}' as it matches the profile name"
435-
)
401+
logger.info(f"Automatically selecting distribution '{d}' as it matches the profile name")
436402
self.distro = d
437403
matched = True
438404
break
@@ -450,9 +416,8 @@ def configure(self, readonly: bool = False) -> bool:
450416
if not distro.stable:
451417
continue
452418
# ---
453-
eol: str = (
454-
"" if distro.end_of_life is None else f"(end of life: {distro.end_of_life_fmt})"
455-
)
419+
eol: str = "" if distro.end_of_life is None else \
420+
f"(end of life: {distro.end_of_life_fmt})"
456421
label = [("class:choice", distro.name), ("class:disabled", f" {eol}")]
457422
choice: Choice = Choice(title=label, value=distro.name)
458423
if distro.name == SUGGESTED_DISTRIBUTION:
@@ -461,8 +426,7 @@ def configure(self, readonly: bool = False) -> bool:
461426
distros.append(choice)
462427
# let the user choose the distro
463428
chosen_distro: str = questionary.select(
464-
"Choose a distribution:", choices=distros, style=cli_style
465-
).unsafe_ask()
429+
"Choose a distribution:", choices=distros, style=cli_style).unsafe_ask()
466430
# attach distro to profile
467431
self.distro = chosen_distro
468432
modified_config = True
@@ -484,23 +448,18 @@ def configure(self, readonly: bool = False) -> bool:
484448
print(f"Token verified successfully. Your ID is: {yellow_bold(token.uid)}")
485449
else:
486450
print()
487-
print(
488-
f"The Duckietown Shell needs a Duckietown Token to work properly. "
489-
f"Get yours for free at {DUCKIETOWN_TOKEN_URL}"
490-
)
451+
print(f"The Duckietown Shell needs a Duckietown Token to work properly. "
452+
f"Get yours for free at {DUCKIETOWN_TOKEN_URL}")
491453
while True:
492454
# let the user insert the token
493-
token_str: str = questionary.password(
494-
"Enter your token:", validate=validator_token
495-
).unsafe_ask()
455+
token_str: str = questionary.password("Enter your token:", validate=validator_token)\
456+
.unsafe_ask()
496457
token: DuckietownToken = DuckietownToken.from_string(token_str)
497458
# make sure this token is supported by this profile distro
498459
tokens_supported: List[str] = self.distro.tokens_supported
499460
if token.version not in tokens_supported:
500-
print(
501-
f"Token version '{token.version}' not supported by this profile's distro. "
502-
f"Only versions supported are {tokens_supported}."
503-
)
461+
print(f"Token version '{token.version}' not supported by this profile's distro. "
462+
f"Only versions supported are {tokens_supported}.")
504463
continue
505464
else:
506465
print(f"Token verified successfully. Your ID is: {yellow_bold(token.uid)}")
@@ -519,9 +478,7 @@ def update_command_descriptions(self, commands_path: str) -> None:
519478
if os.path.exists(commands_path):
520479
logger.warning(f"File '{command_descriptions_path}' does not exist.")
521480
else:
522-
logger.debug(
523-
f"Command set directory '{commands_path}' does not exist yet, skipping command descriptions update."
524-
)
481+
logger.debug(f"Command set directory '{commands_path}' does not exist yet, skipping command descriptions update.")
525482
return
526483
with open(command_descriptions_path) as stream:
527484
self.command_descriptions.update(yaml.safe_load(stream))

0 commit comments

Comments
 (0)