From 0aa1cf4b4ff38f2eab3d0ae7cf07ef3379550f1a Mon Sep 17 00:00:00 2001 From: zeryx <1892175+zeryx@users.noreply.github.com> Date: Tue, 30 May 2023 13:41:59 -0400 Subject: [PATCH 1/3] replaced cookiecutter with gitPython Signed-off-by: zeryx <1892175+zeryx@users.noreply.github.com> --- flytekit/clis/sdk_in_container/helpers.py | 33 +++++++++++++++++++++++ flytekit/clis/sdk_in_container/init.py | 29 ++++++++++---------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/flytekit/clis/sdk_in_container/helpers.py b/flytekit/clis/sdk_in_container/helpers.py index 4c66a2046c..cc296640d7 100644 --- a/flytekit/clis/sdk_in_container/helpers.py +++ b/flytekit/clis/sdk_in_container/helpers.py @@ -1,7 +1,9 @@ from dataclasses import replace from typing import Optional +import shutil, os import rich_click as click +from git import Repo from flytekit.clis.sdk_in_container.constants import CTX_CONFIG_FILE from flytekit.configuration import Config, ImageConfig, get_config_file @@ -63,3 +65,34 @@ def patch_image_config(config_file: Optional[str], image_config: ImageConfig) -> if addl.name not in additional_image_names: new_additional_images.append(addl) return replace(image_config, default_image=new_default, images=new_additional_images) + + +def clone_and_copy_repo_dir(git_url, branch, src_dir, dest_dir): + """ + Clones a git repository, checks out to a specific branch, and copies a specified directory into a local directory. + + Parameters: + - github_url: The URL of the GitHub repository. + - branch: The branch of the repository. + - src_dir: The directory in the repository to copy. + - dest_dir: The local directory to copy into. + """ + # Clone the repo + repo = Repo.clone_from(git_url, 'temp_repo') + + # Checkout to the branch + repo.git.checkout(branch) + + # Define the source directory path + src_path = os.path.join('temp_repo', src_dir) + + # Check if source directory exists + if not os.path.exists(src_path): + print(f"Template named {src_dir} does not exist in the repository.") + return + + # Copy the files from the source directory to the destination directory + shutil.copytree(src_path, dest_dir) + + # Remove the temporary cloned repo + shutil.rmtree('temp_repo') \ No newline at end of file diff --git a/flytekit/clis/sdk_in_container/init.py b/flytekit/clis/sdk_in_container/init.py index 627b393578..001197b68a 100644 --- a/flytekit/clis/sdk_in_container/init.py +++ b/flytekit/clis/sdk_in_container/init.py @@ -1,5 +1,5 @@ import rich_click as click -from cookiecutter.main import cookiecutter +from flytekit.clis.sdk_in_container.helpers import clone_and_copy_repo_dir @click.command("init") @@ -8,8 +8,18 @@ default="simple-example", help="cookiecutter template folder name to be used in the repo - https://github.com/flyteorg/flytekit-python-template.git", ) +@click.option( + "--repository-url", + default="https://github.com/flyteorg/flytekit-python-template.git", + help="template repository url pointing to a git repository containing flytekit templates." +) +@click.option( + "--repository-branch", + default="main", + help="template repository branch to be used." +) @click.argument("project-name") -def init(template, project_name): +def init(template, repository_url, repository_branch, project_name): """ Create flyte-ready projects. """ @@ -18,19 +28,8 @@ def init(template, project_name): "app": "flyte", "workflow": "my_wf", } - cookiecutter( - "https://github.com/flyteorg/flytekit-python-template.git", - checkout="main", - no_input=True, - # We do not want to clobber existing files/directories. - overwrite_if_exists=False, - extra_context=config, - # By specifying directory we can have multiple templates in the same repository, - # as described in https://cookiecutter.readthedocs.io/en/1.7.2/advanced/directories.html. - # The idea is to extend the number of templates, each in their own subdirectory, for example - # a tensorflow-based example. - directory=template, - ) + + clone_and_copy_repo_dir(repository_url, repository_branch, template, project_name) click.echo( f"Visit the {project_name} directory and follow the next steps in the Getting started guide (https://docs.flyte.org/en/latest/getting_started.html) to proceed." From b986379dd6f526ffe44ff3fc95eb4a18293e1ea4 Mon Sep 17 00:00:00 2001 From: zeryx <1892175+zeryx@users.noreply.github.com> Date: Tue, 30 May 2023 13:43:25 -0400 Subject: [PATCH 2/3] removal of cookiecutter from setup.py dependencies Signed-off-by: zeryx <1892175+zeryx@users.noreply.github.com> --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 5273590d9f..118ab14335 100644 --- a/setup.py +++ b/setup.py @@ -68,7 +68,6 @@ "docstring-parser>=0.9.0", "diskcache>=5.2.1", "cloudpickle>=2.0.0", - "cookiecutter>=1.7.3", "numpy", "gitpython", "kubernetes>=12.0.1", From 2caed9895c3cc016fa1180fe11ad9b2cc6327f89 Mon Sep 17 00:00:00 2001 From: zeryx <1892175+zeryx@users.noreply.github.com> Date: Tue, 30 May 2023 14:31:37 -0400 Subject: [PATCH 3/3] corrected linting errors Signed-off-by: zeryx <1892175+zeryx@users.noreply.github.com> --- flytekit/clis/sdk_in_container/helpers.py | 9 +++++---- flytekit/clis/sdk_in_container/init.py | 14 +++----------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/flytekit/clis/sdk_in_container/helpers.py b/flytekit/clis/sdk_in_container/helpers.py index cc296640d7..62a8d02edb 100644 --- a/flytekit/clis/sdk_in_container/helpers.py +++ b/flytekit/clis/sdk_in_container/helpers.py @@ -1,6 +1,7 @@ +import os +import shutil from dataclasses import replace from typing import Optional -import shutil, os import rich_click as click from git import Repo @@ -78,13 +79,13 @@ def clone_and_copy_repo_dir(git_url, branch, src_dir, dest_dir): - dest_dir: The local directory to copy into. """ # Clone the repo - repo = Repo.clone_from(git_url, 'temp_repo') + repo = Repo.clone_from(git_url, "temp_repo") # Checkout to the branch repo.git.checkout(branch) # Define the source directory path - src_path = os.path.join('temp_repo', src_dir) + src_path = os.path.join("temp_repo", src_dir) # Check if source directory exists if not os.path.exists(src_path): @@ -95,4 +96,4 @@ def clone_and_copy_repo_dir(git_url, branch, src_dir, dest_dir): shutil.copytree(src_path, dest_dir) # Remove the temporary cloned repo - shutil.rmtree('temp_repo') \ No newline at end of file + shutil.rmtree("temp_repo") diff --git a/flytekit/clis/sdk_in_container/init.py b/flytekit/clis/sdk_in_container/init.py index 001197b68a..a52e1741ce 100644 --- a/flytekit/clis/sdk_in_container/init.py +++ b/flytekit/clis/sdk_in_container/init.py @@ -1,4 +1,5 @@ import rich_click as click + from flytekit.clis.sdk_in_container.helpers import clone_and_copy_repo_dir @@ -11,23 +12,14 @@ @click.option( "--repository-url", default="https://github.com/flyteorg/flytekit-python-template.git", - help="template repository url pointing to a git repository containing flytekit templates." -) -@click.option( - "--repository-branch", - default="main", - help="template repository branch to be used." + help="template repository url pointing to a git repository containing flytekit templates.", ) +@click.option("--repository-branch", default="main", help="template repository branch to be used.") @click.argument("project-name") def init(template, repository_url, repository_branch, project_name): """ Create flyte-ready projects. """ - config = { - "project_name": project_name, - "app": "flyte", - "workflow": "my_wf", - } clone_and_copy_repo_dir(repository_url, repository_branch, template, project_name)