Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove backoff dependency #2274

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions custom_components/hacs/helpers/functions/download.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Helpers to download repository content."""
from __future__ import annotations
import asyncio
import os
import pathlib
import tempfile
import zipfile

import async_timeout
import backoff

from custom_components.hacs.exceptions import HacsException
from custom_components.hacs.helpers.functions.filters import (
Expand All @@ -26,30 +27,38 @@ def __init__(self, url, path, name):
self.name = name


@backoff.on_exception(backoff.expo, Exception, max_tries=5)
async def async_download_file(url):
async def async_download_file(url: str) -> bytes | None:
"""Download files, and return the content."""
hacs = get_hacs()
if url is None:
return
return None

hacs = get_hacs()
tries_left = 5

if "tags/" in url:
url = url.replace("tags/", "")

_LOGGER.debug("Downloading %s", url)

result = None
while tries_left > 0:
try:
with async_timeout.timeout(60):
request = await hacs.session.get(url)

with async_timeout.timeout(60):
request = await hacs.session.get(url)
# Make sure that we got a valid result
if request.status == 200:
return await request.read()

# Make sure that we got a valid result
if request.status == 200:
result = await request.read()
else:
raise HacsException(f"Got status code {request.status} when trying to download {url}")
raise HacsException(
f"Got status code {request.status} when trying to download {url}"
)
except Exception as exception:
_LOGGER.debug("Download failed - %s", exception)
tries_left -= 1
await asyncio.sleep(1)
continue

return result
return None


def should_try_releases(repository):
Expand Down
3 changes: 1 addition & 2 deletions custom_components/hacs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"name": "HACS",
"requirements": [
"aiogithubapi>=21.8.1",
"awesomeversion>=21.2.2",
"backoff>=1.10.0"
"awesomeversion>=21.2.2"
],
"version": "0.0.0"
}
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ aresponses==2.1.4
asynctest==0.13.0
attrs==21.2.0
awesomeversion>=21.2.2
backoff>=1.10.0
bellybutton==0.3.1
colorlog==6.6.0
pre-commit==2.15.0
Expand Down