From 0c12c42ffb6e36423906abe818b3f32fb28216ad Mon Sep 17 00:00:00 2001 From: rasswanth-s <43314053+rasswanth-s@users.noreply.github.com> Date: Mon, 9 Oct 2023 18:04:26 +0530 Subject: [PATCH 1/5] added url mapping in template --- packages/hagrid/hagrid/cli.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/hagrid/hagrid/cli.py b/packages/hagrid/hagrid/cli.py index 3d7a5b92044..9158e62917a 100644 --- a/packages/hagrid/hagrid/cli.py +++ b/packages/hagrid/hagrid/cli.py @@ -1358,23 +1358,30 @@ def create_launch_cmd( and parsed_kwargs["template"] is None and parsed_kwargs["tag"] not in ["local", "0.7.0"] ): + # third party + from packaging import version + # TODO: we need to redo this so that pypi and docker mappings are in a single # file inside dev if parsed_kwargs["tag"] == "latest": parsed_kwargs["template"] = LATEST_STABLE_SYFT parsed_kwargs["tag"] = LATEST_STABLE_SYFT elif parsed_kwargs["tag"] == "beta": - parsed_kwargs["template"] = "dev" + beta_version = version.parse(LATEST_BETA_SYFT) + parsed_kwargs[ + "template" + ] = f"https://github.com/OpenMined/PySyft/releases/download/v{str(beta_version)}/manifest.yml" parsed_kwargs["tag"] = LATEST_BETA_SYFT else: - template = parsed_kwargs["tag"] - # 🟡 TODO: Revert to use tags once, we have tag branches with beta - # versions also. - if "b" in template: - template = "dev" - # if template == "beta": - # template = "dev" - parsed_kwargs["template"] = template + tag = parsed_kwargs["tag"] + + if "b" in tag: + beta_version = version.parse(tag) + parsed_kwargs[ + "template" + ] = f"https://github.com/OpenMined/PySyft/releases/download/v{str(beta_version)}/manifest.yml" + else: + raise Exception(f"Not a valid beta version: {tag}") if host in ["docker"] and parsed_kwargs["template"] and host is not None: # Setup the files from the manifest_template.yml From 3bee6c9e179db896e8298641e8348c8a4e6c4df7 Mon Sep 17 00:00:00 2001 From: rasswanth-s <43314053+rasswanth-s@users.noreply.github.com> Date: Mon, 9 Oct 2023 18:26:01 +0530 Subject: [PATCH 2/5] updated url --- packages/hagrid/hagrid/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/hagrid/hagrid/cli.py b/packages/hagrid/hagrid/cli.py index 9158e62917a..6d089941a71 100644 --- a/packages/hagrid/hagrid/cli.py +++ b/packages/hagrid/hagrid/cli.py @@ -1370,7 +1370,7 @@ def create_launch_cmd( beta_version = version.parse(LATEST_BETA_SYFT) parsed_kwargs[ "template" - ] = f"https://github.com/OpenMined/PySyft/releases/download/v{str(beta_version)}/manifest.yml" + ] = f"https://github.com/OpenMined/PySyft/releases/download/v{str(beta_version)}/manifest_template.yml" parsed_kwargs["tag"] = LATEST_BETA_SYFT else: tag = parsed_kwargs["tag"] @@ -1379,7 +1379,7 @@ def create_launch_cmd( beta_version = version.parse(tag) parsed_kwargs[ "template" - ] = f"https://github.com/OpenMined/PySyft/releases/download/v{str(beta_version)}/manifest.yml" + ] = f"https://github.com/OpenMined/PySyft/releases/download/v{str(beta_version)}/manifest_template.yml" else: raise Exception(f"Not a valid beta version: {tag}") From 4d3c836fb24fa8c90d72016f180d108f132fba34 Mon Sep 17 00:00:00 2001 From: rasswanth-s <43314053+rasswanth-s@users.noreply.github.com> Date: Tue, 10 Oct 2023 07:59:02 +0530 Subject: [PATCH 3/5] improved exception handling at edge cases --- packages/hagrid/hagrid/cli.py | 46 +++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/packages/hagrid/hagrid/cli.py b/packages/hagrid/hagrid/cli.py index 6d089941a71..884abcf1a8a 100644 --- a/packages/hagrid/hagrid/cli.py +++ b/packages/hagrid/hagrid/cli.py @@ -1366,22 +1366,38 @@ def create_launch_cmd( if parsed_kwargs["tag"] == "latest": parsed_kwargs["template"] = LATEST_STABLE_SYFT parsed_kwargs["tag"] = LATEST_STABLE_SYFT - elif parsed_kwargs["tag"] == "beta": - beta_version = version.parse(LATEST_BETA_SYFT) - parsed_kwargs[ - "template" - ] = f"https://github.com/OpenMined/PySyft/releases/download/v{str(beta_version)}/manifest_template.yml" - parsed_kwargs["tag"] = LATEST_BETA_SYFT - else: - tag = parsed_kwargs["tag"] + elif parsed_kwargs["tag"] == "beta" or "b" in parsed_kwargs["tag"]: + tag = ( + LATEST_BETA_SYFT + if parsed_kwargs["tag"] == "beta" + else parsed_kwargs["tag"] + ) - if "b" in tag: - beta_version = version.parse(tag) - parsed_kwargs[ - "template" - ] = f"https://github.com/OpenMined/PySyft/releases/download/v{str(beta_version)}/manifest_template.yml" - else: - raise Exception(f"Not a valid beta version: {tag}") + # Currently, manifest_template.yml is only supported for beta versions >= 0.8.2b34 + beta_version = version.parse(tag) + MINIMUM_BETA_VERSION = "0.8.2b34" + if beta_version < version.parse(MINIMUM_BETA_VERSION): + raise Exception( + f"Minimum beta version tag supported is {MINIMUM_BETA_VERSION}" + ) + + # Check if the beta version is available + template_url = f"https://github.com/OpenMined/PySyft/releases/download/v{str(beta_version)}/manifest_template.yml" + response = requests.get(template_url) # nosec + if response.status_code != 200: + raise Exception( + f"Tag {parsed_kwargs['tag']} is not available" + + " \n for download. Please check the available tags at: " + + "\n https://github.com/OpenMined/PySyft/releases" + ) + + parsed_kwargs["template"] = template_url + parsed_kwargs["tag"] = tag + else: + raise Exception( + f"Not a valid tag: {parsed_kwargs['tag']}" + + "\nValid tags: latest, beta, beta version(ex: 0.8.2b35)" + ) if host in ["docker"] and parsed_kwargs["template"] and host is not None: # Setup the files from the manifest_template.yml From ffbd2e7388ea0177bbe91e9d122397b737a6d00b Mon Sep 17 00:00:00 2001 From: rasswanth-s <43314053+rasswanth-s@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:28:21 +0530 Subject: [PATCH 4/5] refactored version deployment --- packages/hagrid/hagrid/cli.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/hagrid/hagrid/cli.py b/packages/hagrid/hagrid/cli.py index 884abcf1a8a..4e8e15b2c93 100644 --- a/packages/hagrid/hagrid/cli.py +++ b/packages/hagrid/hagrid/cli.py @@ -130,8 +130,10 @@ def get_compose_src_path( **kwargs: TypeDict[str, Any], ) -> str: grid_path = GRID_SRC_PATH() - tag = kwargs.get("tag", None) - if EDITABLE_MODE and template_location is None or tag == "0.7.0": # type: ignore + tag = kwargs["tag"] + # Use local compose files if in editable mode and + # template_location is None and (tag is None or tag is local) + if EDITABLE_MODE and template_location is None and (tag is None or tag == "local"): # type: ignore path = grid_path else: path = deployment_dir(node_name) @@ -1356,11 +1358,24 @@ def create_launch_cmd( if ( parsed_kwargs["tag"] is not None and parsed_kwargs["template"] is None - and parsed_kwargs["tag"] not in ["local", "0.7.0"] + and parsed_kwargs["tag"] not in ["local"] ): # third party from packaging import version + pattern = r"[0-9].[0-9].[0-9]" + input_tag = parsed_kwargs["tag"] + if ( + not re.match(pattern, input_tag) + and input_tag != "latest" + and input_tag != "beta" + and "b" not in input_tag + ): + raise Exception( + f"Not a valid tag: {parsed_kwargs['tag']}" + + "\nValid tags: latest, beta, beta version(ex: 0.8.2b35),[0-9].[0-9].[0-9]" + ) + # TODO: we need to redo this so that pypi and docker mappings are in a single # file inside dev if parsed_kwargs["tag"] == "latest": @@ -1394,10 +1409,13 @@ def create_launch_cmd( parsed_kwargs["template"] = template_url parsed_kwargs["tag"] = tag else: - raise Exception( - f"Not a valid tag: {parsed_kwargs['tag']}" - + "\nValid tags: latest, beta, beta version(ex: 0.8.2b35)" - ) + MINIMUM_TAG_VERSION = version.parse("0.8.0") + tag = version.parse(parsed_kwargs["tag"]) + if tag < MINIMUM_TAG_VERSION: + raise Exception( + f"Minimum supported stable tag version is {MINIMUM_TAG_VERSION}" + ) + parsed_kwargs["template"] = parsed_kwargs["tag"] if host in ["docker"] and parsed_kwargs["template"] and host is not None: # Setup the files from the manifest_template.yml From 91bea9d857b0e873e4c8abdd58b77dcb7f7323a1 Mon Sep 17 00:00:00 2001 From: rasswanth-s <43314053+rasswanth-s@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:08:56 +0530 Subject: [PATCH 5/5] Added dev mode flag --- packages/hagrid/hagrid/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/hagrid/hagrid/cli.py b/packages/hagrid/hagrid/cli.py index 4e8e15b2c93..35852e6521f 100644 --- a/packages/hagrid/hagrid/cli.py +++ b/packages/hagrid/hagrid/cli.py @@ -132,8 +132,8 @@ def get_compose_src_path( grid_path = GRID_SRC_PATH() tag = kwargs["tag"] # Use local compose files if in editable mode and - # template_location is None and (tag is None or tag is local) - if EDITABLE_MODE and template_location is None and (tag is None or tag == "local"): # type: ignore + # template_location is None and (kwargs["dev"] is True or tag is local) + if EDITABLE_MODE and template_location is None and (kwargs["dev"] is True or tag == "local"): # type: ignore path = grid_path else: path = deployment_dir(node_name)