diff --git a/tutorpicasso/commands/enable_private_packages.py b/tutorpicasso/commands/enable_private_packages.py index 77ee442..f62bfa3 100644 --- a/tutorpicasso/commands/enable_private_packages.py +++ b/tutorpicasso/commands/enable_private_packages.py @@ -6,6 +6,7 @@ from packaging.version import Version from tutor import config as tutor_config from tutor.__about__ import __version__ as tutor_version +from tutor import utils as tutor_utils @click.command(name="enable-private-packages", help="Enable picasso private packages") @@ -35,23 +36,14 @@ def enable_private_packages() -> None: f"{package} is missing one of the required keys: 'name', 'repo', 'version'" ) - if os.path.isdir(f'{private_requirements_path}/{info["name"]}'): - subprocess.call( - ["rm", "-rf", f'{private_requirements_path}/{info["name"]}'] - ) + requirement_path = f'{private_requirements_path}/{info["name"]}' + if os.path.isdir(requirement_path): + tutor_utils.execute("rm", "-rf", requirement_path) - process = subprocess.run( - ["git", "clone", "-b", info["version"], info["repo"]], - cwd=private_requirements_path, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - text=True, + tutor_utils.execute( + "git", "clone", "-b", info["version"], info["repo"], requirement_path ) - click.echo(process.stdout) - if process.stderr: - click.echo(process.stderr) - handle_private_requirements_by_tutor_version(info, private_requirements_path) @@ -89,20 +81,9 @@ def _enable_private_requirements_before_quince( with open(private_requirements_txt, "w") as file: file.write("") - echo_command = f'echo "-e ./{info["name"]}/" >> {private_requirements_txt}' - - process = subprocess.run( - echo_command, - shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - text=True, - ) + echo_command = f'echo "-e ./{info["name"]}/" >> {private_requirements_txt}'.split() - click.echo(process.stdout) - - if process.stderr: - click.echo(process.stderr) + tutor_utils.execute(*echo_command) def _enable_private_requirements_latest( @@ -115,23 +96,10 @@ def _enable_private_requirements_latest( info (Dict[str, str]): A dictionary containing metadata about the requirement. Expected to have a "name" key. private_requirements_path (str): The root directory where private requirements are stored. """ - process = subprocess.run( - [ - "tutor", - "mounts", - "add", - f'{private_requirements_path}/{info["name"]}', - ], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - text=True, + tutor_utils.execute( + "tutor", "mounts", "add", f'{private_requirements_path}/{info["name"]}' ) - click.echo(process.stdout) - - if process.stderr: - click.echo(process.stderr) - def get_picasso_packages(settings: Dict[str, Any]) -> Dict[str, Dict[str, Any]]: """ diff --git a/tutorpicasso/commands/enable_themes.py b/tutorpicasso/commands/enable_themes.py index a585bfb..4282993 100644 --- a/tutorpicasso/commands/enable_themes.py +++ b/tutorpicasso/commands/enable_themes.py @@ -4,6 +4,7 @@ import click from tutor import config as tutor_config +from tutor import utils as tutor_utils @click.command(name="enable-themes", help="Enable picasso themes") @@ -43,20 +44,11 @@ def enable_themes() -> None: theme_version = theme.get("version", "") theme_repo = theme.get("repo", "") - process = subprocess.run( - [ - "git", - "clone", - "-b", - str(theme_version), - str(theme_repo), - str(theme_path), - ], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - text=True, + tutor_utils.execute( + "git", + "clone", + "-b", + str(theme_version), + str(theme_repo), + str(theme_path), ) - - click.echo(process.stdout) - if process.stderr: - click.echo(process.stderr) diff --git a/tutorpicasso/commands/run_extra_commands.py b/tutorpicasso/commands/run_extra_commands.py index 0e2c9ca..04e7fe9 100644 --- a/tutorpicasso/commands/run_extra_commands.py +++ b/tutorpicasso/commands/run_extra_commands.py @@ -6,6 +6,7 @@ import click from tutor import config as tutor_config +from tutor import fmt as tutor_fmt COMMAND_CHAINING_OPERATORS = ["&&", "&", "||", "|", ";"] @@ -80,6 +81,7 @@ def run_command(command: str) -> None: Args: command (str): Tutor command. """ + click.echo(tutor_fmt.command(command)) with subprocess.Popen( command, shell=True,