Skip to content

Commit

Permalink
fix: improve the commands output
Browse files Browse the repository at this point in the history
  • Loading branch information
MaferMazu committed Sep 23, 2024
1 parent 44a822e commit 1787fae
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 13 deletions.
35 changes: 31 additions & 4 deletions tutorpicasso/commands/enable_private_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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(
Expand All @@ -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]]:
"""
Expand Down
40 changes: 31 additions & 9 deletions tutorpicasso/commands/enable_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1787fae

Please sign in to comment.