Skip to content

Commit 7f5c393

Browse files
committed
Removing deprecated urlretrieve to fix download_file issue (#2234)
1 parent 2d36847 commit 7f5c393

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"pyyaml>=6.0",
3434
"docker>=6.1.3",
3535
"psutil>=5.9.5",
36+
"requests>=2.31.0",
3637
]
3738

3839
extras_require = {

src/ansys/fluent/core/examples/downloads.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
"""Functions to download sample datasets from the Ansys example data repository."""
2+
import logging
23
import os
34
from pathlib import Path
45
import re
56
import shutil
67
from typing import Optional
7-
import urllib.request
88
import zipfile
99

10+
import requests
11+
1012
import ansys.fluent.core as pyfluent
1113

14+
logger = logging.getLogger("pyfluent.networking")
15+
1216

1317
def delete_downloads():
1418
"""Delete all downloaded examples from the default examples folder to free space or
@@ -55,30 +59,33 @@ def _retrieve_file(
5559
local_path_no_zip = re.sub(".zip$", "", local_path)
5660
filename_no_zip = re.sub(".zip$", "", filename)
5761
# First check if file has already been downloaded
58-
print("Checking if specified file already exists...")
62+
logger.info(f"Checking if {local_path_no_zip} already exists...")
5963
if os.path.isfile(local_path_no_zip) or os.path.isdir(local_path_no_zip):
6064
print(f"File already exists. File path:\n{local_path_no_zip}")
65+
logger.info("File already exists.")
6166
if return_only_filename:
6267
return filename_no_zip
6368
else:
6469
return local_path_no_zip
6570

66-
print("File does not exist. Downloading specified file...")
71+
logger.info("File does not exist. Downloading specified file...")
6772

6873
# Check if save path exists
6974
if not os.path.exists(save_path):
7075
os.makedirs(save_path)
7176

72-
# grab the correct url retriever
73-
urlretrieve = urllib.request.urlretrieve
77+
# Download file
78+
logger.info(f'Downloading URL: "{url}"')
79+
content = requests.get(url).content
80+
with open(local_path, "wb") as f:
81+
f.write(content)
7482

75-
# Perform download
76-
urlretrieve(url, filename=local_path)
7783
if local_path.endswith(".zip"):
7884
_decompress(local_path)
7985
local_path = local_path_no_zip
8086
filename = filename_no_zip
8187
print(f"Download successful. File path:\n{local_path}")
88+
logger.info("Download successful.")
8289
if return_only_filename:
8390
return filename
8491
else:

0 commit comments

Comments
 (0)