From fc3b113abe169d0a4abc994d8de4c947dfd8a9a6 Mon Sep 17 00:00:00 2001 From: Andres Espinel Date: Fri, 15 Mar 2024 00:59:19 -0500 Subject: [PATCH] feat: added private packages compatibility for quince --- .../commands/enable_private_packages.py | 26 +++++++++++++++++++ ...dx-dev-dockerfile-post-python-requirements | 21 --------------- 2 files changed, 26 insertions(+), 21 deletions(-) delete mode 100644 tutordistro/patches/openedx-dev-dockerfile-post-python-requirements diff --git a/tutordistro/commands/enable_private_packages.py b/tutordistro/commands/enable_private_packages.py index 4383e59..82dc295 100644 --- a/tutordistro/commands/enable_private_packages.py +++ b/tutordistro/commands/enable_private_packages.py @@ -5,6 +5,7 @@ import subprocess import click + from tutor import config as tutor_config from tutordistro.distro.packages.application.package_cloner import PackageCloner @@ -26,6 +27,9 @@ def enable_private_packages(): """ directory = subprocess.check_output("tutor config printroot", shell=True).\ decode("utf-8").strip() + plugin_directory = directory + "/tutor-contrib-edunext-distro/tutordistro/plugin.py" + print('hi') + print(plugin_directory) config = tutor_config.load(directory) repository = PackageGitRepository() @@ -49,5 +53,27 @@ def enable_private_packages(): ) definer(name=package["name"], file_path=f"{requirements_directory}private.txt") + + # Run tutor mounts add command for the package + subprocess.check_output(f"tutor mounts add {requirements_directory}{package['name']}", shell=True) + text = f'hooks.Filters.MOUNTED_DIRECTORIES.add_item(("openedx", "{package["name"]}"))' + + append_text_to_file(file_path=plugin_directory, text_to_append=text) + subprocess.check_output("tutor config save", shell=True) except Exception as error: # pylint: disable=broad-exception-caught click.echo(error) + + +def append_text_to_file(file_path, text_to_append): + + with open(file_path, 'a+') as my_file: # Open file in append and read mode + + my_file.seek(0) # Move the cursor to the beginning of the file + existing_lines = my_file.readlines() + package_name = text_to_append.split('"')[3] # Extract package name from text_to_append + + # Check if package name already exists in the file + if any(package_name in line for line in existing_lines): + print(f"Package '{package_name}' already present in the file.") + else: + my_file.write(text_to_append + "\n") diff --git a/tutordistro/patches/openedx-dev-dockerfile-post-python-requirements b/tutordistro/patches/openedx-dev-dockerfile-post-python-requirements deleted file mode 100644 index fe07ae9..0000000 --- a/tutordistro/patches/openedx-dev-dockerfile-post-python-requirements +++ /dev/null @@ -1,21 +0,0 @@ -{%- for pkg in iter_values_named(suffix="_DPKG") %} -{%- if loop.first -%} -RUN mkdir -p /openedx/extra_deps/ -{% endif %} -{%- if pkg != 'None' -%} -{%- if pkg["private"] == false %} -# Install {{ pkg["name"] }} -{%- endif %} -{%+ if pkg["index"] and pkg["index"] == "pip" -%} -RUN pip install {{ pkg["name"] }}=={{ pkg["version"] }} -{%- elif not pkg["private"] -%} -RUN mkdir -p /openedx/extra_deps/{{ pkg["name"] }} && \ - git clone -b {{ pkg["version"] }} {{ pkg["protocol"] }}://{{ pkg["domain"] }}/{{ pkg["path"] }}/{{ pkg["repo"] }}.git /openedx/extra_deps/{{ pkg["name"] }} -RUN pip install -e /openedx/extra_deps/{{ pkg["name"] }} -{%- elif pkg["private"] -%} -RUN mv /openedx/requirements/{{ pkg["name"] }} /openedx/extra_deps/{{ pkg["name"] }} -RUN pip install -e /openedx/extra_deps/{{ pkg["name"] }} -{%- endif -%} -{%- endif -%} -{% endfor %} -