From 0b2596a7187bcecc9e09da1ff48fe99d5393e636 Mon Sep 17 00:00:00 2001 From: xiaohan-xue Date: Wed, 16 Oct 2024 20:14:28 -0700 Subject: [PATCH] Read ghstackrc from `$GHSTACKRC_PATH` before falling back to `~/.ghstackrc` (#261) --- ghstack/config.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ghstack/config.py b/ghstack/config.py index ce88be4..72a91d0 100644 --- a/ghstack/config.py +++ b/ghstack/config.py @@ -12,6 +12,9 @@ import ghstack.logs +DEFAULT_GHSTACKRC_PATH = Path.home() / ".ghstackrc" +GHSTACKRC_PATH_VAR = "GHSTACKRC_PATH" + Config = NamedTuple( "Config", [ @@ -41,6 +44,12 @@ ) +def get_path_from_env_var(var_name: str) -> Optional[Path]: + if (path := os.environ.get(var_name)) is not None: + return Path(path).expanduser().resolve() + return None + + def read_config( *, request_circle_token: bool = False, @@ -60,7 +69,9 @@ def read_config( write_back = False if config_path is None: - config_path = os.path.expanduser("~/.ghstackrc") + config_path = str( + get_path_from_env_var(GHSTACKRC_PATH_VAR) or DEFAULT_GHSTACKRC_PATH + ) write_back = True logging.debug(f"config_path = {config_path}")