diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index 0214eca..92e86eb 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -56,7 +56,7 @@ jobs: - tutor plugins index add https://raw.githubusercontent.com/eduNEXT/tutor-plugin-indexes/picasso_test/ - tutor plugins install mfe mfe_extensions aspects - tutor plugins enable mfe mfe_extensions aspects - - tutor config save + - tutor plugins list | tutor config save EOF - name: Check run-extra-commands diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e002f50 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [v0.1.1] - 2024-09-25 + +### Fixed + +- Improve the commands output. + +## [v0.1.0] - 2024-09-06 + +### Added + +- Picasso commands in simple way. \ No newline at end of file diff --git a/tutorpicasso/__about__.py b/tutorpicasso/__about__.py index 3dc1f76..485f44a 100644 --- a/tutorpicasso/__about__.py +++ b/tutorpicasso/__about__.py @@ -1 +1 @@ -__version__ = "0.1.0" +__version__ = "0.1.1" diff --git a/tutorpicasso/commands/enable_private_packages.py b/tutorpicasso/commands/enable_private_packages.py index 64721c3..7e982f7 100644 --- a/tutorpicasso/commands/enable_private_packages.py +++ b/tutorpicasso/commands/enable_private_packages.py @@ -6,6 +6,8 @@ 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 +from tutor import fmt as tutor_fmt @click.command(name="enable-private-packages", help="Enable picasso private packages") @@ -35,14 +37,12 @@ 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) - subprocess.call( - ["git", "clone", "-b", info["version"], info["repo"]], - cwd=private_requirements_path, + tutor_utils.execute( + "git", "clone", "-b", info["version"], info["repo"], requirement_path ) handle_private_requirements_by_tutor_version(info, private_requirements_path) @@ -84,6 +84,7 @@ def _enable_private_requirements_before_quince( echo_command = f'echo "-e ./{info["name"]}/" >> {private_requirements_txt}' subprocess.call(echo_command, shell=True) + click.echo(tutor_fmt.command(echo_command)) def _enable_private_requirements_latest( @@ -96,13 +97,8 @@ 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. """ - subprocess.call( - [ - "tutor", - "mounts", - "add", - f'{private_requirements_path}/{info["name"]}', - ] + tutor_utils.execute( + "tutor", "mounts", "add", f'{private_requirements_path}/{info["name"]}' ) diff --git a/tutorpicasso/commands/enable_themes.py b/tutorpicasso/commands/enable_themes.py index a97e24f..a8969d3 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") @@ -25,16 +26,28 @@ def enable_themes() -> None: # because it comes from the Tutor framework. # We are not handle type errors related to this object. for theme in tutor_conf["PICASSO_THEMES"]: # type: ignore - if not {"name", "repo", "version"}.issubset(theme.keys()): # type: ignore + if not isinstance(theme, dict): + raise click.ClickException( + "Expected 'theme' to be a dictionary, but got something else." + ) + + if not {"name", "repo", "version"}.issubset(theme.keys()): raise click.ClickException( f"{theme} is missing one or more required keys: " "'name', 'repo', 'version'" ) - theme_path = f'{tutor_root}/env/build/openedx/themes/{theme["name"]}' # type: ignore + theme_path = f'{tutor_root}/env/build/openedx/themes/{theme["name"]}' if os.path.isdir(theme_path): subprocess.call(["rm", "-rf", theme_path]) - subprocess.call( - ["git", "clone", "-b", theme["version"], theme["repo"], theme_path], # type: ignore + theme_version = theme.get("version", "") + theme_repo = theme.get("repo", "") + tutor_utils.execute( + "git", + "clone", + "-b", + theme_version, + theme_repo, + theme_path, ) diff --git a/tutorpicasso/commands/run_extra_commands.py b/tutorpicasso/commands/run_extra_commands.py index 0e2c9ca..bd27007 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 utils as tutor_utils COMMAND_CHAINING_OPERATORS = ["&&", "&", "||", "|", ";"] @@ -80,24 +81,7 @@ def run_command(command: str) -> None: Args: command (str): Tutor command. """ - with subprocess.Popen( - command, - shell=True, - executable="/bin/bash", - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - text=True, - ) as process: - - stdout, stderr = process.communicate() - - if process.returncode != 0 or "error" in stderr.lower(): - raise click.ClickException( - f"Command '{command}' failed with return code {process.returncode}. Output: {stdout}. Error: {stderr}" - ) - - click.echo(stdout) + tutor_utils.execute("sh", "-c", command) def find_tutor_misspelled(command: str) -> bool: