Skip to content

Commit

Permalink
On Python 3.3+, replace pipes.quote with shlex.quote
Browse files Browse the repository at this point in the history
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 ekalinin#341.
  • Loading branch information
musicinmybrain committed Oct 23, 2023
1 parent eaa9de9 commit d20e14f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 8 additions & 5 deletions nodeenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import argparse
import subprocess
import tarfile
import pipes
try:
from shlex import quote as _quote # Python 3.3+
except ImportError:
from pipes import quote as _quote # Python 2.7
import platform
import zipfile
import shutil
Expand Down Expand Up @@ -728,7 +731,7 @@ def build_node_from_src(env_dir, src_dir, node_src_dir, args):

conf_cmd = [
'./configure',
'--prefix=%s' % pipes.quote(env_dir)
'--prefix=%s' % _quote(env_dir)
]
if args.without_ssl:
conf_cmd.append('--without-ssl')
Expand Down Expand Up @@ -810,7 +813,7 @@ def install_npm(env_dir, _src_dir, args):
(
'bash', '-c',
'. {0} && npm install -g npm@{1}'.format(
pipes.quote(join(env_dir, 'bin', 'activate')),
_quote(join(env_dir, 'bin', 'activate')),
args.npm,
)
),
Expand Down Expand Up @@ -878,10 +881,10 @@ def install_packages(env_dir, args):
activate_path = join(env_dir, 'bin', 'activate')
real_npm_ver = args.npm if args.npm.count(".") == 2 else args.npm + ".0"
if args.npm == "latest" or real_npm_ver >= "1.0.0":
cmd = '. ' + pipes.quote(activate_path) + \
cmd = '. ' + _quote(activate_path) + \
' && npm install -g %(pack)s'
else:
cmd = '. ' + pipes.quote(activate_path) + \
cmd = '. ' + _quote(activate_path) + \
' && npm install %(pack)s' + \
' && npm activate %(pack)s'

Expand Down
9 changes: 6 additions & 3 deletions tests/nodeenv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from __future__ import unicode_literals

import os.path
import pipes
try:
from shlex import quote as _quote # Python 3.3+
except ImportError:
from pipes import quote as _quote # Python 2.7
import subprocess
import sys
import sysconfig
Expand All @@ -29,7 +32,7 @@ def test_smoke(tmpdir):
'-m', 'nodeenv', '--prebuilt', nenv_path,
])
assert os.path.exists(nenv_path)
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
activate = _quote(os.path.join(nenv_path, 'bin', 'activate'))
subprocess.check_call([
'sh', '-c', '. {} && node --version'.format(activate),
])
Expand All @@ -44,7 +47,7 @@ def test_smoke_n_system_special_chars(tmpdir):
'-m', 'nodeenv', '-n', 'system', nenv_path,
))
assert os.path.exists(nenv_path)
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
activate = _quote(os.path.join(nenv_path, 'bin', 'activate'))
subprocess.check_call([
'sh', '-c', '. {} && node --version'.format(activate),
])
Expand Down

0 comments on commit d20e14f

Please sign in to comment.