From 2553bc14af81c805af752aeedf3b94153641afde Mon Sep 17 00:00:00 2001 From: "Sam G." Date: Sun, 18 Aug 2024 11:56:28 -0700 Subject: [PATCH] add py execution support to templates, loosen generate matches --- README.md | 19 +++++++-- docs/index.md | 16 ++++++-- symconf/__main__.py | 30 +++++++++++++- symconf/config.py | 98 +++++++++++++++++++++++++++------------------ symconf/matching.py | 42 ++++++++++--------- symconf/reader.py | 3 ++ symconf/runner.py | 3 ++ symconf/template.py | 61 +++++++++++++++++++++++----- symconf/util.py | 2 +- 9 files changed, 195 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index d592e1d..0295db3 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,9 @@ used when populating config file templates. Specifically, in this example, invok are responsive to `prefers-color-scheme`) - **kitty**: theme template is re-generated using the specified palette, and `kitty` processes are sent a message to live-reload the new config file -- **neovim**: a `vim` theme file is generated from the chosen palette, and running - instances of `neovim` are sent a message to re-source this theme +- **neovim**: a `vim` theme file (along with a statusline theme) is generated from the + chosen palette, and running instances of `neovim` are sent a message to re-source this + theme (via `nvim --remote-send`) - **waybar**: bar styles are updated to match the mode setting - **sway**: the background color and window borders are dynamically set to base palette colors, and `swaymsg reload` is called @@ -73,13 +74,25 @@ You can also install via `pip`, or clone and install locally. all registered apps. * `-m --mode`: preferred lightness mode/scheme, either `light`, `dark`, `any`, or `none`. - * `-s --style`: style indicate, often the name of a color palette, capturing thematic + * `-s --style`: style indicator, often the name of a color palette, capturing thematic details in a config file to be matched. `any` or `none` are reserved keywords (see below). * `-T --template-vars`: additional groups to use when populating templates, in the form `=`, where `` is a template group with a folder `$CONFIG_HOME/groups//` and `` should correspond to a TOML file in this folder (i.e., `.toml`). +- `symconf generate` is a subcommand that can be used for batch generation of config + files. It accepts the same arguments as `symconf config`, but rather than selecting the + best match to be used for the system setting, all matching templates are generated. + There is one additional required argument: + * `-o --output-dir`: the directory under which generated config files should be written. + App-specific subdirectories are created to house config files for each provided app. +- `symconf install`: runs install scripts for matching apps that specify one + * `-a --apps`: comma-separate list of registered apps, or `"*"` (default) to consider + all registered apps. +- `symconf update`: runs update scripts for matching apps that specify one + * `-a --apps`: comma-separate list of registered apps, or `"*"` (default) to consider + all registered apps. The keywords `any` and `none` can be used when specifying `--mode`, `--style`, or as a value in `--template-vars` (and we refer to each of these variables as _factors_ that help diff --git a/docs/index.md b/docs/index.md index 68231e9..9a93d92 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,22 +3,29 @@ {ref}`modindex` {ref}`search` +## Top-level module overview + ```{eval-rst} .. autosummary:: :nosignatures: + :recursive: - # list modules here for quick links + symconf.config + symconf.template + symconf.matching + symconf.reader + symconf.runner ``` +## Auto-reference contents ```{toctree} :maxdepth: 3 -:caption: Autoref _autoref/symconf.rst ``` ```{toctree} -:maxdepth: 3 +:maxdepth: 2 :caption: Contents reference/configuring @@ -28,4 +35,7 @@ reference/documentation/index ``` ```{include} ../README.md +:relative-docs: docs/ +:relative-images: ``` + diff --git a/symconf/__main__.py b/symconf/__main__.py index a500d3b..72fa083 100644 --- a/symconf/__main__.py +++ b/symconf/__main__.py @@ -50,6 +50,7 @@ def add_config_subparser(subparsers): apps=args.apps, scheme=args.mode, style=args.style, + **args.template_vars ) parser = subparsers.add_parser( @@ -81,6 +82,7 @@ def add_config_subparser(subparsers): '-T', '--template-vars', required = False, nargs='+', + default = {}, action=util.KVPair, help='Groups to use when populating templates, in the form group=value' ) @@ -90,8 +92,11 @@ def add_generate_subparser(subparsers): def generate_apps(args): cm = ConfigManager(args.config_dir) cm.generate_app_templates( - gen_dir=args.gen_dir, + gen_dir=args.output_dir, apps=args.apps, + scheme=args.mode, + style=args.style, + **args.template_vars ) parser = subparsers.add_parser( @@ -99,11 +104,24 @@ def add_generate_subparser(subparsers): description='Generate all template config files for specified apps' ) parser.add_argument( - '-g', '--gen-dir', + '-o', '--output-dir', required = True, type = util.absolute_path, help = 'Path to write generated template files' ) + parser.add_argument( + '-s', '--style', + required = False, + default = 'any', + help = 'Style indicator (often a color palette) capturing thematic details in ' + 'a config file' + ) + parser.add_argument( + '-m', '--mode', + required = False, + default = "any", + help = 'Preferred lightness mode/scheme, either "light," "dark," "any," or "none."' + ) parser.add_argument( '-a', '--apps', required = False, @@ -112,6 +130,14 @@ def add_generate_subparser(subparsers): help = 'Application target for theme. App must be present in the registry. ' \ + 'Use "*" to apply to all registered apps' ) + parser.add_argument( + '-T', '--template-vars', + required = False, + nargs = '+', + default = {}, + action = util.KVPair, + help = 'Groups to use when populating templates, in the form group=value' + ) parser.set_defaults(func=generate_apps) diff --git a/symconf/config.py b/symconf/config.py index 0d21fa4..8db459c 100644 --- a/symconf/config.py +++ b/symconf/config.py @@ -1,19 +1,19 @@ ''' -Get the config map for a provided app. +Primary config management abstractions The config map is a dict mapping from config file **path names** to their absolute path locations. That is, -```sh - -> /apps///-. -``` +.. code-block:: sh + + -> /apps///-. For example, -``` -palette1-light.conf.ini -> ~/.config/symconf/apps/user/palette1-light.conf.ini -palette2-dark.app.conf -> ~/.config/symconf/apps/generated/palette2-dark.app.conf -``` +.. code-block:: sh + + palette1-light.conf.ini -> ~/.config/symconf/apps/user/palette1-light.conf.ini + palette2-dark.app.conf -> ~/.config/symconf/apps/generated/palette2-dark.app.conf This ensures we have unique config names pointing to appropriate locations (which is mostly important when the same config file names are present across ``user`` @@ -220,16 +220,16 @@ class ConfigManager: files just the same as we do for non-template config files. That is, we will look for files of the format - ```sh -