Skip to content

Commit c78e64b

Browse files
authored
Fixes #59: Don't store source when it was the fallback. (#60)
Also cleans up some trivial TODOs
1 parent c5bff00 commit c78e64b

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/manage/install_command.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
)
1111
from .fsutils import ensure_tree, rmtree, unlink
1212
from .indexutils import Index
13-
from .logging import LOGGER, ProgressPrinter
13+
from .logging import CONSOLE_MAX_WIDTH, LOGGER, ProgressPrinter
1414
from .pathutils import Path, PurePath
1515
from .tagutils import install_matches_any, tag_or_range
1616
from .urlutils import (
@@ -21,11 +21,6 @@
2121
)
2222

2323

24-
# TODO: Consider reading the current console width
25-
# Though there's a solid argument we should just pick one and stick with it
26-
CONSOLE_WIDTH = 79
27-
28-
2924
# In-process cache to save repeat downloads
3025
DOWNLOAD_CACHE = {}
3126

@@ -404,7 +399,7 @@ def _download_one(cmd, source, install, download_dir, *, must_copy=False):
404399
if install["url"].casefold().endswith(".nupkg".casefold()):
405400
package = package.with_suffix(".nupkg")
406401

407-
with ProgressPrinter("Downloading", maxwidth=CONSOLE_WIDTH) as on_progress:
402+
with ProgressPrinter("Downloading", maxwidth=CONSOLE_MAX_WIDTH) as on_progress:
408403
package = download_package(cmd, install, package, DOWNLOAD_CACHE, on_progress=on_progress)
409404
validate_package(install, package)
410405
if must_copy and package.parent != download_dir:
@@ -456,7 +451,7 @@ def _install_one(cmd, source, install, *, target=None):
456451
)
457452
raise
458453

459-
with ProgressPrinter("Extracting", maxwidth=CONSOLE_WIDTH) as on_progress:
454+
with ProgressPrinter("Extracting", maxwidth=CONSOLE_MAX_WIDTH) as on_progress:
460455
extract_package(package, dest, on_progress=on_progress, repair=cmd.repair)
461456

462457
if target:
@@ -493,13 +488,13 @@ def _install_one(cmd, source, install, *, target=None):
493488
if s["kind"] not in cmd.disable_shortcut_kinds]
494489
install["shortcuts"] = shortcuts
495490

491+
install["url"] = sanitise_url(install["url"])
492+
if source != cmd.fallback_source:
493+
install["source"] = sanitise_url(source)
494+
496495
LOGGER.debug("Write __install__.json to %s", dest)
497496
with open(dest / "__install__.json", "w", encoding="utf-8") as f:
498-
json.dump({
499-
**install,
500-
"url": sanitise_url(install["url"]),
501-
"source": sanitise_url(source),
502-
}, f, default=str)
497+
json.dump(install, f, default=str)
503498

504499
LOGGER.verbose("Install complete")
505500

@@ -510,13 +505,11 @@ def _fatal_install_error(cmd, ex):
510505
LOGGER.error("An error occurred. Please check any output above, "
511506
"or the log file, and try again.")
512507
LOGGER.info("Log file for this session: !Y!%s!W!", logfile)
513-
# TODO: Update issues URL to actual repository
514508
LOGGER.info("If you cannot resolve it yourself, please report the error with "
515509
"your log file at https://github.com/python/pymanager")
516510
else:
517511
LOGGER.error("An error occurred. Please check any output above, "
518512
"and try again with -vv for more information.")
519-
# TODO: Update issues URL to actual repository
520513
LOGGER.info("If you cannot resolve it yourself, please report the error with "
521514
"verbose output file at https://github.com/python/pymanager")
522515
LOGGER.debug("TRACEBACK:", exc_info=True)
@@ -546,7 +539,7 @@ def execute(cmd):
546539
if not cmd.automatic_install:
547540
LOGGER.debug("automatic_install is not set - exiting")
548541
raise AutomaticInstallDisabledError()
549-
LOGGER.info("!B!" + "*" * CONSOLE_WIDTH + "!W!")
542+
LOGGER.info("!B!" + "*" * CONSOLE_MAX_WIDTH + "!W!")
550543

551544
download_index = {"versions": []}
552545

@@ -737,6 +730,6 @@ def execute(cmd):
737730
finally:
738731
if cmd.automatic:
739732
LOGGER.info("To see all available commands, run '!G!py help!W!'")
740-
LOGGER.info("!B!" + "*" * CONSOLE_WIDTH + "!W!")
733+
LOGGER.info("!B!" + "*" * CONSOLE_MAX_WIDTH + "!W!")
741734

742735
LOGGER.debug("END install_command.execute")

src/manage/pep514utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _is_tag_managed(company_key, tag_name, *, creating=False):
208208
raise
209209
else:
210210
LOGGER.warn("Attempted to clean up invalid registry key %s but "
211-
"failed after too many attempts.", tag_name);
211+
"failed after too many attempts.", tag_name)
212212
return False
213213
return True
214214

0 commit comments

Comments
 (0)