diff --git a/README.md b/README.md index 4f7c4ed..715f29c 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,9 @@ numpy >= 1.18.5 easydict >= 1.7 appdirs >= 1.4.4 tqdm >= 4.64.1 -wget >= 3.2 networkx >= 2.8.8 +aiohttp +async-timeout ``` ## Available Graph Matching Solvers diff --git a/docs/requirements.txt b/docs/requirements.txt index cdf54f1..d9affdf 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -14,6 +14,8 @@ sphinx-gallery==0.11.1 matplotlib networkx scikit-learn -wget +requests networkx==2.8.8 +async-timeout +aiohttp pygmtools diff --git a/pygmtools/utils.py b/pygmtools/utils.py index 277989f..b1595aa 100644 --- a/pygmtools/utils.py +++ b/pygmtools/utils.py @@ -23,11 +23,13 @@ import shutil from tqdm.auto import tqdm import inspect -import wget import numpy as np import pygmtools import networkx as nx import urllib.request +import asyncio +import aiohttp +import async_timeout NOT_IMPLEMENTED_MSG = \ 'The backend function for {} is not implemented. ' \ @@ -1225,6 +1227,13 @@ def download(filename, url, md5=None, retries=5, to_cache=True): else: raise ValueError("The url should be string or list of string.") +async def _asyncdownload(filename, url): + async with aiohttp.ClientSession() as session: + async with async_timeout.timeout(120): + async with session.get(url) as response: + with open(filename, 'wb') as file: + async for data in response.content.iter_chunked(512): + file.write(data) def _download(filename, url, md5, retries, to_cache=True): if retries <= 0: @@ -1249,7 +1258,7 @@ def _download(filename, url, md5, retries, to_cache=True): return download(filename, url, md5, retries - 1) elif retries % 3 == 2: try: - wget.download(url,out=filename) + asyncio.run(_asyncdownload(filename, url)) except: return _download(filename, url, md5, retries - 1) else: @@ -1529,4 +1538,4 @@ def to_graphml(adj_matrix, filename, backend=None): [0.15422904, 0.64656912, 0.93219422, 0.784769 ]]) """ nx.write_graphml(to_networkx(adj_matrix, backend), filename) - \ No newline at end of file + diff --git a/setup.py b/setup.py index 3aa9879..8a47a53 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def get_property(prop, project): VERSION = get_property('__version__', NAME) REQUIRED = [ 'requests>=2.25.1', 'scipy>=1.4.1', 'Pillow>=7.2.0', 'numpy>=1.18.5', 'easydict>=1.7', 'appdirs>=1.4.4', 'tqdm>=4.64.1', - 'wget>=3.2', 'networkx>=2.8.8' + 'async-timeout','aiohttp','networkx>=2.8.8' ] EXTRAS = {} diff --git a/tests/requirements.txt b/tests/requirements.txt index a1b9cfe..8b06bf0 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -12,6 +12,7 @@ appdirs>=1.4.4 tensorflow==2.9.3 distro cython -wget +aiohttp +async-timeout networkx==2.8.8 diff --git a/tests/requirements_win_mac.txt b/tests/requirements_win_mac.txt index 5b0fcd8..e1f906e 100644 --- a/tests/requirements_win_mac.txt +++ b/tests/requirements_win_mac.txt @@ -12,5 +12,6 @@ tensorflow==2.9.3 mindspore==1.10.0 distro cython -wget -networkx==2.8.8 \ No newline at end of file +aiohttp +async-timeout +networkx==2.8.8