Skip to content

Commit c28feb4

Browse files
committed
Update shell_utils.py
1 parent 7c2be8e commit c28feb4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

codeflash/code_utils/shell_utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
from __future__ import annotations
2+
13
import os
24
import re
35
from pathlib import Path
4-
from typing import Optional
6+
from typing import TYPE_CHECKING, Optional
57

68
from codeflash.code_utils.compat import LF
7-
from codeflash.either import Failure, Result, Success
9+
from codeflash.either import Failure, Success
10+
11+
if TYPE_CHECKING:
12+
from codeflash.either import Result
813

914
if os.name == "nt": # Windows
1015
SHELL_RC_EXPORT_PATTERN = re.compile(r"^set CODEFLASH_API_KEY=(cf-.*)$", re.MULTILINE)
@@ -17,7 +22,7 @@
1722
def read_api_key_from_shell_config() -> Optional[str]:
1823
try:
1924
shell_rc_path = get_shell_rc_path()
20-
with open(shell_rc_path, encoding="utf8") as shell_rc:
25+
with shell_rc_path.open(encoding="utf8") as shell_rc:
2126
shell_contents = shell_rc.read()
2227
matches = SHELL_RC_EXPORT_PATTERN.findall(shell_contents)
2328
return matches[-1] if matches else None
@@ -40,11 +45,11 @@ def get_api_key_export_line(api_key: str) -> str:
4045
return f"{SHELL_RC_EXPORT_PREFIX}{api_key}"
4146

4247

43-
def save_api_key_to_rc(api_key) -> Result[str, str]:
48+
def save_api_key_to_rc(api_key: str) -> Result[str, str]:
4449
shell_rc_path = get_shell_rc_path()
4550
api_key_line = get_api_key_export_line(api_key)
4651
try:
47-
with open(shell_rc_path, "r+", encoding="utf8") as shell_file:
52+
with shell_rc_path.open("r+", encoding="utf8") as shell_file:
4853
shell_contents = shell_file.read()
4954
if os.name == "nt" and not shell_contents: # on windows we're writing to a batch file
5055
shell_contents = "@echo off"

0 commit comments

Comments
 (0)