Turns TOML files and command-line arguments into dataclasses for config
Project description
xconf
- Dataclasses and TOML for command configuration
Demo
An example of how to use xconf.Command
, xconf.field
, and xconf.config
is in demo.py
. Run it to see its configuration keys.
$ python demo.py demo_command -h
demo_command: Demo command
usage: demo.py demo_command [-c CONFIG_FILE] [-h] [-v] [--dump-config] [vars ...]
positional arguments:
vars Config variables set with 'key.key.key=value' notation
optional arguments:
-c CONFIG_FILE, --config-file CONFIG_FILE
Path to config file (default: demo_command.conf.toml)
-h, --help Print usage information
-v, --verbose Enable debug logging
--dump-config Dump final configuration state as TOML and exit
configuration keys:
collections
dict[str, ExtendedThingie]
collections.<str>.name
str
collections.<str>.extended
bool
either_one
[int, str]
should_bar
bool
(default: False)
should_foo
bool
Whether demo should foo
number_list
list[int]
List of favorite numbers
sequence
list[ExtendedThingie]
Default config file
The command name, demo_command
, is generated from the class name and used to find a default configuration file (demo_command.conf.toml
) in the current directory.
Providing arguments at the command line
Any configuration key from the help output can be supplied on the command line in a dotted.name=value
format.
For lists of primitive types (str
, int
, float
), you can just use commas to separate the values on the right hand side of the =
. Example: number_list=1,2,3
.
To override a single entry in a list, use some_name[#]
or dotted[#].name=value
where #
is an integer index will work. Example: number_list[0]=99
String values are bare (i.e. no quotation marks around value
). Boolean values are case-insensitive true
, t
, or 1 for True, false
, f
, or 0 for False.
Structuring the command
See demo.py
for an example. Note that commands must subclass xconf.Command
and apply the @xconf.config
decorator. Options are defined by a hierarchy of dataclasses. (For uninteresting reasons, they aren't strictly speaking import dataclass
dataclasses.)
License
All code outside xconf/vendor/
is provided under the terms of the MIT License, except for demo.py
and demo_command.conf.toml
, which are released into the public domain for you to build off of.
Note that code under xconf/vendor/
is used under the terms of the licenses listed there.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xconf-0.0.1.tar.gz
.
File metadata
- Download URL: xconf-0.0.1.tar.gz
- Upload date:
- Size: 27.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f66722f5f467a3e3adc10aa14f1069a3771da9eedbe1af0f63244917483ba23 |
|
MD5 | 49a2c8e9514a02506033561b20e973c1 |
|
BLAKE2b-256 | 3aac5b0307f2d34f28ed1d8452f77bb412f2724f2f899fb37ab700e579094142 |
File details
Details for the file xconf-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: xconf-0.0.1-py3-none-any.whl
- Upload date:
- Size: 28.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c57cb7b93cfe47a38b163f551239113bebbf193be11be366efd629e81b6f207a |
|
MD5 | 49eb6685cc7da5532287290e8106c5fb |
|
BLAKE2b-256 | 37e4016f90ef6c013990803c867c2b80758ace01195853a0ce1f20672cf7d930 |