1+ from __future__ import annotations
2+
13import os
24import re
35from pathlib import Path
4- from typing import Optional
6+ from typing import TYPE_CHECKING , Optional
57
68from 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
914if os .name == "nt" : # Windows
1015 SHELL_RC_EXPORT_PATTERN = re .compile (r"^set CODEFLASH_API_KEY=(cf-.*)$" , re .MULTILINE )
1722def 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 open (shell_rc_path , encoding = "utf8" ) as shell_rc : # noqa: PTH123
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 open (shell_rc_path , "r+" , encoding = "utf8" ) as shell_file : # noqa: PTH123
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