-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates to pyflyte init templating #1665
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import os | ||
import shutil | ||
from dataclasses import replace | ||
from typing import Optional | ||
|
||
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 +66,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") | ||
Comment on lines
+95
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about we use a |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,6 @@ | |
"docstring-parser>=0.9.0", | ||
"diskcache>=5.2.1", | ||
"cloudpickle>=2.0.0", | ||
"cookiecutter>=1.7.3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
"numpy", | ||
"gitpython", | ||
"kubernetes>=12.0.1", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can pass the branch name directly in the call to
Repo.clone_from
.