Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08e9971

Browse files
committed
MNT: minor fix ups
- remove debugging prints - use local backport of makedirs with exist_ok=True - raise exception with manual instructions if downloading fails - move a comment block - save a pass through a list comprehension
1 parent 0b0d779 commit 08e9971

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

setup.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
import setupext
4646
from setupext import (print_line, print_raw, print_message, print_status,
47-
download_or_cache)
47+
download_or_cache, makedirs as _makedirs)
4848

4949
# Get the version from versioneer
5050
import versioneer
@@ -124,15 +124,13 @@ def _download_jquery_to(dest):
124124
url = "https://jqueryui.com/resources/download/jquery-ui-1.12.1.zip"
125125
sha = 'f8233674366ab36b2c34c577ec77a3d70cac75d2e387d8587f3836345c0f624d'
126126
if not os.path.exists(os.path.join(dest, "jquery-ui-1.12.1")):
127+
_makedirs(dest, exist_ok=True)
127128
try:
128-
os.makedirs(dest)
129-
except OSError:
130-
pass
131-
print("DOWNLOADING JQUERY TO {}".format(dest))
132-
# jQueryUI's website blocks direct downloads from urllib.request's
133-
# default User-Agent, but not (for example) wget; so I don't feel too
134-
# bad passing in an empty User-Agent.
135-
buff = download_or_cache(url, sha)
129+
buff = download_or_cache(url, sha)
130+
except Exception:
131+
raise IOError("Failed to download jquery-ui. Please download " +
132+
"{url} and extract it to {dest}.".format(
133+
url=url, dest=dest))
136134
with ZipFile(buff) as zf:
137135
zf.extractall(dest)
138136

setupext.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def get_from_cache(local_fn):
9797
raise Exception("no cache dir")
9898
cache_filename = os.path.join(cache_dir, local_fn)
9999
with open(cache_filename, 'rb') as fin:
100-
print('opened the file')
101100
buf = BytesIO(fin.read())
102101
file_sha = get_fd_hash(buf)
103102
if file_sha != sha:
@@ -128,6 +127,9 @@ def write_cache(local_fn, data):
128127
except Exception:
129128
pass
130129

130+
# jQueryUI's website blocks direct downloads from urllib.request's
131+
# default User-Agent, but not (for example) wget; so I don't feel too
132+
# bad passing in an empty User-Agent.
131133
with urlopen(
132134
Request(url, headers={"User-Agent": ""})) as req:
133135
file_contents = BytesIO(req.read())
@@ -971,19 +973,19 @@ def do_custom_build(self):
971973
]
972974
tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION)
973975

974-
for url_fmt in url_fmts:
975-
tarball_url = url_fmt.format(
976-
version=LOCAL_FREETYPE_VERSION, tarball=tarball)
976+
target_urls = [
977+
url_fmt.format(version=LOCAL_FREETYPE_VERSION,
978+
tarball=tarball)
979+
for url_fmt in url_fmts]
980+
981+
for tarball_url in target_urls:
977982
try:
978983
tar_contents = download_or_cache(tarball_url,
979984
LOCAL_FREETYPE_HASH)
980985
break
981986
except Exception as ex:
982987
raise ex
983988
else:
984-
target_urls = [url_fmt.format(
985-
version=LOCAL_FREETYPE_VERSION, tarball=tarball)
986-
for url_fmt in url_fmts]
987989
raise IOError("Failed to download FreeType. Please download " +
988990
"one of {target_urls} ".format(
989991
target_urls=target_urls) +

0 commit comments

Comments
 (0)