A package designed to simplify configurable defaults from argparse.
Project description
cfg_argparser 1.1.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
cfg-argparser-1.1.2.tar.gz
(5.7 kB
view hashes)
Built Distribution
Close
Hashes for cfg_argparser-1.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0885a4d5d592d627b3f7473a589c58e33f91fec01fd88f3291293c89d92e727 |
|
MD5 | be8ad8f0d4fc6d71c06d8543ba800f10 |
|
BLAKE2b-256 | 5f3c254b1633ae88f4261dfdd445900efe9a1b4740163c90a609c689511abf79 |