Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve the commands output #8

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
MaferMazu marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

- Improve the commands output.

## [v0.1.0]

### Added

- Picasso commands in simple way.
2 changes: 1 addition & 1 deletion tutorpicasso/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
24 changes: 10 additions & 14 deletions tutorpicasso/commands/enable_private_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
BryanttV marked this conversation as resolved.
Show resolved Hide resolved
)

handle_private_requirements_by_tutor_version(info, private_requirements_path)
Expand Down Expand Up @@ -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(
Expand All @@ -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"]}'
)


Expand Down
34 changes: 24 additions & 10 deletions tutorpicasso/commands/enable_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -25,16 +26,29 @@ 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])

subprocess.call(
["git", "clone", "-b", theme["version"], theme["repo"], theme_path], # type: ignore
)
else:
MaferMazu marked this conversation as resolved.
Show resolved Hide resolved
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),
MaferMazu marked this conversation as resolved.
Show resolved Hide resolved
)
2 changes: 2 additions & 0 deletions tutorpicasso/commands/run_extra_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import click
from tutor import config as tutor_config
from tutor import fmt as tutor_fmt

COMMAND_CHAINING_OPERATORS = ["&&", "&", "||", "|", ";"]

Expand Down Expand Up @@ -80,6 +81,7 @@ def run_command(command: str) -> None:
Args:
command (str): Tutor command.
"""
click.echo(tutor_fmt.command(command))
Copy link
Contributor

@mariajgrimaldi mariajgrimaldi Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want this to be a blocker since the design of running multiple commands is out of the scope of this PR, so please, don't consider it one.

Why can't we use tutor_utils.execute instead of directly calling subprocess.Popen? It will save us a lot of trouble since we won't have to handle errors or echo the command info manually.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but it makes the chained elements weird.

For example:
Using: tutor_utils.execute(*command.split()) it returns:
tutor plugins update '|' tutor plugins index add https://raw.githubusercontent.com/eduNEXT/tutor-plugin-indexes/picasso_test/
To make it possible to allow chained elements, we would need to add shell=True in https://github.com/overhangio/tutor/blob/master/tutor/utils.py#L216

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a way:
Using: tutor_utils.execute('sh', '-c', command)
The only thing that is not so good about this is that every command will have a sh -c prefix:
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this solution. Having the sh -c prefix is not good looking but improves the readability of the code and doesn't bother a lot in the logs.

If you have more feedback about this, please let me know.

Copy link
Contributor

@mariajgrimaldi mariajgrimaldi Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks significantly better and gives even more information for debugging purposes. I tested it and it's working as expected. Thank you!

with subprocess.Popen(
command,
shell=True,
Expand Down
Loading