Merge pull request #184 from dhalbert/9.x-support

add 9.x-support; don't give up if download fails
This commit is contained in:
foamyguy 2023-10-29 19:36:35 -05:00 committed by GitHub
commit c4e1c1ad8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 13 deletions

View file

@ -58,7 +58,7 @@ NOT_MCU_LIBRARIES = [
#: The version of CircuitPython found on the connected device.
CPY_VERSION = ""
#: Module formats list (and the other form used in github files)
PLATFORMS = {"py": "py", "8mpy": "8.x-mpy"}
PLATFORMS = {"py": "py", "8mpy": "8.x-mpy", "9mpy": "9.x-mpy"}
#: Commands that do not require an attached board
BOARDLESS_COMMANDS = ["show", "bundle-add", "bundle-remove", "bundle-show"]
#: Version identifier for a bad MPY file format
@ -486,13 +486,12 @@ def ensure_latest_bundle(bundle):
# See #20 for reason for this
click.secho(
(
"There was a problem downloading the bundle. "
"Please try again in a moment."
"There was a problem downloading that platform bundle. "
"Skipping and using existing download if available."
),
fg="red",
)
logger.exception(ex)
sys.exit(1)
else:
logger.info("Current bundle up to date %s.", tag)
@ -691,8 +690,10 @@ def get_bundle(bundle, tag):
:param Bundle bundle: the target Bundle object.
:param str tag: The GIT tag to use to download the bundle.
"""
click.echo("Downloading latest version for {}.\n".format(bundle.key))
click.echo(f"Downloading latest bundles for {bundle.key} ({tag}).")
for platform, github_string in PLATFORMS.items():
# Report the platform: "8.x-mpy", etc.
click.echo(f"{github_string}:")
url = bundle.url_format.format(platform=github_string, tag=tag)
logger.info("Downloading bundle: %s", url)
r = requests.get(url, stream=True, timeout=REQUESTS_TIMEOUT)
@ -703,9 +704,9 @@ def get_bundle(bundle, tag):
# pylint: enable=no-member
total_size = int(r.headers.get("Content-Length"))
temp_zip = bundle.zip.format(platform=platform)
with click.progressbar(r.iter_content(1024), length=total_size) as pbar, open(
temp_zip, "wb"
) as zip_fp:
with click.progressbar(
r.iter_content(1024), label="Extracting:", length=total_size
) as pbar, open(temp_zip, "wb") as zip_fp:
for chunk in pbar:
zip_fp.write(chunk)
pbar.update(len(chunk))

View file

@ -858,7 +858,7 @@ def test_ensure_latest_bundle_to_update():
def test_ensure_latest_bundle_to_update_http_error():
"""
If an HTTP error happens during a bundle update, print a friendly
error message and exit 1.
error message, and use existing bundle.
"""
tags_data = {TEST_BUNDLE_NAME: "12345"}
with mock.patch("circup.Bundle.latest_tag", "54321"), mock.patch(
@ -872,9 +872,7 @@ def test_ensure_latest_bundle_to_update_http_error():
"circup.json"
) as mock_json, mock.patch(
"circup.click.secho"
) as mock_click, mock.patch(
"circup.sys.exit"
) as mock_exit:
) as mock_click:
circup.Bundle.tags_data = dict()
mock_json.load.return_value = tags_data
bundle = circup.Bundle(TEST_BUNDLE_NAME)
@ -882,7 +880,6 @@ def test_ensure_latest_bundle_to_update_http_error():
mock_gb.assert_called_once_with(bundle, "54321")
assert mock_json.dump.call_count == 0 # not saved.
assert mock_click.call_count == 1 # friendly message.
mock_exit.assert_called_once_with(1) # exit 1.
def test_ensure_latest_bundle_no_update():