From 65ad66191463d310e0f19c7b5506b38a4a4cc0a8 Mon Sep 17 00:00:00 2001 From: Paul O'Leary McCann Date: Thu, 8 Sep 2022 12:57:28 +0900 Subject: [PATCH] Remove join_command Also fixes issue with run_commands on Windows. --- spacy/cli/project/dvc.py | 13 ++++++------- spacy/cli/project/run.py | 5 +++-- spacy/util.py | 10 ---------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/spacy/cli/project/dvc.py b/spacy/cli/project/dvc.py index 15c56a392..331ed182c 100644 --- a/spacy/cli/project/dvc.py +++ b/spacy/cli/project/dvc.py @@ -7,7 +7,7 @@ from wasabi import msg from .._util import PROJECT_FILE, load_project_config, get_hash, project_cli from .._util import Arg, Opt, NAME, COMMAND -from ...util import working_dir, join_command, run_command +from ...util import working_dir, run_command from ...util import SimpleFrozenList @@ -122,7 +122,7 @@ def update_dvc_config( if command.get("no_skip"): dvc_cmd.append("--always-changed") full_cmd = [*dvc_cmd, *deps_cmd, *outputs_cmd, *outputs_nc_cmd, *project_cmd] - dvc_commands.append(join_command(full_cmd)) + dvc_commands.append(full_cmd) with working_dir(path): dvc_flags = {"--verbose": verbose, "--quiet": silent} run_dvc_commands(dvc_commands, flags=dvc_flags) @@ -134,21 +134,20 @@ def update_dvc_config( def run_dvc_commands( - commands: Iterable[str] = SimpleFrozenList(), flags: Dict[str, bool] = {} + commands: Iterable[List[str]] = SimpleFrozenList(), flags: Dict[str, bool] = {} ) -> None: """Run a sequence of DVC commands in a subprocess, in order. - commands (List[str]): The string commands without the leading "dvc". + commands (List[List[str]]): The string commands without the leading "dvc". flags (Dict[str, bool]): Conditional flags to be added to command. Makes it easier to pass flags like --quiet that depend on a variable or command-line setting while avoiding lots of nested conditionals. """ for c in commands: - dvc_command = "dvc " + c + dvc_command = ["dvc", *c] # Add the flags if they are set to True for flag, is_active in flags.items(): - if is_active: - dvc_command += " " + flag + dvc_command.append(flag) run_command(dvc_command) diff --git a/spacy/cli/project/run.py b/spacy/cli/project/run.py index 4f27cef4d..ceddcf304 100644 --- a/spacy/cli/project/run.py +++ b/spacy/cli/project/run.py @@ -10,7 +10,7 @@ import typer from ... import about from ...git_info import GIT_VERSION from ...compat import is_windows -from ...util import working_dir, run_command, is_cwd, join_command +from ...util import working_dir, run_command, is_cwd from ...util import SimpleFrozenList, is_minor_version_match, ENV_VARS from ...util import check_bool_env_var, SimpleFrozenDict from .._util import PROJECT_FILE, PROJECT_LOCK, load_project_config, get_hash @@ -170,6 +170,7 @@ def run_commands( if is_windows: # On Windows we don't rewrite the command because there's no # reliable way to split and reassemble it + command = c if not silent: print(f"Running command: {c}") else: @@ -186,7 +187,7 @@ def run_commands( elif len(command) and command[0] in ("pip", "pip3"): command = [sys.executable, "-m", "pip", *command[1:]] if not silent: - print(f"Running command: {join_command(command)}") + print(f"Running command: {c}") if not dry: run_command(command, capture=capture) diff --git a/spacy/util.py b/spacy/util.py index ca069d88a..7e767bed6 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -936,16 +936,6 @@ def replace_model_node(model: Model, target: Model, replacement: Model) -> None: node.set_ref(ref_name, replacement) -def join_command(command: List[str]) -> str: - """Join a command using shlex. shlex.join is only available for Python 3.8+, - so we're using a workaround here. - - command (List[str]): The command to join. - RETURNS (str): The joined command - """ - return " ".join(shlex.quote(cmd) for cmd in command) - - def run_command( command: Union[str, List[str]], *,