argparse settings with miniconfig
code
from miniconfig_argparse import get_configurator
config = get_configurator()
config.include("yourmodule")
config.include("yourmodule.extra")
args = config.make_args()
# using args
in yourmodule, using config like a below.
def includeme(config):
parser = config.parser
parser.add_argument(
'-v', '--verbose', action='count', default=0,
help="(default option: increment logging level(default is WARNING))"
)
parser.add_argument(
'-q', '--quiet', action='count', default=0,
help="(default option: decrement logging level(default is WARNING))"
)
def setup_closure(args):
logging_level = logging.WARN + 10 * args.quiet - 10 * args.verbose
logging.basicConfig(level=logging_level)
return args
parser.add_callback(setup_closure)
default directives
make_parser
replace_parser
call_function_as_command
make_parser(fn) + call_function_as_command
Using make_parser() and call_function_as_command() combinations are useful, sometimes.
make_parser(fn) – creating parser from a function definition.
call_function_as_command – call function using parsed argument object.
Such as below.
def greeting(message, is_surprised=False, name="foo"):
""" greeting message
:param message: message of greeting
:param is_surprised: surprised or not (default=False)
:param name: name of actor
"""
suffix = "!" if is_surprised else ""
print("{name}: {message}{suffix}".format(name=name, message=message, suffix=suffix))
def includeme(config):
parser = config.make_parser(greeting)
config.replace_parser(parser)
if __name__ == "__main__":
from miniconfig_argparse import get_configurator
config = get_configurator()
config.include(includeme)
args = config.make_args()
config.call_function_as_command(greeting, args)
Metadata
Release files for miniconfig-argparse 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| miniconfig-argparse-0.0.4.tar.gz | 4.5 kB | Without provenance | Details for miniconfig-argparse-0.0.4.tar.gz |
Release files / miniconfig-argparse-0.0.4.tar.gz
| Download URL | miniconfig-argparse-0.0.4.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50b4f8e11f43dc642c7741493f3279d070cafac1716f5c584981a3cf4ba6ea3d
|
|
BLAKE2b-256 checksum How to use checksums |
3d0e6381066170c2e89c79620973c089c81113fcf20e91881c4d893ec69cacae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for miniconfig-argparse 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.