Skip to main content

A package designed to simplify configurable defaults from argparse.

Project description

cfg_argparser 1.1.5

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


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.5.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

cfg_argparser-1.1.5-py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page