Skip to content

Commit

Permalink
Windows build failing with SSL error #733
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite authored and mergify[bot] committed Oct 14, 2021
1 parent 295b8b0 commit ea577ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Ignore VCF files during pytest collection, so it doesn't fail if cyvcf2 isn't installed.
collect_ignore_glob = ["sgkit/io/vcf/*.py", ".github/scripts/*.py"]
collect_ignore_glob = ["benchmarks/*.py", "sgkit/io/vcf/*.py", ".github/scripts/*.py"]


def pytest_configure(config) -> None: # type: ignore
Expand Down
2 changes: 2 additions & 0 deletions sgkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sgkit._windows_ssl_fix # noqa: F401 isort:skip # must be imported first to apply fix

from pkg_resources import DistributionNotFound, get_distribution

from .display import display_genotypes
Expand Down
22 changes: 22 additions & 0 deletions sgkit/_windows_ssl_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Monkey patch https://github.com/pystatgen/sgkit/issues/733
import ssl


def _ssl_load_windows_store_certs(self, storename, purpose): # type: ignore[no-untyped-def] # pragma: no cover
# Code adapted from _load_windows_store_certs in https://github.com/python/cpython/blob/main/Lib/ssl.py
try:
certs = [
cert
for cert, encoding, trust in ssl.enum_certificates(storename) # type: ignore
if encoding == "x509_asn" and (trust is True or purpose.oid in trust)
]
except PermissionError:
return
for cert in certs:
try:
self.load_verify_locations(cadata=cert)
except ssl.SSLError:
pass


ssl.SSLContext._load_windows_store_certs = _ssl_load_windows_store_certs # type: ignore

0 comments on commit ea577ba

Please sign in to comment.