From e11f91ef7e5b47a13355fd9ca4ac3cf15905fd7c Mon Sep 17 00:00:00 2001 From: robcxyz Date: Mon, 14 Nov 2022 01:55:26 +0530 Subject: [PATCH] chore: add xdg special vars --- docs/special-variables.md | 8 ++++ tackle/special_vars.py | 44 ++++++++++++++++++++++ tests/parser/test_parser_hook_arguments.py | 24 ------------ 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/docs/special-variables.md b/docs/special-variables.md index 4c69ce4e2..c12540dd4 100644 --- a/docs/special-variables.md +++ b/docs/special-variables.md @@ -12,6 +12,14 @@ A number of special variables exist for using within tackle files to gain access - `current_directory` - The directory of the input tackle file. - `tackle_dir` - Directory where tackle config is, ie `~/.config/tackle` - `provider_dir` - Directory where tackle config is, ie `~/.config/tackle/providers` +- `xdg_cache_home` - XDG [cache dir](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) +- `xdg_config_dirs` - XDG [config dirs](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) +- `xdg_config_home` - XDG [config home](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) +- `xdg_data_dirs` - XDG [data dirs](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) +- `xdg_data_home` - XDG [data dir](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) +- `xdg_runtime_dir` - XDG [runtime dir](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) +- `xdg_state_home` - XDG [state home](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) + ### System Properties diff --git a/tackle/special_vars.py b/tackle/special_vars.py index 73fa4321c..9ad3597c4 100644 --- a/tackle/special_vars.py +++ b/tackle/special_vars.py @@ -2,6 +2,15 @@ import platform import csv from typing import TYPE_CHECKING +from xdg import ( + xdg_cache_home, + xdg_config_dirs, + xdg_config_home, + xdg_data_dirs, + xdg_data_home, + xdg_runtime_dir, + xdg_state_home, +) from tackle.settings import settings @@ -115,6 +124,34 @@ def _key_path_block(context: 'Context'): return context.key_path_block +def _xdg_cache_home(): + return xdg_cache_home() + + +def _xdg_config_dirs(): + return xdg_config_dirs() + + +def _xdg_config_home(): + return xdg_config_home() + + +def _xdg_data_dirs(): + return xdg_data_dirs() + + +def _xdg_data_home(): + return xdg_data_home() + + +def _xdg_runtime_dir(): + return xdg_runtime_dir() + + +def _xdg_state_home(): + return xdg_state_home() + + special_variables = { 'cwd': _cwd, 'home_dir': _home_dir, @@ -137,4 +174,11 @@ def _key_path_block(context: 'Context'): 'temporary_context': _temporary_context, 'key_path': _key_path, 'key_path_block': _key_path_block, + 'xdg_cache_home': _xdg_cache_home, + 'xdg_config_dirs': _xdg_config_dirs, + 'xdg_config_home': _xdg_config_home, + 'xdg_data_dirs': _xdg_data_dirs, + 'xdg_data_home': _xdg_data_home, + 'xdg_runtime_dir': _xdg_runtime_dir, + 'xdg_state_home': _xdg_state_home, } diff --git a/tests/parser/test_parser_hook_arguments.py b/tests/parser/test_parser_hook_arguments.py index 0eef869e1..c1128da19 100644 --- a/tests/parser/test_parser_hook_arguments.py +++ b/tests/parser/test_parser_hook_arguments.py @@ -51,27 +51,3 @@ def test_parser_render_hook_input(change_curdir_fixtures): for k, v in output.items(): if k.startswith('stuff'): assert v == 'things' - - -# TODO: When help is done -# @pytest.mark.parametrize("input_string", ['do_stuff', 'tackle.yaml do_stuff']) -# def test_parser_call_key_on_args(chdir_fixture, input_string): -# """Validate that when an additional argument is supplied that the key is called.""" -# chdir_fixture('help') -# output = tackle(input_string) -# assert output['do_stuff'] == 'Doing things...' -# assert output['do_things'] != 'Doing stuff...' - - -# @pytest.mark.parametrize( -# "input_string", -# [ -# # 'do_stuff', -# # 'file.yaml do_stuff do_things' -# 'file.yaml do_stuff_compact do_things and other things' -# # 'file.yaml do_stuff_compact_block print_this and print all this to' -# ], -# ) -# def test_parser_call_key_on_args_cli(chdir_fixture, input_string): -# chdir_fixture('help') -# main(input_string.split())