Skip to content

Commit 0a9abba

Browse files
committed
backport shlex.join to older Pythons
1 parent d31a9e0 commit 0a9abba

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

ipyparallel/cluster/launcher.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from traitlets import Unicode
4848
from traitlets.config.configurable import LoggingConfigurable
4949

50+
from ..util import shlex_join
5051
from ._win32support import forward_read_events
5152
from ._winhpcjob import IPControllerJob
5253
from ._winhpcjob import IPControllerTask
@@ -705,14 +706,14 @@ def sshx(ssh_cmd, cmd, remote_output_file, log=None):
705706
706707
Uses nohup and pipes to put it in the background
707708
"""
708-
remote_cmd = shlex.join(cmd)
709+
remote_cmd = shlex_join(cmd)
709710

710711
full_remote_cmd = [
711712
f"nohup {remote_cmd} > {remote_output_file} 2>&1 </dev/null & echo __remote_pid=$!__"
712713
]
713714
full_cmd = ssh_cmd + full_remote_cmd
714715
if log:
715-
log.info(f"Running `{shlex.join(full_cmd)}`")
716+
log.info(f"Running `{shlex_join(full_cmd)}`")
716717
out = check_output(full_cmd, input=None).decode("utf8", "replace")
717718
values = _ssh_outputs(out)
718719
if 'remote_pid' in values:
@@ -886,7 +887,7 @@ def get_output(self, remove=False):
886887
+ [
887888
self.location,
888889
"--",
889-
shlex.join(["rm", "-f", self.remote_output_file]),
890+
shlex_join(["rm", "-f", self.remote_output_file]),
890891
],
891892
input=None,
892893
)
@@ -1518,9 +1519,9 @@ def _context_default(self):
15181519

15191520
@observe("program", "program_args")
15201521
def _program_changed(self, change=None):
1521-
self.context['program'] = shlex.join(self.program)
1522-
self.context['program_args'] = shlex.join(self.program_args)
1523-
self.context['program_and_args'] = shlex.join(self.program + self.program_args)
1522+
self.context['program'] = shlex_join(self.program)
1523+
self.context['program_args'] = shlex_join(self.program_args)
1524+
self.context['program_and_args'] = shlex_join(self.program + self.program_args)
15241525

15251526
@observe("n", "queue")
15261527
def _update_context(self, change):

ipyparallel/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import os
77
import re
8+
import shlex
89
import socket
910
import stat
1011
import sys
@@ -696,3 +697,8 @@ def _locate_profiles(profiles=None):
696697
ProfileDir.find_profile_dir_by_name(ipython_dir, name=profile).location
697698
for profile in profiles
698699
]
700+
701+
702+
def shlex_join(cmd):
703+
"""Backport shlex.join to Python < 3.8"""
704+
return ' '.join(shlex.quote(s) for s in cmd)

0 commit comments

Comments
 (0)