'My standard' goto package for all my scripts/apps. Get argparse cli and configuration management in ONE LINE per parameter ;-)
Project description
confused-argparse
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:
-
confused-argparse THIS PACKAGE
-
venv for python virtual enviroment
-
confuse for handling configuration TOML files
-
argparse for creating a CLI parser
-
os.environ for reading enviroment variables
-
logging for logging to console
-
YAML for saving configuration data
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 withpython3 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
- There are a number of standard argparse options already set, like
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
-
Supports latest python3.7+
-
poetry for managing dependencies and build & publish to pypy
-
wemake-python-package for steting up a out of the box ready building enviroment
- Minor tweaks to
.gitignore
andMakefile
- Minor tweaks to
-
gnu make for runing tests and building docs
-
jupyter for quick tests and some development
-
sphinx and readthedocs.org for documentation
-
travis or Github Actions as the default CI
-
@dependabot for always up-to-date dependencies
-
mypy for optional static typing
-
pytest for testing
-
flake8 and wemake-python-styleguide for linting
License
(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
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 confused-argparse-0.2.2.tar.gz
.
File metadata
- Download URL: confused-argparse-0.2.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.5 Darwin/18.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
fc4776b4653ed5b9e4d16d85434a5156f69f3df1bb74825c452825da250ba76c
|
|
MD5 |
167a57c82aeccee0cae6ab4c8c3503d4
|
|
BLAKE2b-256 |
5ec21086814916a50f761ea17b8f02ea8e0c4315358d8da3896df13a58879358
|
File details
Details for the file confused_argparse-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: confused_argparse-0.2.2-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.5 Darwin/18.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
7651aee55f7a39b35158f704ca96a7e96196ec89feecc8498dfa5c55960756a5
|
|
MD5 |
4e627fb8bec8667c6db711f948a07296
|
|
BLAKE2b-256 |
0f08bf249334263194df04a523e3dc1554eed89c4574249ea22d9ba58b615039
|