Skip to content

Commit

Permalink
Replace wget with aiohttp (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkmgit authored Aug 18, 2023
1 parent 3ed8deb commit 29947b8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ sphinx-gallery==0.11.1
matplotlib
networkx
scikit-learn
wget
requests
networkx==2.8.8
async-timeout
aiohttp
pygmtools
15 changes: 12 additions & 3 deletions pygmtools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. ' \
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
3 changes: 2 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ appdirs>=1.4.4
tensorflow==2.9.3
distro
cython
wget
aiohttp
async-timeout
networkx==2.8.8

5 changes: 3 additions & 2 deletions tests/requirements_win_mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ tensorflow==2.9.3
mindspore==1.10.0
distro
cython
wget
networkx==2.8.8
aiohttp
async-timeout
networkx==2.8.8

0 comments on commit 29947b8

Please sign in to comment.