Skip to content

Commit c1dffc5

Browse files
authoredMay 28, 2024··
On Python 3.3+, replace pipes.quote with shlex.quote (#342)
* On Python 3.3+, replace pipes.quote with shlex.quote The pipes.quote() function was undocumented, and the pipes module was deprecated in Python 3.11 and will be removed in Python 3.13. Fixes #341. * Choose shlex or pipes based on Python version It was pointed out that pyupgrade can handle this better than try/except.
1 parent de428ee commit c1dffc5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed
 

‎nodeenv.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
import argparse
2424
import subprocess
2525
import tarfile
26-
import pipes
26+
if sys.version_info < (3, 3):
27+
from pipes import quote as _quote
28+
else:
29+
from shlex import quote as _quote
2730
import platform
2831
import zipfile
2932
import shutil
@@ -733,7 +736,7 @@ def build_node_from_src(env_dir, src_dir, node_src_dir, args):
733736

734737
conf_cmd = [
735738
'./configure',
736-
'--prefix=%s' % pipes.quote(env_dir)
739+
'--prefix=%s' % _quote(env_dir)
737740
]
738741
if args.without_ssl:
739742
conf_cmd.append('--without-ssl')
@@ -815,7 +818,7 @@ def install_npm(env_dir, _src_dir, args):
815818
(
816819
'bash', '-c',
817820
'. {0} && npm install -g npm@{1}'.format(
818-
pipes.quote(join(env_dir, 'bin', 'activate')),
821+
_quote(join(env_dir, 'bin', 'activate')),
819822
args.npm,
820823
)
821824
),
@@ -883,10 +886,10 @@ def install_packages(env_dir, args):
883886
activate_path = join(env_dir, 'bin', 'activate')
884887
real_npm_ver = args.npm if args.npm.count(".") == 2 else args.npm + ".0"
885888
if args.npm == "latest" or real_npm_ver >= "1.0.0":
886-
cmd = '. ' + pipes.quote(activate_path) + \
889+
cmd = '. ' + _quote(activate_path) + \
887890
' && npm install -g %(pack)s'
888891
else:
889-
cmd = '. ' + pipes.quote(activate_path) + \
892+
cmd = '. ' + _quote(activate_path) + \
890893
' && npm install %(pack)s' + \
891894
' && npm activate %(pack)s'
892895

‎tests/nodeenv_test.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
from __future__ import unicode_literals
33

44
import os.path
5-
import pipes
5+
if sys.version_info < (3, 3):
6+
from pipes import quote as _quote
7+
else:
8+
from shlex import quote as _quote
69
import subprocess
710
import sys
811
import sysconfig
@@ -29,7 +32,7 @@ def test_smoke(tmpdir):
2932
'-m', 'nodeenv', '--prebuilt', nenv_path,
3033
])
3134
assert os.path.exists(nenv_path)
32-
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
35+
activate = _quote(os.path.join(nenv_path, 'bin', 'activate'))
3336
subprocess.check_call([
3437
'sh', '-c', '. {} && node --version'.format(activate),
3538
])
@@ -44,7 +47,7 @@ def test_smoke_n_system_special_chars(tmpdir):
4447
'-m', 'nodeenv', '-n', 'system', nenv_path,
4548
))
4649
assert os.path.exists(nenv_path)
47-
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
50+
activate = _quote(os.path.join(nenv_path, 'bin', 'activate'))
4851
subprocess.check_call([
4952
'sh', '-c', '. {} && node --version'.format(activate),
5053
])

0 commit comments

Comments
 (0)
Please sign in to comment.