From 5d8dc5bd9e1c3f96dc4ed531d5cdb2c71d6556cd Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Mon, 26 Aug 2024 16:06:57 -0500 Subject: [PATCH] refactor: improve the naming in enable_private_packages --- .../commands/enable_private_packages.py | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/tutorpicasso/commands/enable_private_packages.py b/tutorpicasso/commands/enable_private_packages.py index 63ff042..dcc55bf 100644 --- a/tutorpicasso/commands/enable_private_packages.py +++ b/tutorpicasso/commands/enable_private_packages.py @@ -23,11 +23,11 @@ def enable_private_packages() -> None: tutor_root = context.root tutor_conf = tutor_config.load(tutor_root) - private_requirements_root = f"{tutor_root}/env/build/openedx/private_requirements" + private_requirements_path = f"{tutor_root}/env/build/openedx/requirements" packages = get_picasso_packages(tutor_conf) - if not os.path.exists(private_requirements_root): - os.makedirs(private_requirements_root) + if not os.path.exists(private_requirements_path): + os.makedirs(private_requirements_path) for package, info in packages.items(): if not {"name", "repo", "version"}.issubset(info): @@ -35,46 +35,48 @@ def enable_private_packages() -> None: f"{package} is missing one of the required keys: 'name', 'repo', 'version'" ) - if os.path.isdir(f'{private_requirements_root}/{info["name"]}'): + if os.path.isdir(f'{private_requirements_path}/{info["name"]}'): subprocess.call( - ["rm", "-rf", f'{private_requirements_root}/{info["name"]}'] + ["rm", "-rf", f'{private_requirements_path}/{info["name"]}'] ) subprocess.call( ["git", "clone", "-b", info["version"], info["repo"]], - cwd=private_requirements_root, + cwd=private_requirements_path, ) - handle_private_requirements_by_tutor_version(info, private_requirements_root) + handle_private_requirements_by_tutor_version(info, private_requirements_path) -def handle_private_requirements_by_tutor_version(info: Dict[str, str], private_requirements_path: str) -> None: +def handle_private_requirements_by_tutor_version( + info: Dict[str, str], private_requirements_path: str +) -> None: """ Handle the private requirements based on the Tutor version. Args: - info (Dict[str, str]): A dictionary containing metadata about the package. Expected to have a "name" key. - private_requirements_path (str): The directory path to store the private packages. + info (Dict[str, str]): A dictionary containing metadata about the requirement. Expected to have a "name" key. + private_requirements_path (str): The directory path to store the private requirements. """ tutor_version_obj = Version(tutor_version) quince_version_obj = Version("v17.0.0") if tutor_version_obj < quince_version_obj: private_txt_path = f"{private_requirements_path}/private.txt" - _enable_private_packages_before_quince(info, private_txt_path) + _enable_private_requirements_before_quince(info, private_txt_path) else: - _enable_private_packages_latest(info, private_requirements_path) + _enable_private_requirements_latest(info, private_requirements_path) -def _enable_private_packages_before_quince( +def _enable_private_requirements_before_quince( info: Dict[str, str], private_requirements_txt: str ) -> None: """ - Copy the package name in the private.txt file to ensure that packages are added in the build process for Tutor versions < Quince. + Copy the requirement name in the private.txt file to ensure that requirements are added in the build process for Tutor versions < Quince. Args: - info (Dict[str, str]): A dictionary containing metadata about the package. Expected to have a "name" key. - private_requirements_txt (str): The file path to `private.txt`, which stores the list of private packages to be included in the build. + info (Dict[str, str]): A dictionary containing metadata about the requirement. Expected to have a "name" key. + private_requirements_txt (str): The file path to `private.txt`, which stores the list of private requirements to be included in the build. """ if not os.path.exists(private_requirements_txt): with open(private_requirements_txt, "w") as file: @@ -84,22 +86,22 @@ def _enable_private_packages_before_quince( subprocess.call(echo_command, shell=True) -def _enable_private_packages_latest( - info: Dict[str, str], private_requirements_root: str +def _enable_private_requirements_latest( + info: Dict[str, str], private_requirements_path: str ) -> None: """ - Use the tutor mounts method to ensure that packages are added in the build process. + Use the tutor mounts method to ensure that requirements are added in the build process. Args: - info (Dict[str, str]): A dictionary containing metadata about the package. Expected to have a "name" key. - private_requirements_root (str): The root directory where private packages are stored. + 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_root}/{info["name"]}', + f'{private_requirements_path}/{info["name"]}', ] )