Skip to content

Commit 3b78945

Browse files
authored
Reorder first run output, and suppress unnecessary error. (#213)
Fixes #212
1 parent 3b5cdd5 commit 3b78945

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

src/manage/firstrun.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def __call__(self):
317317
self._shown = True
318318
LOGGER.print("!G!Welcome to the Python installation manager "
319319
"configuration helper.!W!")
320+
line_break()
320321

321322

322323
def line_break():
@@ -329,18 +330,17 @@ def first_run(cmd):
329330
if not cmd.enabled:
330331
return
331332

333+
shown_any = False
334+
332335
welcome = _Welcome()
333336
if cmd.explicit:
334337
welcome()
335-
336-
shown_any = False
338+
shown_any = True
337339

338340
if cmd.check_app_alias:
339341
r = check_app_alias(cmd)
340342
if not r:
341343
welcome()
342-
line_break()
343-
shown_any = True
344344
LOGGER.print("!Y!Your app execution alias settings are configured to launch "
345345
"other commands besides 'py' and 'python'.!W!",
346346
level=logging.WARN)
@@ -358,17 +358,18 @@ def first_run(cmd):
358358
"!B!App execution aliases!W! page and scroll to the "
359359
"'!B!Python!W!' entries to enable the new commands.",
360360
wrap=True)
361+
line_break()
362+
shown_any = True
361363
elif cmd.explicit:
362364
if r == "skip":
363365
LOGGER.info("Skipped app execution aliases check")
364366
else:
365367
LOGGER.info("Checked app execution aliases")
368+
line_break()
366369

367370
if cmd.check_long_paths:
368371
if not check_long_paths(cmd):
369372
welcome()
370-
line_break()
371-
shown_any = True
372373
LOGGER.print("!Y!Windows is not configured to allow paths longer than "
373374
"260 characters.!W!", level=logging.WARN)
374375
LOGGER.print("\nPython and some other apps can exceed this limit, "
@@ -378,33 +379,35 @@ def first_run(cmd):
378379
"path support enabled.\n", wrap=True)
379380
if not cmd.confirm or not cmd.ask_ny("Update setting now?"):
380381
do_configure_long_paths(cmd)
382+
line_break()
383+
shown_any = True
381384
elif cmd.explicit:
382385
LOGGER.info("Checked system long paths setting")
386+
line_break()
383387

384388
if cmd.check_py_on_path:
385389
r = check_py_on_path(cmd)
386390
if not r:
387391
welcome()
388-
line_break()
389-
shown_any = True
390392
LOGGER.print("!Y!The legacy 'py' command is still installed.!W!", level=logging.WARN)
391393
LOGGER.print("\nThis may interfere with launching the new 'py' "
392394
"command, and may be resolved by uninstalling "
393395
"'!B!Python launcher!W!'.\n", wrap=True)
394396
if cmd.confirm and not cmd.ask_ny("Open Installed apps now?"):
395397
os.startfile("ms-settings:appsfeatures")
398+
line_break()
399+
shown_any = True
396400
elif cmd.explicit:
397401
if r == "skip":
398402
LOGGER.info("Skipped check for legacy 'py' command")
399403
else:
400404
LOGGER.info("Checked PATH for legacy 'py' command")
405+
line_break()
401406

402407
if cmd.check_global_dir:
403408
r = check_global_dir(cmd)
404409
if not r:
405410
welcome()
406-
line_break()
407-
shown_any = True
408411
LOGGER.print("!Y!The global shortcuts directory is not "
409412
"configured.!W!", level=logging.WARN)
410413
LOGGER.print("\nConfiguring this enables commands like "
@@ -423,18 +426,19 @@ def first_run(cmd):
423426
not cmd.ask_ny("Add commands directory to your PATH now?")
424427
):
425428
do_global_dir_on_path(cmd)
429+
line_break()
430+
shown_any = True
426431
elif cmd.explicit:
427432
if r == "skip":
428433
LOGGER.info("Skipped check for commands directory on PATH")
429434
else:
430435
LOGGER.info("Checked PATH for versioned commands directory")
436+
line_break()
431437

