nixpkgs/pkgs/development/python-modules/certifi/env.patch
VojtechStep 8f81cc2fd8 python3Packages.certifi: fix build on Python 3.10
The previous commit to the patch removed too much when adjusting to
upstream deprecating 3.7
2026-02-01 16:40:36 +01:00

61 lines
1.7 KiB
Diff

diff --git a/certifi/core.py b/certifi/core.py
index 1c9661c..d904382 100644
--- a/certifi/core.py
+++ b/certifi/core.py
@@ -4,6 +4,7 @@ certifi.py
This module returns the installation location of cacert.pem or its contents.
"""
+import os
import sys
import atexit
@@ -11,12 +12,21 @@ def exit_cacert_ctx() -> None:
_CACERT_CTX.__exit__(None, None, None) # type: ignore[union-attr]
+def get_cacert_path_from_environ():
+ path = os.environ.get("NIX_SSL_CERT_FILE", None)
+
+ if path == "/no-cert-file.crt":
+ return None
+
+ return path
+
+
if sys.version_info >= (3, 11):
from importlib.resources import as_file, files
_CACERT_CTX = None
- _CACERT_PATH = None
+ _CACERT_PATH = get_cacert_path_from_environ()
def where() -> str:
# This is slightly terrible, but we want to delay extracting the file
@@ -44,6 +54,8 @@ if sys.version_info >= (3, 11):
return _CACERT_PATH
def contents() -> str:
+ if _CACERT_PATH is not None:
+ return open(_CACERT_PATH, encoding="utf-8").read()
return files("certifi").joinpath("cacert.pem").read_text(encoding="ascii")
else:
@@ -51,7 +63,7 @@ else:
from importlib.resources import path as get_path, read_text
_CACERT_CTX = None
- _CACERT_PATH = None
+ _CACERT_PATH = get_cacert_path_from_environ()
def where() -> str:
# This is slightly terrible, but we want to delay extracting the
@@ -80,4 +92,6 @@ else:
return _CACERT_PATH
def contents() -> str:
- return read_text("certifi", "cacert.pem", encoding="ascii")
+ if _CACERT_PATH is not None:
+ return open(_CACERT_PATH, encoding="utf-8").read()
+ return read_text("certifi", "cacert.pem", encoding="utf-8")