-
Notifications
You must be signed in to change notification settings - Fork 0
Pyproject #10
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
Merged
Pyproject #10
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fd2b8be
add support for pyproject.toml parsing
malmans2 480ca90
cleanup
malmans2 9c4f19f
allow default branch
malmans2 d4689be
fix var name
malmans2 a98687c
add warning
malmans2 b2a8dcf
qa
malmans2 d958779
fix action
malmans2 9ae5340
cleanup
malmans2 66bd665
update README
malmans2 fb64fd8
only add repo-list from pyproject
malmans2 c87c3a9
avoid duplicates
malmans2 678c99a
fix README
malmans2 a8c188e
no default branch
malmans2 bf534ea
rename
malmans2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,13 @@ | |
| # ] | ||
| # /// | ||
|
|
||
| import os | ||
| import logging | ||
| import os | ||
| import shutil | ||
| from typing import Annotated | ||
|
|
||
| import git | ||
| import tomllib | ||
| import typer | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
@@ -24,7 +26,8 @@ def git_clone_repo( | |
| repo_ref: str, | ||
| multi_options: tuple[str, ...] = ("--depth=1", "--recurse-submodules"), | ||
| ) -> str: | ||
| multi_options += (f"--branch {repo_ref}",) | ||
| if repo_ref: | ||
| multi_options += (f"--branch {repo_ref}",) | ||
|
|
||
| if os.path.exists(repo_path): | ||
| logger.info(f"removing {repo_path!r}") | ||
|
|
@@ -44,7 +47,10 @@ def git_clone_repos( | |
| git_pat: str, | ||
| default_repo_ref: str, | ||
| ) -> None: | ||
| for repo_path in paths: | ||
| if not paths: | ||
| logger.warning("No repository to clone.") | ||
|
|
||
| for repo_path in set(paths): | ||
| repo_name = os.path.basename(repo_path) | ||
| repo_org = os.path.basename(os.path.dirname(repo_path)) | ||
| git_pat_org = os.getenv(f"GIT_PAT_{repo_org.upper()}", git_pat) | ||
|
|
@@ -68,17 +74,32 @@ def git_clone_repos( | |
|
|
||
| @app.command() | ||
| def main( | ||
| github_repos: list[str] = typer.Argument(..., help="GitHub repositories to clone"), | ||
| git_pat: str = typer.Option( | ||
| default="", envvar="GIT_PAT", help="GitHub Personal Access Token" | ||
| ), | ||
| default_repo_ref: str = typer.Option( | ||
| default="main", help="Default Git reference to check out" | ||
| ), | ||
| repo_list: Annotated[ | ||
|
Member
Author
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. I changed the script variable name for consistency with the action. But should not have impact has it's an argument variable |
||
| list[str], | ||
| typer.Argument(help="GitHub repositories to clone."), | ||
| ] = [], | ||
| git_pat: Annotated[ | ||
| str, | ||
| typer.Option(envvar="GIT_PAT", help="GitHub Personal Access Token."), | ||
| ] = "", | ||
| default_repo_ref: Annotated[ | ||
| str, | ||
| typer.Option(help="Default Git reference to check out."), | ||
| ] = "", | ||
| pyproject_path: Annotated[ | ||
| str | None, | ||
| typer.Option(help="Path to the pyproject.toml file."), | ||
| ] = None, | ||
| ): | ||
| if pyproject_path: | ||
| with open(pyproject_path, "rb") as fp: | ||
| pyproject = tomllib.load(fp) | ||
| config = pyproject.get("tool", {}).get("git-clone", {}) | ||
| repo_list.extend(config.get("repo-list", [])) | ||
|
|
||
| logging.basicConfig(level=logging.INFO) | ||
| git_clone_repos( | ||
| github_repos, | ||
| repo_list, | ||
| "https://{credentials}github.com/{repo_org}/{repo_name}.git", | ||
| git_pat, | ||
| default_repo_ref, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This allows to rely on the default repo branch instead of hardcoding main as default. There's some repos that use different default branches, and others such as cdsapi use master