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

Skip to content

Commit 699742e

Browse files
dopplershiftMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #9243: Fix download of freetype 2.6.1.
by checking file hash before exiting the download loop. attn QuLogic <!--Thank you so much for your PR! To help us review, fill out the form to the best of your ability. Please make use of the development guide at https://matplotlib.org/devdocs/devel/index.html--> <!--Provide a general summary of your changes in the title above, for example "Raises ValueError on Non-Numeric Input to set_xlim". Please avoid non-descriptive titles such as "Addresses issue 8576".--> <!--If you are able to do so, please do not create the PR out of master, but out of a separate branch. See https://matplotlib.org/devel/gitwash/development_workflow.html for instructions.--> PR Summary <!--Please provide at least 1-2 sentences describing the pull request in detail. Why is this change required? What problem does it solve?--> <!--If it fixes an open issue, please link to the issue here.--> PR Checklist - [ ] Has Pytest style unit tests - [ ] Code is PEP 8 compliant - [ ] New features are documented, with examples if plot related - [ ] Documentation is sphinx and numpydoc compliant - [ ] Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there) - [ ] Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way <!--We understand that PRs can sometimes be overwhelming, especially as the reviews start coming in. Please let us know if the reviews are unclear or the recommended next step seems overly demanding , or if you would like help in addressing a reviewer's comments. And please ping us if you've been waiting too long to hear back on your PR.-->
1 parent f2c8fae commit 699742e

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

setupext.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,40 +1166,39 @@ def do_custom_build(self):
11661166
if not os.path.exists('build'):
11671167
os.makedirs('build')
11681168

1169-
sourceforge_url = (
1169+
url_fmts = [
11701170
'https://downloads.sourceforge.net/project/freetype'
1171-
'/freetype2/{0}/'.format(LOCAL_FREETYPE_VERSION)
1172-
)
1173-
url_fmts = (
1174-
sourceforge_url + '{0}',
1175-
'https://download.savannah.gnu.org/releases/freetype/{0}'
1176-
)
1171+
'/freetype2/{version}/{tarball}',
1172+
'https://download.savannah.gnu.org/releases/freetype'
1173+
'/{tarball}'
1174+
]
11771175
for url_fmt in url_fmts:
1178-
tarball_url = url_fmt.format(tarball)
1176+
tarball_url = url_fmt.format(
1177+
version=LOCAL_FREETYPE_VERSION, tarball=tarball)
11791178

11801179
print("Downloading {0}".format(tarball_url))
11811180
try:
11821181
urlretrieve(tarball_url, tarball_path)
1183-
except:
1182+
except IOError: # URLError (a subclass) on Py3.
11841183
print("Failed to download {0}".format(tarball_url))
11851184
else:
1186-
break
1187-
if not os.path.isfile(tarball_path):
1185+
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
1186+
print("Invalid hash.")
1187+
else:
1188+
break
1189+
else:
11881190
raise IOError("Failed to download freetype")
1189-
if get_file_hash(tarball_path) == LOCAL_FREETYPE_HASH:
1190-
try:
1191-
os.makedirs(tarball_cache_dir)
1192-
except OSError:
1193-
# Don't care if it exists.
1194-
pass
1195-
try:
1196-
shutil.copy(tarball_path, tarball_cache_path)
1197-
print('Cached tarball at: {}'
1198-
.format(tarball_cache_path))
1199-
except OSError:
1200-
# again, we do not care if this fails, can
1201-
# always re download
1202-
pass
1191+
try:
1192+
os.makedirs(tarball_cache_dir)
1193+
except OSError:
1194+
# Don't care if it exists.
1195+
pass
1196+
try:
1197+
shutil.copy(tarball_path, tarball_cache_path)
1198+
print('Cached tarball at: {}'.format(tarball_cache_path))
1199+
except OSError:
1200+
# If this fails, we can always re-download.
1201+
pass
12031202

12041203
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
12051204
raise IOError(

0 commit comments

Comments
 (0)