MCPcopy Index your code
hub / github.com/httpie/cli / get_default_config_dir

Function get_default_config_dir

httpie/config.py:20–55  ·  view source on GitHub ↗

Return the path to the httpie configuration directory. This directory isn't guaranteed to exist, and nor are any of its ancestors (only the legacy ~/.httpie, if returned, is guaranteed to exist). XDG Base Directory Specification support: <https://wiki.archlinux.org/index.

()

Source from the content-addressed store, hash-verified

18
19
20def get_default_config_dir() -> Path:
21 """
22 Return the path to the httpie configuration directory.
23
24 This directory isn&#x27;t guaranteed to exist, and nor are any of its
25 ancestors (only the legacy ~/.httpie, if returned, is guaranteed to exist).
26
27 XDG Base Directory Specification support:
28
29 <https://wiki.archlinux.org/index.php/XDG_Base_Directory>
30
31 $XDG_CONFIG_HOME is supported; $XDG_CONFIG_DIRS is not
32
33 """
34 # 1. explicitly set through env
35 env_config_dir = os.environ.get(ENV_HTTPIE_CONFIG_DIR)
36 if env_config_dir:
37 return Path(env_config_dir)
38
39 # 2. Windows
40 if is_windows:
41 return DEFAULT_WINDOWS_CONFIG_DIR
42
43 home_dir = Path.home()
44
45 # 3. legacy ~/.httpie
46 legacy_config_dir = home_dir / DEFAULT_RELATIVE_LEGACY_CONFIG_DIR
47 if legacy_config_dir.exists():
48 return legacy_config_dir
49
50 # 4. XDG
51 xdg_config_home_dir = os.environ.get(
52 ENV_XDG_CONFIG_HOME, # 4.1. explicit
53 home_dir / DEFAULT_RELATIVE_XDG_CONFIG_HOME # 4.2. default
54 )
55 return Path(xdg_config_home_dir) / DEFAULT_CONFIG_DIRNAME
56
57
58DEFAULT_CONFIG_DIR = get_default_config_dir()

Callers 6

test_legacy_config_dirFunction · 0.90
test_custom_config_dirFunction · 0.90
test_windows_config_dirFunction · 0.90
config.pyFile · 0.85

Calls 3

PathClass · 0.85
getMethod · 0.80
existsMethod · 0.80

Tested by 5

test_legacy_config_dirFunction · 0.72
test_custom_config_dirFunction · 0.72
test_windows_config_dirFunction · 0.72