Skip to content

Commit eba8cb8

Browse files
committed
move to env utils, pre-commit
1 parent e5e1ff0 commit eba8cb8

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

codeflash/code_utils/env_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,18 @@ def is_ci() -> bool:
121121
@lru_cache(maxsize=1)
122122
def is_LSP_enabled() -> bool:
123123
return console.quiet
124+
125+
126+
def is_pr_draft() -> bool:
127+
"""Check if the PR is draft. in the github action context."""
128+
try:
129+
event_path = os.getenv("GITHUB_EVENT_PATH")
130+
pr_number = get_pr_number()
131+
if pr_number is not None and event_path:
132+
with Path(event_path).open() as f:
133+
event_data = json.load(f)
134+
return bool(event_data["pull_request"]["draft"])
135+
return False # noqa
136+
except Exception as e:
137+
logger.warning(f"Error checking if PR is draft: {e}")
138+
return False

codeflash/optimization/optimizer.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import ast
4-
import json
54
import os
65
import tempfile
76
import time
@@ -13,7 +12,7 @@
1312
from codeflash.cli_cmds.console import console, logger, progress_bar
1413
from codeflash.code_utils import env_utils
1514
from codeflash.code_utils.code_utils import cleanup_paths, get_run_tmp_file
16-
from codeflash.code_utils.env_utils import get_pr_number
15+
from codeflash.code_utils.env_utils import get_pr_number, is_pr_draft
1716
from codeflash.either import is_successful
1817
from codeflash.models.models import ValidCode
1918
from codeflash.telemetry.posthog_cf import ph
@@ -64,7 +63,6 @@ def run_benchmarks(
6463
from codeflash.benchmarking.replay_test import generate_replay_test
6564
from codeflash.benchmarking.trace_benchmarks import trace_benchmarks_pytest
6665
from codeflash.benchmarking.utils import print_benchmark_table, validate_and_format_benchmark_table
67-
from codeflash.code_utils.env_utils import get_pr_number
6866

6967
with progress_bar(
7068
f"Running benchmarks in {self.args.benchmarks_root}", transient=True, revert_to_print=bool(get_pr_number())
@@ -394,18 +392,3 @@ def run_with_args(args: Namespace) -> None:
394392
optimizer.cleanup_temporary_paths()
395393

396394
raise SystemExit from None
397-
398-
399-
def is_pr_draft() -> bool:
400-
"""Check if the PR is draft. in the github action context."""
401-
try:
402-
event_path = os.getenv("GITHUB_EVENT_PATH")
403-
pr_number = get_pr_number()
404-
if pr_number is not None and event_path:
405-
with Path(event_path).open() as f:
406-
event_data = json.load(f)
407-
return bool(event_data["pull_request"]["draft"])
408-
return False # noqa
409-
except Exception as e:
410-
logger.warning(f"Error checking if PR is draft: {e}")
411-
return False

0 commit comments

Comments
 (0)