import contextlib import logging import os import tempfile @contextlib.contextmanager def _tempfile(content, suffix=''): fd, raw_path = tempfile.mkstemp(suffix=suffix) try: os.write(fd, content) os.close(fd) yield raw_path finally: # never called? os.remove(raw_path) def path(package, resource): return _tempfile(b'content', suffix='cacert.pem') _CACERT_CTX = None _CACERT_PATH = None def where(): global _CACERT_CTX global _CACERT_PATH if _CACERT_PATH is None: _CACERT_CTX = path("pip.certifi", "cacert.pem") _CACERT_PATH = str(_CACERT_CTX.__enter__()) return _CACERT_PATH DEFAULT_CA_BUNDLE_PATH = where() class VerboseLogger(logging.Logger): def verbose(self, msg, *args, **kwargs): pass def init_logging(): logging.setLoggerClass(VerboseLogger) init_logging() print("bug.py: temporary directory:", os.listdir('TMP'))