Skip to content

Use certifi when downloading bundled build requirements. #18225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def build_extensions(self):

python_requires='>={}'.format('.'.join(str(n) for n in min_version)),
setup_requires=[
"certifi>=2020.06.20",
"numpy>=1.15",
],
install_requires=[
Expand Down
10 changes: 9 additions & 1 deletion setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def _get_hash(data):
return hasher.hexdigest()


@functools.lru_cache()
def _get_ssl_context():
import certifi
import ssl
return ssl.create_default_context(cafile=certifi.where())


def download_or_cache(url, sha):
"""
Get bytes from the given url or local cache.
Expand Down Expand Up @@ -73,7 +80,8 @@ def download_or_cache(url, sha):
# default User-Agent, but not (for example) wget; so I don't feel too
# bad passing in an empty User-Agent.
with urllib.request.urlopen(
urllib.request.Request(url, headers={"User-Agent": ""})) as req:
urllib.request.Request(url, headers={"User-Agent": ""}),
context=_get_ssl_context()) as req:
data = req.read()

file_sha = _get_hash(data)
Expand Down