diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 838e00369..fd5270c21 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -36,6 +36,7 @@ from spacy.training import Example, docs_to_json, offsets_to_biluo_tags from spacy.training.converters import conll_ner_to_docs, conllu_to_docs from spacy.training.converters import iob_to_docs from spacy.util import ENV_VARS, get_minor_version, load_model_from_config, load_config +from spacy.util import run_command from ..cli.init_pipeline import _init_labels from .util import make_tempdir @@ -855,3 +856,9 @@ def test_span_length_freq_dist_output_must_be_correct(): span_freqs = _get_spans_length_freq_dist(sample_span_lengths, threshold) assert sum(span_freqs.values()) >= threshold assert list(span_freqs.keys()) == [3, 1, 4, 5, 2] + + +def test_shell_quoting(): + # simple quoted shell commands should run on any platform + ret = run_command('bash -c "echo ok"') + assert ret.returncode == 0 diff --git a/spacy/util.py b/spacy/util.py index d170fc15b..a2ec63295 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -937,12 +937,12 @@ def replace_model_node(model: Model, target: Model, replacement: Model) -> None: def split_command(command: str) -> List[str]: - """Split a string command using shlex. Handles platform compatibility. + """Split a string command using shlex. command (str) : The command to split RETURNS (List[str]): The split command. """ - return shlex.split(command, posix=not is_windows) + return shlex.split(command, posix=True) def join_command(command: List[str]) -> str: @@ -981,8 +981,9 @@ def run_command( cmd_list = command cmd_str = " ".join(command) try: + cmd_to_run = cmd_str if is_windows else cmd_list ret = subprocess.run( - cmd_list, + cmd_to_run, env=os.environ.copy(), input=stdin, encoding="utf8",