Skip to content

Commit

Permalink
Remove backoff dependency (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Nov 11, 2021
1 parent 36ea527 commit 976fc4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
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

0 comments on commit 976fc4f

Please sign in to comment.