Skip to content

Commit

Permalink
fix(asrgs, config): Correctly source xdg data paths (#806) (fixes: #801)
Browse files Browse the repository at this point in the history
* Prefer environment variables over config

* Sync default config values
  • Loading branch information
samuel-jimenez committed Jun 15, 2024
1 parent 0b34e1e commit a3a476c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 26 additions & 2 deletions pikaur/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ def init_value(cls) -> Path:
return Path(gettempdir())


class _CachePathDefault(FixedPathSingleton):
@classmethod
def init_value(cls) -> Path:
return Path(
pre_arg_parser("--xdg-cache-home", "")
or os.environ.get(
"XDG_CACHE_HOME",
)
or Home()() / ".cache/",
)


class _UserCacheRoot(FixedPathSingleton):
@classmethod
def init_value(cls) -> Path:
Expand Down Expand Up @@ -190,6 +202,18 @@ def init_value(cls) -> Path:
)


class _DataPathDefault(FixedPathSingleton):
@classmethod
def init_value(cls) -> Path:
return Path(
pre_arg_parser("--xdg-data-home", "")
or os.environ.get(
"XDG_DATA_HOME",
)
or Home()() / ".local/share/",
)


class DataRoot(FixedPathSingleton):
@classmethod
def init_value(cls) -> Path:
Expand Down Expand Up @@ -459,11 +483,11 @@ class DiffPagerValues:
},
"CachePath": {
"data_type": STR,
"default": str(Home()() / ".cache/"),
"default": str(_CachePathDefault()()),
},
"DataPath": {
"data_type": STR,
"default": str(Home()() / ".local/share/"),
"default": str(_DataPathDefault()()),
},
"PacmanPath": {
"data_type": STR,
Expand Down
2 changes: 1 addition & 1 deletion pikaur/privilege.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_args_to_elevate_pikaur(original_args: list[str]) -> list[str]:
("--xdg-data-home", "xdg_data_home", "XDG_DATA_HOME"),
):
arg_value = str(getattr(args, arg_key, None) or "")
if value := (arg_value or os.environ.get(env_key)):
if value := (os.environ.get(env_key) or arg_value):
extra_args += [
(flag, value),
]
Expand Down

0 comments on commit a3a476c

Please sign in to comment.