Add capture argument to project_run (#6878)

* add capture argument to project_run and run_commands

* git bump to 3.0.1

* Set version to 3.0.1.dev0

Co-authored-by: Matthew Honnibal <honnibal+gh@gmail.com>
This commit is contained in:
Sofie Van Landeghem 2021-02-02 03:11:15 +01:00 committed by GitHub
parent f638306598
commit f319d2765f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 5 deletions

View File

@ -1,6 +1,6 @@
# fmt: off # fmt: off
__title__ = "spacy" __title__ = "spacy"
__version__ = "3.0.0" __version__ = "3.0.1.dev0"
__download_url__ = "https://github.com/explosion/spacy-models/releases/download" __download_url__ = "https://github.com/explosion/spacy-models/releases/download"
__compatibility__ = "https://raw.githubusercontent.com/explosion/spacy-models/master/compatibility.json" __compatibility__ = "https://raw.githubusercontent.com/explosion/spacy-models/master/compatibility.json"
__projects__ = "https://github.com/explosion/projects" __projects__ = "https://github.com/explosion/projects"

View File

@ -37,7 +37,12 @@ def project_run_cli(
def project_run( def project_run(
project_dir: Path, subcommand: str, *, force: bool = False, dry: bool = False project_dir: Path,
subcommand: str,
*,
force: bool = False,
dry: bool = False,
capture: bool = False,
) -> None: ) -> None:
"""Run a named script defined in the project.yml. If the script is part """Run a named script defined in the project.yml. If the script is part
of the default pipeline (defined in the "run" section), DVC is used to of the default pipeline (defined in the "run" section), DVC is used to
@ -48,6 +53,11 @@ def project_run(
subcommand (str): Name of command to run. subcommand (str): Name of command to run.
force (bool): Force re-running, even if nothing changed. force (bool): Force re-running, even if nothing changed.
dry (bool): Perform a dry run and don't execute commands. dry (bool): Perform a dry run and don't execute commands.
capture (bool): Whether to capture the output and errors of individual commands.
If False, the stdout and stderr will not be redirected, and if there's an error,
sys.exit will be called with the return code. You should use capture=False
when you want to turn over execution to the command, and capture=True
when you want to run the command more like a function.
""" """
config = load_project_config(project_dir) config = load_project_config(project_dir)
commands = {cmd["name"]: cmd for cmd in config.get("commands", [])} commands = {cmd["name"]: cmd for cmd in config.get("commands", [])}
@ -72,7 +82,7 @@ def project_run(
if not rerun and not force: if not rerun and not force:
msg.info(f"Skipping '{cmd['name']}': nothing changed") msg.info(f"Skipping '{cmd['name']}': nothing changed")
else: else:
run_commands(cmd["script"], dry=dry) run_commands(cmd["script"], dry=dry, capture=capture)
if not dry: if not dry:
update_lockfile(current_dir, cmd) update_lockfile(current_dir, cmd)
@ -126,12 +136,18 @@ def run_commands(
commands: Iterable[str] = SimpleFrozenList(), commands: Iterable[str] = SimpleFrozenList(),
silent: bool = False, silent: bool = False,
dry: bool = False, dry: bool = False,
capture: bool = False,
) -> None: ) -> None:
"""Run a sequence of commands in a subprocess, in order. """Run a sequence of commands in a subprocess, in order.
commands (List[str]): The string commands. commands (List[str]): The string commands.
silent (bool): Don't print the commands. silent (bool): Don't print the commands.
dry (bool): Perform a dry run and don't execut anything. dry (bool): Perform a dry run and don't execut anything.
capture (bool): Whether to capture the output and errors of individual commands.
If False, the stdout and stderr will not be redirected, and if there's an error,
sys.exit will be called with the return code. You should use capture=False
when you want to turn over execution to the command, and capture=True
when you want to run the command more like a function.
""" """
for command in commands: for command in commands:
command = split_command(command) command = split_command(command)
@ -149,7 +165,7 @@ def run_commands(
if not silent: if not silent:
print(f"Running command: {join_command(command)}") print(f"Running command: {join_command(command)}")
if not dry: if not dry:
run_command(command, capture=False) run_command(command, capture=capture)
def validate_subcommand( def validate_subcommand(

View File

@ -803,7 +803,7 @@ def run_command(
stdin (Optional[Any]): stdin to read from or None. stdin (Optional[Any]): stdin to read from or None.
capture (bool): Whether to capture the output and errors. If False, capture (bool): Whether to capture the output and errors. If False,
the stdout and stderr will not be redirected, and if there's an error, the stdout and stderr will not be redirected, and if there's an error,
sys.exit will be called with the returncode. You should use capture=False sys.exit will be called with the return code. You should use capture=False
when you want to turn over execution to the command, and capture=True when you want to turn over execution to the command, and capture=True
when you want to run the command more like a function. when you want to run the command more like a function.
RETURNS (Optional[CompletedProcess]): The process object. RETURNS (Optional[CompletedProcess]): The process object.