|
3 | 3 | from argparse import SUPPRESS, ArgumentParser, Namespace |
4 | 4 | from pathlib import Path |
5 | 5 |
|
6 | | -import git |
7 | | - |
8 | 6 | from codeflash.cli_cmds import logging_config |
9 | 7 | from codeflash.cli_cmds.cli_common import apologize_and_exit |
10 | 8 | from codeflash.cli_cmds.cmd_init import init_codeflash, install_github_actions |
11 | 9 | from codeflash.cli_cmds.console import logger |
12 | 10 | from codeflash.code_utils import env_utils |
13 | 11 | from codeflash.code_utils.config_parser import parse_config_file |
14 | | -from codeflash.code_utils.git_utils import ( |
15 | | - check_and_push_branch, |
16 | | - check_running_in_git_repo, |
17 | | - confirm_proceeding_with_no_git_repo, |
18 | | - get_repo_owner_and_name, |
19 | | -) |
20 | | -from codeflash.code_utils.github_utils import get_github_secrets_page_url, require_github_app_or_exit |
21 | 12 | from codeflash.version import __version__ as version |
22 | 13 |
|
23 | 14 |
|
@@ -75,6 +66,13 @@ def parse_args() -> Namespace: |
75 | 66 |
|
76 | 67 |
|
77 | 68 | def process_and_validate_cmd_args(args: Namespace) -> Namespace: |
| 69 | + from codeflash.code_utils.git_utils import ( |
| 70 | + check_running_in_git_repo, |
| 71 | + confirm_proceeding_with_no_git_repo, |
| 72 | + get_repo_owner_and_name, |
| 73 | + ) |
| 74 | + from codeflash.code_utils.github_utils import require_github_app_or_exit |
| 75 | + |
78 | 76 | is_init: bool = args.command.startswith("init") if args.command else False |
79 | 77 | if args.verbose: |
80 | 78 | logging_config.set_level(logging.DEBUG, echo_setting=not is_init) |
@@ -144,21 +142,26 @@ def process_pyproject_config(args: Namespace) -> Namespace: |
144 | 142 | assert Path(args.benchmarks_root).resolve().is_relative_to(Path(args.tests_root).resolve()), ( |
145 | 143 | f"--benchmarks-root {args.benchmarks_root} must be a subdirectory of --tests-root {args.tests_root}" |
146 | 144 | ) |
147 | | - if env_utils.get_pr_number() is not None: |
148 | | - assert env_utils.ensure_codeflash_api_key(), ( |
149 | | - "Codeflash API key not found. When running in a Github Actions Context, provide the " |
150 | | - "'CODEFLASH_API_KEY' environment variable as a secret.\n" |
151 | | - "You can add a secret by going to your repository's settings page, then clicking 'Secrets' in the left sidebar.\n" |
152 | | - "Then, click 'New repository secret' and add your api key with the variable name CODEFLASH_API_KEY.\n" |
153 | | - f"Here's a direct link: {get_github_secrets_page_url()}\n" |
154 | | - "Exiting..." |
155 | | - ) |
| 145 | + if env_utils.get_pr_number() is not None: |
| 146 | + import git |
| 147 | + |
| 148 | + from codeflash.code_utils.git_utils import get_repo_owner_and_name |
| 149 | + from codeflash.code_utils.github_utils import get_github_secrets_page_url, require_github_app_or_exit |
| 150 | + |
| 151 | + assert env_utils.ensure_codeflash_api_key(), ( |
| 152 | + "Codeflash API key not found. When running in a Github Actions Context, provide the " |
| 153 | + "'CODEFLASH_API_KEY' environment variable as a secret.\n" |
| 154 | + "You can add a secret by going to your repository's settings page, then clicking 'Secrets' in the left sidebar.\n" |
| 155 | + "Then, click 'New repository secret' and add your api key with the variable name CODEFLASH_API_KEY.\n" |
| 156 | + f"Here's a direct link: {get_github_secrets_page_url()}\n" |
| 157 | + "Exiting..." |
| 158 | + ) |
156 | 159 |
|
157 | | - repo = git.Repo(search_parent_directories=True) |
| 160 | + repo = git.Repo(search_parent_directories=True) |
158 | 161 |
|
159 | | - owner, repo_name = get_repo_owner_and_name(repo) |
| 162 | + owner, repo_name = get_repo_owner_and_name(repo) |
160 | 163 |
|
161 | | - require_github_app_or_exit(owner, repo_name) |
| 164 | + require_github_app_or_exit(owner, repo_name) |
162 | 165 |
|
163 | 166 | if hasattr(args, "ignore_paths") and args.ignore_paths is not None: |
164 | 167 | normalized_ignore_paths = [] |
@@ -187,6 +190,11 @@ def project_root_from_module_root(module_root: Path, pyproject_file_path: Path) |
187 | 190 |
|
188 | 191 | def handle_optimize_all_arg_parsing(args: Namespace) -> Namespace: |
189 | 192 | if hasattr(args, "all"): |
| 193 | + import git |
| 194 | + |
| 195 | + from codeflash.code_utils.git_utils import check_and_push_branch, get_repo_owner_and_name |
| 196 | + from codeflash.code_utils.github_utils import require_github_app_or_exit |
| 197 | + |
190 | 198 | # Ensure that the user can actually open PRs on the repo. |
191 | 199 | try: |
192 | 200 | git_repo = git.Repo(search_parent_directories=True) |
|
0 commit comments