Skip to content

Commit

Permalink
On Python 3.3+, replace pipes.quote with shlex.quote (#342)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
musicinmybrain committed May 28, 2024
1 parent de428ee commit c1dffc5
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
if sys.version_info < (3, 3):
from pipes import quote as _quote
else:
from shlex import quote as _quote
import platform
import zipfile
import shutil
Expand Down Expand Up @@ -733,7 +736,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 @@ -815,7 +818,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 @@ -883,10 +886,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
if sys.version_info < (3, 3):
from pipes import quote as _quote
else:
from shlex import quote as _quote
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 c1dffc5

Please sign in to comment.