From 0cc4b3740a754a5094b8898ddd33436767dc78cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 13 Dec 2018 09:57:05 +0100 Subject: [PATCH] Don't fail on missing certifi's cert bundle https://bugzilla.redhat.com/show_bug.cgi?id=1655253 https://github.com/pypa/virtualenv/pull/1252 --- dont-fail-on-missing-certifi-cert.patch | 79 +++++++++++++++++++++++++ python-virtualenv.spec | 9 ++- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 dont-fail-on-missing-certifi-cert.patch diff --git a/dont-fail-on-missing-certifi-cert.patch b/dont-fail-on-missing-certifi-cert.patch new file mode 100644 index 0000000..dd6bc0d --- /dev/null +++ b/dont-fail-on-missing-certifi-cert.patch @@ -0,0 +1,79 @@ +diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py +index ce45ede..3cd200b 100644 +--- a/tests/test_virtualenv.py ++++ b/tests/test_virtualenv.py +@@ -4,11 +4,16 @@ import os + import shutil + import sys + import tempfile ++import zipfile + import pytest + import platform # noqa + + from mock import patch, Mock + ++try: ++ from pathlib import Path ++except ImportError: ++ from pathlib2 import Path + + def test_version(): + """Should have a version string""" +@@ -139,3 +144,44 @@ def test_always_copy_option(): + " symlink (to %s)" % (full_name, os.readlink(full_name)) + finally: + shutil.rmtree(tmp_virtualenv) ++ ++ ++def test_missing_certifi_pem(tmp_path): ++ """Make sure that we can still create virtual environment if pip is ++ patched to not use certifi's cacert.pem and the file is removed. ++ This can happen if pip is packaged by Linux distributions.""" ++ proj_dir = Path(__file__).parent.parent ++ support_original = proj_dir / "virtualenv_support" ++ pip_wheel = sorted(support_original.glob("pip*whl"))[0] ++ whl_name = pip_wheel.name ++ ++ wheeldir = tmp_path / "wheels" ++ wheeldir.mkdir() ++ tmpcert = tmp_path / "tmpcert.pem" ++ cacert = "pip/_vendor/certifi/cacert.pem" ++ certifi = "pip/_vendor/certifi/core.py" ++ oldpath = b"os.path.join(f, 'cacert.pem')" ++ newpath = "r'{}'".format(tmpcert).encode() ++ removed = False ++ replaced = False ++ ++ with zipfile.ZipFile(str(pip_wheel), "r") as whlin: ++ with zipfile.ZipFile(str(wheeldir / whl_name), "w") as whlout: ++ for item in whlin.infolist(): ++ buff = whlin.read(item.filename) ++ if item.filename == cacert: ++ tmpcert.write_bytes(buff) ++ removed = True ++ continue ++ if item.filename == certifi: ++ nbuff = buff.replace(oldpath, newpath) ++ assert nbuff != buff ++ buff = nbuff ++ replaced = True ++ whlout.writestr(item, buff) ++ ++ assert removed and replaced ++ ++ venvdir = tmp_path / "venv" ++ search_dirs = [str(wheeldir), str(support_original)] ++ virtualenv.create_environment(str(venvdir), search_dirs=search_dirs) +diff --git a/virtualenv.py b/virtualenv.py +index c1fe7f1..3837250 100755 +--- a/virtualenv.py ++++ b/virtualenv.py +@@ -867,6 +867,8 @@ def install_wheel(project_names, py_executable, search_dirs=None, + except ImportError: + from pip import main as _main + cert_data = pkgutil.get_data("pip._vendor.requests", "cacert.pem") ++ except IOError: ++ cert_data = None + + if cert_data is not None: + cert_file = tempfile.NamedTemporaryFile(delete=False) diff --git a/python-virtualenv.spec b/python-virtualenv.spec index 9483e7d..3d9db34 100644 --- a/python-virtualenv.spec +++ b/python-virtualenv.spec @@ -1,6 +1,6 @@ Name: python-virtualenv Version: 16.0.0 -Release: 5%{?dist} +Release: 6%{?dist} Summary: Tool to create isolated Python environments Group: Development/Languages @@ -23,6 +23,10 @@ Patch1: python26.patch # Add /usr/share/python-wheels to file_search_dirs Patch2: rpm-wheels.patch +# Don't fail on missing certifi's cert +# https://github.com/pypa/virtualenv/pull/1252 +Patch3: dont-fail-on-missing-certifi-cert.patch + BuildArch: noarch BuildRequires: git-core BuildRequires: python2-devel @@ -195,6 +199,9 @@ rm %{buildroot}/%{_bindir}/virtualenv %changelog +* Thu Dec 13 2018 Miro Hrončok - 16.0.0-6 +- Don't fail on missing certifi's cert bundle (#1655253) + * Wed Aug 15 2018 Miro Hrončok - 16.0.0-5 - Use wheels from RPM packages - Put wheels needed for Python 2.6 into a subpackage