Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions guardrails/classes/rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ class RC(Serializeable):

@staticmethod
def exists() -> bool:
home = expanduser("~")
guardrails_rc = os.path.join(home, ".guardrailsrc")
return os.path.exists(guardrails_rc)
# Cache the home directory to avoid recomputing expanduser("~") every call
# This optimization is safe because the home directory doesn't change during runtime
# and the location of the .guardrailsrc file is fixed for the user context
if not hasattr(RC.exists, "_guardrails_rc"):
home = expanduser("~")
RC.exists._guardrails_rc = os.path.join(home, ".guardrailsrc")
return os.path.exists(RC.exists._guardrails_rc)

@classmethod
def load(cls, logger: Optional[logging.Logger] = None) -> "RC":
Expand Down