Skip to content

Commit b20c7fe

Browse files
Merge pull request #79 from bepoli/xdg_config
Support XDG directories
2 parents 1afd1df + 1c8b6b6 commit b20c7fe

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

condax/config.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,31 @@ def candidates() -> "Generator[Optional[StrPath], None, None]":
8484
raise RuntimeError("Could not find conda executable")
8585

8686

87-
_condaxrc_path = os.path.expanduser(os.path.join("~", ".condaxrc"))
88-
if os.path.exists(_condaxrc_path):
87+
_condaxrc_path_list = [os.path.expanduser(os.path.join("~", ".condaxrc"))]
88+
if "CONDAXRC" in os.environ:
89+
_condaxrc_path_list = [os.environ["CONDAXRC"]] + _condaxrc_path_list
90+
if "XDG_CONFIG_HOME" in os.environ:
91+
_condaxrc_path_list += [
92+
os.path.expanduser(
93+
os.path.join(os.environ["XDG_CONFIG_HOME"], "condax", "condaxrc")
94+
),
95+
os.path.expanduser(
96+
os.path.join(os.environ["XDG_CONFIG_HOME"], "condax", ".condaxrc")
97+
),
98+
]
99+
_condaxrc_path_list += [
100+
os.path.join("~", ".condax", "condaxrc"),
101+
os.path.join("~", ".condax", ".condaxrc"),
102+
os.path.join("~", ".config", "condax", "condaxrc"),
103+
os.path.join("~", ".config", "condax", ".condaxrc"),
104+
"/etc/condax/condaxrc",
105+
"/etc/condax/.condaxrc",
106+
"/var/lib/condax/condaxrc",
107+
"/var/lib/condax/.condaxrc",
108+
]
109+
_condaxrc_path_list = [x for x in _condaxrc_path_list if os.path.exists(x)]
110+
if any(_condaxrc_path_list):
111+
_condaxrc_path = _condaxrc_path_list[0]
89112
with open(_condaxrc_path) as fo:
90113
CONFIG = Config(**yaml.safe_load(fo))
91114
else:

news/xdg_config.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Added:
2+
3+
* Look for `condaxrc` in `$XDG_CONFIG_HOME/condax` (usually `~/.config/condax`) and other paths, if `~/.condaxrc` is not present.

0 commit comments

Comments
 (0)