Remove join_command

Also fixes issue with run_commands on Windows.
This commit is contained in:
Paul O'Leary McCann 2022-09-08 12:57:28 +09:00
parent 0f1d97d87d
commit 65ad661914
3 changed files with 9 additions and 19 deletions

View File

@ -7,7 +7,7 @@ from wasabi import msg
from .._util import PROJECT_FILE, load_project_config, get_hash, project_cli from .._util import PROJECT_FILE, load_project_config, get_hash, project_cli
from .._util import Arg, Opt, NAME, COMMAND 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 from ...util import SimpleFrozenList
@ -122,7 +122,7 @@ def update_dvc_config(
if command.get("no_skip"): if command.get("no_skip"):
dvc_cmd.append("--always-changed") dvc_cmd.append("--always-changed")
full_cmd = [*dvc_cmd, *deps_cmd, *outputs_cmd, *outputs_nc_cmd, *project_cmd] 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): with working_dir(path):
dvc_flags = {"--verbose": verbose, "--quiet": silent} dvc_flags = {"--verbose": verbose, "--quiet": silent}
run_dvc_commands(dvc_commands, flags=dvc_flags) run_dvc_commands(dvc_commands, flags=dvc_flags)
@ -134,21 +134,20 @@ def update_dvc_config(
def run_dvc_commands( def run_dvc_commands(
commands: Iterable[str] = SimpleFrozenList(), flags: Dict[str, bool] = {} commands: Iterable[List[str]] = SimpleFrozenList(), flags: Dict[str, bool] = {}
) -> None: ) -> None:
"""Run a sequence of DVC commands in a subprocess, in order. """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 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 easier to pass flags like --quiet that depend on a variable or
command-line setting while avoiding lots of nested conditionals. command-line setting while avoiding lots of nested conditionals.
""" """
for c in commands: for c in commands:
dvc_command = "dvc " + c dvc_command = ["dvc", *c]
# Add the flags if they are set to True # Add the flags if they are set to True
for flag, is_active in flags.items(): for flag, is_active in flags.items():
if is_active: dvc_command.append(flag)
dvc_command += " " + flag
run_command(dvc_command) run_command(dvc_command)

View File

@ -10,7 +10,7 @@ import typer
from ... import about from ... import about
from ...git_info import GIT_VERSION from ...git_info import GIT_VERSION
from ...compat import is_windows 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 SimpleFrozenList, is_minor_version_match, ENV_VARS
from ...util import check_bool_env_var, SimpleFrozenDict from ...util import check_bool_env_var, SimpleFrozenDict
from .._util import PROJECT_FILE, PROJECT_LOCK, load_project_config, get_hash from .._util import PROJECT_FILE, PROJECT_LOCK, load_project_config, get_hash
@ -170,6 +170,7 @@ def run_commands(
if is_windows: if is_windows:
# On Windows we don't rewrite the command because there's no # On Windows we don't rewrite the command because there's no
# reliable way to split and reassemble it # reliable way to split and reassemble it
command = c
if not silent: if not silent:
print(f"Running command: {c}") print(f"Running command: {c}")
else: else:
@ -186,7 +187,7 @@ def run_commands(
elif len(command) and command[0] in ("pip", "pip3"): elif len(command) and command[0] in ("pip", "pip3"):
command = [sys.executable, "-m", "pip", *command[1:]] command = [sys.executable, "-m", "pip", *command[1:]]
if not silent: if not silent:
print(f"Running command: {join_command(command)}") print(f"Running command: {c}")
if not dry: if not dry:
run_command(command, capture=capture) run_command(command, capture=capture)

View File

@ -936,16 +936,6 @@ def replace_model_node(model: Model, target: Model, replacement: Model) -> None:
node.set_ref(ref_name, replacement) 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( def run_command(
command: Union[str, List[str]], command: Union[str, List[str]],
*, *,