From 1787faeef9b5b1248156cd8ce5dac4de93fad3e1 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Mon, 23 Sep 2024 16:27:29 -0500 Subject: [PATCH 1/5] fix: improve the commands output --- .../commands/enable_private_packages.py | 35 ++++++++++++++-- tutorpicasso/commands/enable_themes.py | 40 ++++++++++++++----- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/tutorpicasso/commands/enable_private_packages.py b/tutorpicasso/commands/enable_private_packages.py index 64721c3..77ee442 100644 --- a/tutorpicasso/commands/enable_private_packages.py +++ b/tutorpicasso/commands/enable_private_packages.py @@ -40,11 +40,18 @@ def enable_private_packages() -> None: ["rm", "-rf", f'{private_requirements_path}/{info["name"]}'] ) - subprocess.call( + process = subprocess.run( ["git", "clone", "-b", info["version"], info["repo"]], cwd=private_requirements_path, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, ) + click.echo(process.stdout) + if process.stderr: + click.echo(process.stderr) + handle_private_requirements_by_tutor_version(info, private_requirements_path) @@ -83,7 +90,19 @@ def _enable_private_requirements_before_quince( file.write("") echo_command = f'echo "-e ./{info["name"]}/" >> {private_requirements_txt}' - subprocess.call(echo_command, shell=True) + + process = subprocess.run( + echo_command, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + + click.echo(process.stdout) + + if process.stderr: + click.echo(process.stderr) def _enable_private_requirements_latest( @@ -96,15 +115,23 @@ 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( + process = subprocess.run( [ "tutor", "mounts", "add", f'{private_requirements_path}/{info["name"]}', - ] + ], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, ) + 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 a97e24f..a585bfb 100644 --- a/tutorpicasso/commands/enable_themes.py +++ b/tutorpicasso/commands/enable_themes.py @@ -25,16 +25,38 @@ 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( - f"{theme} is missing one or more required keys: " - "'name', 'repo', 'version'" + "Expected 'theme' to be a dictionary, but got something else." ) - theme_path = f'{tutor_root}/env/build/openedx/themes/{theme["name"]}' # type: ignore - if os.path.isdir(theme_path): - subprocess.call(["rm", "-rf", theme_path]) + 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"]}' + if os.path.isdir(theme_path): + subprocess.call(["rm", "-rf", theme_path]) + + 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, + ) - subprocess.call( - ["git", "clone", "-b", theme["version"], theme["repo"], theme_path], # type: ignore - ) + click.echo(process.stdout) + if process.stderr: + click.echo(process.stderr) From 5c5e1efd3b1fe252bfc782e88c9b14e179c9f2de Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Mon, 23 Sep 2024 17:25:12 -0500 Subject: [PATCH 2/5] docs: bumpversion to 0.1.1 --- CHANGELOG.md | 18 ++++++++++++++++++ tutorpicasso/__about__.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9a2e58c --- /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] + +### Fixed + +- Improve the commands output. + +## [v0.1.0] + +### 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" From 093470099c2db6ff8e108009827b7f3b5b5ba923 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Mon, 23 Sep 2024 18:59:42 -0500 Subject: [PATCH 3/5] refactor: use tutor utils to execute and print --- .../commands/enable_private_packages.py | 53 ++++--------------- tutorpicasso/commands/enable_themes.py | 24 +++------ tutorpicasso/commands/run_extra_commands.py | 2 + 3 files changed, 21 insertions(+), 58 deletions(-) diff --git a/tutorpicasso/commands/enable_private_packages.py b/tutorpicasso/commands/enable_private_packages.py index 77ee442..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,23 +37,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) @@ -90,19 +83,8 @@ def _enable_private_requirements_before_quince( 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, - ) - - click.echo(process.stdout) - - if process.stderr: - click.echo(process.stderr) + subprocess.call(echo_command, shell=True) + click.echo(tutor_fmt.command(echo_command)) def _enable_private_requirements_latest( @@ -115,23 +97,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, From 0d46c8d13b0654491565c49e19213c0bcbb08a25 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Tue, 24 Sep 2024 14:52:22 -0500 Subject: [PATCH 4/5] refactor: apply feedback and improve run_extra_commands s --- CHANGELOG.md | 4 +-- tutorpicasso/commands/enable_themes.py | 39 ++++++++++----------- tutorpicasso/commands/run_extra_commands.py | 22 ++---------- 3 files changed, 23 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a2e58c..e002f50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,13 @@ 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] +## [v0.1.1] - 2024-09-25 ### Fixed - Improve the commands output. -## [v0.1.0] +## [v0.1.0] - 2024-09-06 ### Added diff --git a/tutorpicasso/commands/enable_themes.py b/tutorpicasso/commands/enable_themes.py index 4282993..a8969d3 100644 --- a/tutorpicasso/commands/enable_themes.py +++ b/tutorpicasso/commands/enable_themes.py @@ -31,24 +31,23 @@ def enable_themes() -> None: "Expected 'theme' to be a dictionary, but got something else." ) - 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"]}' - if os.path.isdir(theme_path): - subprocess.call(["rm", "-rf", theme_path]) - - theme_version = theme.get("version", "") - theme_repo = theme.get("repo", "") - tutor_utils.execute( - "git", - "clone", - "-b", - str(theme_version), - str(theme_repo), - str(theme_path), + 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"]}' + if os.path.isdir(theme_path): + subprocess.call(["rm", "-rf", theme_path]) + + 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 04e7fe9..bd27007 100644 --- a/tutorpicasso/commands/run_extra_commands.py +++ b/tutorpicasso/commands/run_extra_commands.py @@ -6,7 +6,7 @@ import click from tutor import config as tutor_config -from tutor import fmt as tutor_fmt +from tutor import utils as tutor_utils COMMAND_CHAINING_OPERATORS = ["&&", "&", "||", "|", ";"] @@ -81,25 +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, - 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: From 867378053bf2cb5677d02ec2b8f816e082e1e637 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Tue, 24 Sep 2024 18:44:17 -0500 Subject: [PATCH 5/5] test: add chained command --- .github/workflows/integration_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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