Return the XDG_CONFIG_HOME, if it is defined and exists, else None. This is only for non-OS X posix (Linux,Unix,etc.) systems.
()
| 197 | 'set $HOME environment variable to override' % homedir) |
| 198 | |
| 199 | def get_xdg_dir() -> str | None: |
| 200 | """Return the XDG_CONFIG_HOME, if it is defined and exists, else None. |
| 201 | |
| 202 | This is only for non-OS X posix (Linux,Unix,etc.) systems. |
| 203 | """ |
| 204 | |
| 205 | env = os.environ |
| 206 | |
| 207 | if os.name == "posix": |
| 208 | # Linux, Unix, AIX, etc. |
| 209 | # use ~/.config if empty OR not set |
| 210 | xdg = env.get("XDG_CONFIG_HOME", None) or os.path.join(get_home_dir(), '.config') |
| 211 | if xdg and _writable_dir(xdg): |
| 212 | assert isinstance(xdg, str) |
| 213 | return xdg |
| 214 | |
| 215 | return None |
| 216 | |
| 217 | |
| 218 | def get_xdg_cache_dir(): |
no test coverage detected
searching dependent graphs…