Skip to content

Commit

Permalink
refactor: apply feedback and improve run_extra_commands
Browse files Browse the repository at this point in the history
s
  • Loading branch information
MaferMazu committed Sep 24, 2024
1 parent 0934700 commit ef7596c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 45 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
41 changes: 20 additions & 21 deletions tutorpicasso/commands/enable_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,29 @@ def enable_themes() -> None:
# We use `type: ignore` for the `tutor_conf` object
# 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
for theme in tutor_conf["PICASSO_THEMES"]:
if not isinstance(theme, dict):
raise click.ClickException(
"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,
)
26 changes: 4 additions & 22 deletions tutorpicasso/commands/run_extra_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["&&", "&", "||", "|", ";"]

Expand Down Expand Up @@ -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:
Expand All @@ -126,8 +108,8 @@ def create_regex_from_list(special_chars: List[str]) -> Pattern[str]:
Return:
A new compiled regex pattern that can be used for comparisons
"""
escaped_special_chars = list(map(re.escape, special_chars)) # type: ignore
regex_pattern = "|".join(escaped_special_chars) # type: ignore
escaped_special_chars = list(map(re.escape, special_chars))
regex_pattern = "|".join(escaped_special_chars)
return re.compile(regex_pattern)


Expand Down

0 comments on commit ef7596c

Please sign in to comment.