432438
# This check must be last, because a failed install may exit the program.
433439
if cmd.check_any_install:
434440
if not check_any_install(cmd):
435441
welcome()
436-
line_break()
437-
shown_any = True
438442
LOGGER.print("!Y!You do not have any Python runtimes installed.!W!",
439443
level=logging.WARN)
440444
LOGGER.print("\nInstall the current latest version of CPython? If "
@@ -444,14 +448,15 @@ def first_run(cmd):
444448
LOGGER.info("")
445449
if not cmd.confirm or cmd.ask_yn("Install CPython now?"):
446450
do_install(cmd)
451+
line_break()
452+
shown_any = True
447453
elif cmd.explicit:
448454
LOGGER.info("Checked for any Python installs")
455+
line_break()
449456

450457
if cmd.check_latest_install:
451458
if not check_latest_install(cmd):
452459
welcome()
453-
line_break()
454-
shown_any = True
455460
LOGGER.print("!Y!You do not have the latest Python runtime.!W!",
456461
level=logging.WARN)
457462
LOGGER.print("\nInstall the current latest version of CPython? If "
@@ -460,11 +465,13 @@ def first_run(cmd):
460465
LOGGER.info("")
461466
if not cmd.confirm or cmd.ask_yn("Install CPython now?"):
462467
do_install(cmd)
468+
line_break()
469+
shown_any = True
463470
elif cmd.explicit:
464471
LOGGER.info("Checked for the latest available Python install")
472+
line_break()
465473

466-
if shown_any or cmd.explicit:
467-
line_break()
474+
if shown_any:
468475
LOGGER.print("!G!Configuration checks completed.!W!", level=logging.WARN)
469476
LOGGER.print("\nTo run these checks again, launch !B!Python install "
470477
"manager!W! from your Start menu, or !B!py install "

src/manage/list_command.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,12 @@ def execute(cmd):
324324
cmd.fallback_source,
325325
]:
326326
if source:
327+
downloader = IndexDownloader(source, Index)
328+
if cmd.fallback_source_only:
329+
downloader.quiet = True
327330
try:
328331
installs = _get_installs_from_index(
329-
IndexDownloader(source, Index),
332+
downloader,
330333
tags,
331334
)
332335
break

src/manage/urlutils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ def __init__(self, source, index_cls, auth=None, cache=None):
633633
self._auth = auth if auth is not None else {}
634634
self._cache = cache if cache is not None else {}
635635
self._urlopen = urlopen
636+
self.quiet = False
636637

637638
def __iter__(self):
638639
return self
@@ -667,17 +668,23 @@ def __next__(self):
667668
on_auth_request=self.on_auth,
668669
)
669670
except FileNotFoundError: # includes 404
670-
LOGGER.error("Unable to find runtimes index at %s", sanitise_url(url))
671+
(LOGGER.verbose if self.quiet else LOGGER.error)(
672+
"Unable to find runtimes index at %s",
673+
sanitise_url(url),
674+
)
671675
raise
672676
except OSError as ex:
673-
LOGGER.error(
677+
(LOGGER.verbose if self.quiet else LOGGER.error)(
674678
"Unable to access runtimes index at %s: %s",
675679
sanitise_url(url),
676-
ex.args[1] if len(ex.args) >= 2 else ex
680+
ex.args[1] if len(ex.args) >= 2 else ex,
677681
)
678682
raise
679683
except RuntimeError as ex:
680-
LOGGER.error("An unexpected error occurred while downloading the index: %s", ex)
684+
(LOGGER.verbose if self.quiet else LOGGER.error)(
685+
"An unexpected error occurred while downloading the index: %s",
686+
ex,
687+
)
681688
raise
682689

683690
j = json.loads(data)

tests/test_firstrun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ def test_welcome(assert_log):
124124
welcome = firstrun._Welcome()
125125
assert_log(assert_log.end_of_log())
126126
welcome()
127-
assert_log(".*Welcome.*", assert_log.end_of_log())
127+
assert_log(".*Welcome.*", "", r"!B!\*+!W!", "", assert_log.end_of_log())
128128
welcome()
129-
assert_log(".*Welcome.*", assert_log.end_of_log())
129+
assert_log(".*Welcome.*", "", r"!B!\*+!W!", "", assert_log.end_of_log())
130130

131131

132132

0 commit comments

Comments
 (0)