Improve compatibility with Python 3.11

This commit is contained in:
Lumir Balhar 2022-06-06 08:10:27 +02:00 committed by Miro Hrončok
parent 53bd17cb3d
commit e19b87e849
2 changed files with 197 additions and 1 deletions

189
2351.patch Normal file
View File

@ -0,0 +1,189 @@
From 2ebeb2016653914f0fac02dfec52fb20113e523f Mon Sep 17 00:00:00 2001
From: Lumir Balhar <lbalhar@redhat.com>
Date: Mon, 6 Jun 2022 07:12:56 +0200
Subject: [PATCH] Use shlex.quote instead of deprecated pipes.quote
pipes module is deprecated in Py 3.11 and will be removed in 3.13.
https://docs.python.org/3.11/whatsnew/3.11.html
---
docs/changelog/2351.bugfix.rst | 1 +
src/virtualenv/discovery/cached_py_info.py | 8 ++++++--
tasks/make_zipapp.py | 8 ++++++--
tests/unit/activation/conftest.py | 10 +++++++---
tests/unit/activation/test_batch.py | 10 +++++++---
tests/unit/activation/test_powershell.py | 9 +++++++--
6 files changed, 34 insertions(+), 12 deletions(-)
create mode 100644 docs/changelog/2351.bugfix.rst
diff --git a/docs/changelog/2351.bugfix.rst b/docs/changelog/2351.bugfix.rst
new file mode 100644
index 000000000..273c3332a
--- /dev/null
+++ b/docs/changelog/2351.bugfix.rst
@@ -0,0 +1 @@
+Use ``shlex.quote`` instead of deprecated ``pipes.quote`` in Python 3. - by :user:`frenzymadness`.
diff --git a/src/virtualenv/discovery/cached_py_info.py b/src/virtualenv/discovery/cached_py_info.py
index 31beff52f..4e1d976ff 100644
--- a/src/virtualenv/discovery/cached_py_info.py
+++ b/src/virtualenv/discovery/cached_py_info.py
@@ -8,7 +8,6 @@
import logging
import os
-import pipes
import sys
from collections import OrderedDict
@@ -19,6 +18,11 @@
from virtualenv.util.six import ensure_text
from virtualenv.util.subprocess import Popen, subprocess
+if PY2:
+ from pipes import quote
+else:
+ from shlex import quote
+
_CACHE = OrderedDict()
_CACHE[Path(sys.executable)] = PythonInfo()
@@ -126,7 +130,7 @@ def __repr__(self):
def e(v):
return v.decode("utf-8") if isinstance(v, bytes) else v
- cmd_repr = e(" ").join(pipes.quote(e(c)) for c in self.cmd)
+ cmd_repr = e(" ").join(quote(e(c)) for c in self.cmd)
if self.env is not None:
cmd_repr += e(" env of {!r}").format(self.env)
if PY2:
diff --git a/tasks/make_zipapp.py b/tasks/make_zipapp.py
index aa6f62509..8ff2998aa 100644
--- a/tasks/make_zipapp.py
+++ b/tasks/make_zipapp.py
@@ -3,7 +3,6 @@
import io
import json
import os
-import pipes
import shutil
import subprocess
import sys
@@ -18,6 +17,11 @@
from packaging.markers import Marker
from packaging.requirements import Requirement
+if sys.version_info[0] == 2:
+ from pipes import quote
+else:
+ from shlex import quote
+
HERE = Path(__file__).parent.absolute()
VERSIONS = ["3.{}".format(i) for i in range(10, 4, -1)] + ["2.7"]
@@ -227,7 +231,7 @@ def run_suppress_output(cmd, stop_print_on_fail=False):
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
out, err = process.communicate()
if stop_print_on_fail and process.returncode != 0:
- print("exit with {} of {}".format(process.returncode, " ".join(pipes.quote(i) for i in cmd)), file=sys.stdout)
+ print("exit with {} of {}".format(process.returncode, " ".join(quote(i) for i in cmd)), file=sys.stdout)
if out:
print(out, file=sys.stdout)
if err:
diff --git a/tests/unit/activation/conftest.py b/tests/unit/activation/conftest.py
index 6f2dd431c..5c4ae567a 100644
--- a/tests/unit/activation/conftest.py
+++ b/tests/unit/activation/conftest.py
@@ -1,7 +1,6 @@
from __future__ import absolute_import, unicode_literals
import os
-import pipes
import re
import shutil
import subprocess
@@ -11,12 +10,17 @@
import pytest
import six
-from virtualenv.info import IS_PYPY, WIN_CPYTHON_2
+from virtualenv.info import IS_PYPY, PY2, WIN_CPYTHON_2
from virtualenv.run import cli_run
from virtualenv.util.path import Path
from virtualenv.util.six import ensure_str, ensure_text
from virtualenv.util.subprocess import Popen
+if PY2:
+ from pipes import quote
+else:
+ from shlex import quote
+
class ActivationTester(object):
def __init__(self, of_class, session, cmd, activate_script, extension):
@@ -157,7 +161,7 @@ def assert_output(self, out, raw, tmp_path):
assert out[-1] == "None", raw
def quote(self, s):
- return pipes.quote(s)
+ return quote(s)
def python_cmd(self, cmd):
return "{} -c {}".format(os.path.basename(sys.executable), self.quote(cmd))
diff --git a/tests/unit/activation/test_batch.py b/tests/unit/activation/test_batch.py
index 973f0bad8..985d9ff55 100644
--- a/tests/unit/activation/test_batch.py
+++ b/tests/unit/activation/test_batch.py
@@ -1,8 +1,12 @@
from __future__ import absolute_import, unicode_literals
-import pipes
-
from virtualenv.activation import BatchActivator
+from virtualenv.info import PY2
+
+if PY2:
+ from pipes import quote
+else:
+ from shlex import quote
def test_batch(activation_tester_class, activation_tester, tmp_path, activation_python):
@@ -25,7 +29,7 @@ def _get_test_lines(self, activate_script):
def quote(self, s):
"""double quotes needs to be single, and single need to be double"""
- return "".join(("'" if c == '"' else ('"' if c == "'" else c)) for c in pipes.quote(s))
+ return "".join(("'" if c == '"' else ('"' if c == "'" else c)) for c in quote(s))
def print_prompt(self):
return "echo %PROMPT%"
diff --git a/tests/unit/activation/test_powershell.py b/tests/unit/activation/test_powershell.py
index f3705cda1..72ac1bd7d 100644
--- a/tests/unit/activation/test_powershell.py
+++ b/tests/unit/activation/test_powershell.py
@@ -1,11 +1,16 @@
from __future__ import absolute_import, unicode_literals
-import pipes
import sys
import pytest
from virtualenv.activation import PowerShellActivator
+from virtualenv.info import PY2
+
+if PY2:
+ from pipes import quote
+else:
+ from shlex import quote
@pytest.mark.slow
@@ -23,7 +28,7 @@ def __init__(self, session):
def quote(self, s):
"""powershell double double quote needed for quotes within single quotes"""
- return pipes.quote(s).replace('"', '""')
+ return quote(s).replace('"', '""')
def _get_test_lines(self, activate_script):
# for BATCH utf-8 support need change the character code page to 650001

View File

@ -1,6 +1,6 @@
Name: python-virtualenv
Version: 20.13.4
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Tool to create isolated Python environments
License: MIT
@ -9,6 +9,9 @@ Source0: %{pypi_source virtualenv}
# Add /usr/share/python-wheels to extra_search_dir
Patch1: rpm-wheels.patch
# Use shlex.quote instead of deprecated pipes.quote
# https://github.com/pypa/virtualenv/pull/2351
Patch2: https://github.com/pypa/virtualenv/pull/2351.patch
BuildArch: noarch
@ -158,6 +161,10 @@ rm -r tmp_path
%changelog
* Mon Jun 06 2022 Lumír Balhar <lbalhar@redhat.com> - 20.13.4-2
- Improve compatibility with Python 3.11
Resolves: rhbz#2093193
* Mon Mar 21 2022 Lumír Balhar <lbalhar@redhat.com> - 20.13.4-1
- Update to 20.13.4
Resolves: rhbz#2065839