Skip to content

Commit f484ff0

Browse files
committed
reduce duplication
1 parent ffbb167 commit f484ff0

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from codeflash.cli_cmds.console import console, logger
2323
from codeflash.code_utils.compat import LF
2424
from codeflash.code_utils.config_parser import parse_config_file
25-
from codeflash.code_utils.env_utils import get_codeflash_api_key
25+
from codeflash.code_utils.env_utils import check_formatter_installed, get_codeflash_api_key
2626
from codeflash.code_utils.git_utils import get_git_remotes, get_repo_owner_and_name
2727
from codeflash.code_utils.github_utils import get_github_secrets_page_url
2828
from codeflash.code_utils.shell_utils import get_shell_rc_path, save_api_key_to_rc
@@ -239,7 +239,7 @@ def collect_setup_info() -> SetupInfo:
239239
else:
240240
apologize_and_exit()
241241
else:
242-
tests_root = Path(curdir) / Path(cast(str, tests_root_answer))
242+
tests_root = Path(curdir) / Path(cast("str", tests_root_answer))
243243
tests_root = tests_root.relative_to(curdir)
244244
ph("cli-tests-root-provided")
245245

@@ -302,7 +302,7 @@ def collect_setup_info() -> SetupInfo:
302302
elif benchmarks_answer == no_benchmarks_option:
303303
benchmarks_root = None
304304
else:
305-
benchmarks_root = tests_root / Path(cast(str, benchmarks_answer))
305+
benchmarks_root = tests_root / Path(cast("str", benchmarks_answer))
306306

307307
# TODO: Implement other benchmark framework options
308308
# if benchmarks_root:
@@ -354,9 +354,9 @@ def collect_setup_info() -> SetupInfo:
354354
module_root=str(module_root),
355355
tests_root=str(tests_root),
356356
benchmarks_root=str(benchmarks_root) if benchmarks_root else None,
357-
test_framework=cast(str, test_framework),
357+
test_framework=cast("str", test_framework),
358358
ignore_paths=ignore_paths,
359-
formatter=cast(str, formatter),
359+
formatter=cast("str", formatter),
360360
git_remote=str(git_remote),
361361
)
362362

@@ -466,7 +466,7 @@ def check_for_toml_or_setup_file() -> str | None:
466466
click.echo("⏩️ Skipping pyproject.toml creation.")
467467
apologize_and_exit()
468468
click.echo()
469-
return cast(str, project_name)
469+
return cast("str", project_name)
470470

471471

472472
def install_github_actions(override_formatter_check: bool = False) -> None:
@@ -717,11 +717,7 @@ def configure_pyproject_toml(setup_info: SetupInfo) -> None:
717717
)
718718
elif formatter == "don't use a formatter":
719719
formatter_cmds.append("disabled")
720-
if formatter in ["black", "ruff"]:
721-
try:
722-
subprocess.run([formatter], capture_output=True, check=False)
723-
except (FileNotFoundError, NotADirectoryError):
724-
click.echo(f"⚠️ Formatter not found: {formatter}, please ensure it is installed")
720+
check_formatter_installed(formatter_cmds)
725721
codeflash_section["formatter-cmds"] = formatter_cmds
726722
# Add the 'codeflash' section, ensuring 'tool' section exists
727723
tool_section = pyproject_data.get("tool", tomlkit.table())

0 commit comments

Comments
 (0)