Skip to content

Commit

Permalink
feat: add backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MaferMazu committed Aug 16, 2024
1 parent 9e035ec commit 4d3bf9f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def load_about():
packages=find_packages(exclude=["tests*"]),
include_package_data=True,
python_requires=">=3.8",
install_requires=["tutor", "importlib_resources"],
install_requires=["tutor", "importlib_resources", "packaging"],
extras_require={
"dev": [
"tutor[dev]",
Expand Down
37 changes: 30 additions & 7 deletions tutorpicasso/commands/enable_private_packages.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import subprocess

# Was necessary to use this for compatibility with Python 3.8
from typing import Any, Dict
from packaging.version import Version

import click
from tutor import config as tutor_config
Expand All @@ -21,25 +21,48 @@ def enable_private_packages() -> None:
"""
tutor_root = (
subprocess.check_output("tutor config printroot", shell=True)
.decode("utf-8")
.strip()
.decode("utf-8").strip()
)
tutor_version = (
subprocess.check_output("tutor --version", shell=True)
.decode("utf-8").strip()
).split()[-1]
tutor_version_obj = Version(tutor_version)
# Define Quince version as the method for installing private packages changes from this version
quince_version_obj = Version('v17.0.0')
# Use these specific paths as required by Tutor < Quince
private_requirements_root = f'{tutor_root}/env/build/openedx/requirements'
private_requirements_txt = f'{private_requirements_root}/private.txt'
config = tutor_config.load(tutor_root)
packages = get_picasso_packages(config)

# Create necessary files and directories if they don't exist
if not os.path.exists(private_requirements_root):
os.makedirs(private_requirements_root)
if not os.path.exists(private_requirements_txt) and tutor_version_obj < quince_version_obj:
with open(private_requirements_txt, 'w') as file:
file.write('')

for package, info in packages.items():
try:
if not {"name", "repo", "version"}.issubset(info):
raise KeyError(
f"{package} is missing one of the required keys: 'name', 'repo', 'version'"
)

if os.path.isdir(f'{tutor_root}/{info["name"]}'):
subprocess.call(["rm", "-rf", f'{tutor_root}/{info["name"]}'])
if os.path.isdir(f'{private_requirements_root}/{info["name"]}'):
subprocess.call(["rm", "-rf", f'{private_requirements_root}/{info["name"]}'])

subprocess.call(
["git", "clone", "-b", info["version"], info["repo"]], cwd=tutor_root
["git", "clone", "-b", info["version"], info["repo"]], cwd=private_requirements_root
)
subprocess.call(["tutor", "mounts", "add", f'{tutor_root}/{info["name"]}'])

if tutor_version_obj < quince_version_obj:
subprocess.call(
["echo", f'-e ./{info["name"]}', ">>", private_requirements_txt]
)
else:
subprocess.call(["tutor", "mounts", "add", f'{private_requirements_root}/{info["name"]}'])

except KeyError as e:
raise click.ClickException(str(e))
Expand Down

0 comments on commit 4d3bf9f

Please sign in to comment.