Skip to content

Commit 0b2596a

Browse files
authored
Read ghstackrc from $GHSTACKRC_PATH before falling back to ~/.ghstackrc (#261)
1 parent a53b4fe commit 0b2596a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ghstack/config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
import ghstack.logs
1414

15+
DEFAULT_GHSTACKRC_PATH = Path.home() / ".ghstackrc"
16+
GHSTACKRC_PATH_VAR = "GHSTACKRC_PATH"
17+
1518
Config = NamedTuple(
1619
"Config",
1720
[
@@ -41,6 +44,12 @@
4144
)
4245

4346

47+
def get_path_from_env_var(var_name: str) -> Optional[Path]:
48+
if (path := os.environ.get(var_name)) is not None:
49+
return Path(path).expanduser().resolve()
50+
return None
51+
52+
4453
def read_config(
4554
*,
4655
request_circle_token: bool = False,
@@ -60,7 +69,9 @@ def read_config(
6069

6170
write_back = False
6271
if config_path is None:
63-
config_path = os.path.expanduser("~/.ghstackrc")
72+
config_path = str(
73+
get_path_from_env_var(GHSTACKRC_PATH_VAR) or DEFAULT_GHSTACKRC_PATH
74+
)
6475
write_back = True
6576

6677
logging.debug(f"config_path = {config_path}")

0 commit comments

Comments
 (0)