Skip to content

Commit 60d9fe0

Browse files
committed
Avoid importing pipes on Python 3.3+
1 parent c3a9856 commit 60d9fe0

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Adam Johnson
12
Albin Vass
23
Alex Grönholm
34
Alexander Loechel

docs/changelog/2417.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid importing ``pipes`` on Python 3.3+ to avoid ``DeprecationWarning`` on Python 3.11 -- by :user:`adamchainz`

src/tox/action.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import, unicode_literals
22

33
import os
4-
import pipes
54
import signal
65
import subprocess
76
import sys
@@ -18,6 +17,11 @@
1817
from tox.util.lock import get_unique_file
1918
from tox.util.stdlib import is_main_thread
2019

20+
try:
21+
from shlex import quote as shlex_quote
22+
except ImportError:
23+
from pipes import quote as shlex_quote
24+
2125

2226
class Action(object):
2327
"""Action is an effort to group operations with the same goal (within reporting)"""
@@ -89,7 +93,7 @@ def popen(
8993
"""this drives an interaction with a subprocess"""
9094
cwd = py.path.local() if cwd is None else cwd
9195
cmd_args = [str(x) for x in self._rewrite_args(cwd, args)]
92-
cmd_args_shell = " ".join(pipes.quote(i) for i in cmd_args)
96+
cmd_args_shell = " ".join(shlex_quote(i) for i in cmd_args)
9397
stream_getter = self._get_standard_streams(
9498
capture_err,
9599
cmd_args_shell,

src/tox/exception.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import os
2-
import pipes
32
import signal
43

4+
try:
5+
from shlex import quote as shlex_quote
6+
except ImportError:
7+
from pipes import quote as shlex_quote
8+
59

610
def exit_code_str(exception_name, command, exit_code):
711
"""String representation for an InvocationError, with exit code
@@ -96,7 +100,7 @@ def __init__(self, config):
96100
self.config = config
97101

98102
def __str__(self):
99-
return " ".join(pipes.quote(i) for i in self.config.requires)
103+
return " ".join(shlex_quote(i) for i in self.config.requires)
100104

101105

102106
class BadRequirement(Error):

src/tox/venv.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import codecs
22
import json
33
import os
4-
import pipes
54
import re
65
import sys
76
from itertools import chain
@@ -19,6 +18,11 @@
1918

2019
from .config import DepConfig
2120

21+
try:
22+
from shlex import quote as shlex_quote
23+
except ImportError:
24+
from pipes import quote as shlex_quote
25+
2226
#: maximum parsed shebang interpreter length (see: prepend_shebang_interpreter)
2327
MAXINTERP = 2048
2428

@@ -194,7 +198,7 @@ def getcommandpath(self, name, venv=True, cwd=None):
194198

195199
if path is None:
196200
raise tox.exception.InvocationError(
197-
"could not find executable {}".format(pipes.quote(name)),
201+
"could not find executable {}".format(shlex_quote(name)),
198202
)
199203

200204
return str(path) # will not be rewritten for reporting
@@ -534,7 +538,7 @@ def test(
534538
# happens if the same environment is invoked twice
535539
message = "commands[{}] | {}".format(
536540
i,
537-
" ".join(pipes.quote(str(x)) for x in argv),
541+
" ".join(shlex_quote(str(x)) for x in argv),
538542
)
539543
action.setactivity(name, message)
540544
# check to see if we need to ignore the return code

tests/unit/session/test_session.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import pipes
32
import sys
43
import textwrap
54
from threading import Thread
@@ -11,6 +10,11 @@
1110
from tox.package import resolve_package
1211
from tox.reporter import Verbosity
1312

13+
try:
14+
from shlex import quote as shlex_quote
15+
except ImportError:
16+
from pipes import quote as shlex_quote
17+
1418

1519
def test_resolve_pkg_missing_directory(tmpdir, mocksession):
1620
distshare = tmpdir.join("distshare")
@@ -355,7 +359,7 @@ def test_command_prev_fail_command_skip_post_run(cmd, initproj, mock_venv):
355359
___________________________________ summary ___________________________________{}
356360
ERROR: py: commands failed
357361
""".format(
358-
pipes.quote(sys.executable),
362+
shlex_quote(sys.executable),
359363
"_" if sys.platform != "win32" else "",
360364
),
361365
)

0 commit comments

Comments
 (0)