Skip to main content

'My standard' goto package for all my scripts/apps. Get argparse cli and configuration management in ONE LINE per parameter ;-)

Project description

confused-argparse

Build Status Coverage Python Version wemake-python-styleguide

Note: VERY Beta, please wait for relase 1.0, since it is not even complete yet

"My standard" goto package for all my scripts/apps. Get argparse cli and configuration management in ONE LINE per parameter ;-)

With minimal boilerplate to handle:

  • System, default and script level configuration management files with confuse using YAML
  • OS enviroment does overwite settings from YAML
  • Automagic argparse CLI creation and handling. Will overwrite all settings from YAML and os enviroment
  • Setting the logging level

And:

  • Creating the user default and script level YAML files at first run
  • Optional: Saving state at exit
  • and so much more ...

See:

Install:

  • bash Shell:
$ python3 -m venv /path/to/new/virtual/environment
$ cd /path/to/new/virtual/environment
$ source ./bin/activate
$ pip install confused-argparse

First Excample

  • PROGNAME.py:
import confused-argparse
ca=confused-argparse.set_var()
ca('input_file', str, 'Input file: Read from a local file')

Behind the scenes:

  • If input_file was set in any of the YAML files, it will already have a value (Actually views of values, see confuse)
  • If input_file was set in the os enviroment, input_file will be set accrodingly, overriting the YAML setting
  • If --input_file was set via the command line interface with python3 PROGNAME.py --input_file my_file.txt, overriting the YAML and os enviroment setting to my_file.txt

In the bash shell:

$ python3 PROGNAME.py -h

usage: PROGNAME.py [-h] [--input_file INPUT_FILE]

optional arguments:
  -h, --help                  show this help message and exit
  --input_file INPUT_FILE     Input file: Read from a local file

Next level:

  • PROGNAME.py:
import confused-argparse
ca = confused-argparse.set_var(standard=True, description='My App: Solves a problem')
ca('input_file', str, 'Input file: Read from a local file', group='I/O')

Behind the scenes:

  • standard=True:
    • There are a number of standard argparse options already set, like --verbose, --debug, --cron
    • Scans and read the values defined in the os enviroment, case independant, so also the enviroment variable VERBOSE
    • For excample: --verbose will set the logging level to INFO
  • description='My App: Solves a problem'
    • argparse will print this
  • group='I/O':
    • argparse will group options with this optional parameter
$ python3 PROGNAME.py -h

usage: PROGNAME.py [-h] [--input_file INPUT_FILE] [--list_defaults] [--debug] [--verbose] [--cron]

My App: Solves a problem

optional arguments:
  -h, --help                  show this help message and exit

I/O:
  --input_file INPUT_FILE     Input file: Read from a local file [str]=''

Debug options:
Note: Will override 
  --list_defaults             List: List all Vars in dict with there Defaults [bool]=False
  --debug                     Debug: Logging DEBUG Messages (if not --cron, overrides --verbose) [bool]=False
  --verbose                   Verbose: Logging INFO Messages (if not --cron) [bool]=False
  --cron                      Called from Cronjob [bool]=False

Want more?

See Documentation. (Soon)

Pull Requests?

  • Will be welcomed, when we reached the first beta
  • Note: The confused-argparse github repository is still private/closed

DEV

License

MIT

(c) 2020 Nikolai von Krusenstiern

Credits

This project was generated with wemake-python-package. Current template version is: 69435b231f7f398474073ac6dd14868dd3edf2c1. See what is updated since then.

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

confused-argparse-0.2.2.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

confused_argparse-0.2.2-py3-none-any.whl (4.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