A package designed to simplify configurable defaults from argparse.
Project description
cfg_argparser 1.1.4-1
a config wrapper I made to be easily applied to argparse objects.
Installation
# from pypi:
pip install cfg-argparser
# from github:
git clone "https://github.com/zeptofine/cfg-argparser"
cd cfg-argparser
pip install -e .
Example
import argparse
from cfg_argparser import ConfigArgParser
def parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument("--file")
return parser
if __name__ == "__main__":
args = ConfigArgParser(parser(),
"config.json",
exit_on_change=True).parse_args()
print(args.file)
Wrapping the ConfigArgParser
around parser()
adds a few "magic" arguments.
here's what it adds:
Config options:
--set KEY VAL change a default argument's options
--reset [VALUE ...] removes a changed option.
--reset_all resets every option.
Here's what it looks like in practice:
> python example.py
None
> python example.py --file foo.txt
foo.txt
> python example.py --set file foo.txt
> python example.py
foo.txt
Compatibilty
This was mainly tested on 3.9 and 3.10, but it should work from 3.6 onwards. i can't test earlier versions for some reason.
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
Close
Hashes for cfg-argparser-1.1.4.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 086f080570f2edf5f199065e807f2d87a76289d0e8426c31fce2ba36af2a46a3 |
|
MD5 | d705e4983248cb8277744477e3d545f6 |
|
BLAKE2b-256 | 790a4ef2e73d3c7cb369917e578a77c3e2b82e68b3af29297803c5c0fd01e6c1 |
Close
Hashes for cfg_argparser-1.1.4.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 899ed34086f7d9f3ac8de909cdef63f1892c965dd01f03f526f048ba17e33a18 |
|
MD5 | 71a15075160afc2fd8ac1ec45d056122 |
|
BLAKE2b-256 | 3689cc8db61b78c3ff29eb88bd1290d08cb6afe511aafc2732cfa1788ac1cfe9 |