Skip to content

Commit

Permalink
Read ghstackrc from $GHSTACKRC_PATH before falling back to `~/.ghst…
Browse files Browse the repository at this point in the history
…ackrc` (#261)
  • Loading branch information
xiaohan-xue authored Oct 17, 2024
1 parent a53b4fe commit 0b2596a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ghstack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import ghstack.logs

DEFAULT_GHSTACKRC_PATH = Path.home() / ".ghstackrc"
GHSTACKRC_PATH_VAR = "GHSTACKRC_PATH"

Config = NamedTuple(
"Config",
[
Expand Down Expand Up @@ -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,
Expand All @@ -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}")
Expand Down

0 comments on commit 0b2596a

Please sign in to comment.