1- from __future__ import annotations
2-
31import os
42import re
53from pathlib import Path
6- from typing import TYPE_CHECKING , Optional
4+ from typing import Optional
75
86from codeflash .code_utils .compat import LF
9- from codeflash .either import Failure , Success
10-
11- if TYPE_CHECKING :
12- from codeflash .either import Result
7+ from codeflash .either import Failure , Result , Success
138
149if os .name == "nt" : # Windows
1510 SHELL_RC_EXPORT_PATTERN = re .compile (r"^set CODEFLASH_API_KEY=(cf-.*)$" , re .MULTILINE )
2217def read_api_key_from_shell_config () -> Optional [str ]:
2318 try :
2419 shell_rc_path = get_shell_rc_path ()
25- with shell_rc_path . open (encoding = "utf8" ) as shell_rc :
20+ with open (shell_rc_path , encoding = "utf8" ) as shell_rc :
2621 shell_contents = shell_rc .read ()
2722 matches = SHELL_RC_EXPORT_PATTERN .findall (shell_contents )
2823 return matches [- 1 ] if matches else None
@@ -45,11 +40,11 @@ def get_api_key_export_line(api_key: str) -> str:
4540 return f"{ SHELL_RC_EXPORT_PREFIX } { api_key } "
4641
4742
48- def save_api_key_to_rc (api_key : str ) -> Result [str , str ]:
43+ def save_api_key_to_rc (api_key ) -> Result [str , str ]:
4944 shell_rc_path = get_shell_rc_path ()
5045 api_key_line = get_api_key_export_line (api_key )
5146 try :
52- with shell_rc_path . open ("r+" , encoding = "utf8" ) as shell_file :
47+ with open (shell_rc_path , "r+" , encoding = "utf8" ) as shell_file :
5348 shell_contents = shell_file .read ()
5449 if os .name == "nt" and not shell_contents : # on windows we're writing to a batch file
5550 shell_contents = "@echo off"
0 commit comments