Skip to content

Commit 3a7a7cf

Browse files
committed
Avoid importing pipes on Python 3.3+
1 parent c3a9856 commit 3a7a7cf

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
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+
if sys.version_info >= (3, 3):
21+
from shlex import quote as shlex_quote
22+
else:
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/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
from .parallel import add_parallel_config, add_parallel_flags
4545
from .reporter import add_verbosity_commands
4646

47-
try:
47+
if sys.version_info >= (3, 3):
4848
from shlex import quote as shlex_quote
49-
except ImportError:
49+
else:
5050
from pipes import quote as shlex_quote
5151

5252

src/tox/exception.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import os
2-
import pipes
32
import signal
3+
import sys
4+
5+
if sys.version_info >= (3, 3):
6+
from shlex import quote as shlex_quote
7+
else:
8+
from pipes import quote as shlex_quote
49

510

611
def exit_code_str(exception_name, command, exit_code):
@@ -96,7 +101,7 @@ def __init__(self, config):
96101
self.config = config
97102

98103
def __str__(self):
99-
return " ".join(pipes.quote(i) for i in self.config.requires)
104+
return " ".join(shlex_quote(i) for i in self.config.requires)
100105

101106

102107
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+
if sys.version_info >= (3, 3):
22+
from shlex import quote as shlex_quote
23+
else:
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+
if sys.version_info >= (3, 3):
14+
from shlex import quote as shlex_quote
15+
else:
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)