Skip to content

Commit

Permalink
chore: add xdg special vars
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Nov 13, 2022
1 parent 9a9fdb1 commit e11f91e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 24 deletions.
8 changes: 8 additions & 0 deletions docs/special-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 44 additions & 0 deletions tackle/special_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
24 changes: 0 additions & 24 deletions tests/parser/test_parser_hook_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit e11f91e

Please sign in to comment.