Skip to content
Snippets Groups Projects
Commit 1a7f5b62 authored by Jon Crall's avatar Jon Crall
Browse files

Merge branch 'dev/0.7.15' into 'main'

Start branch for dev/0.7.15

See merge request !32
parents 6a311add f1d26f55
No related branches found
No related tags found
1 merge request!32Start branch for dev/0.7.15
Pipeline #399329 passed
......@@ -4,7 +4,12 @@ This changelog follows the specifications detailed in: [Keep a Changelog](https:
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), although we have not yet reached a `1.0.0` release.
## Version 0.7.14 - Unreleased
## Version 0.7.15 - Unreleased
### Added
* Allow special options to be passed to cli
## Version 0.7.14 - Released 2024-04-15
### Changed
* Better error messages when parsing argv
......
......@@ -151,7 +151,7 @@ Ignore:
mkinit ~/code/scriptconfig/scriptconfig/__init__.py --nomods --relative -w
"""
__version__ = '0.7.14'
__version__ = '0.7.15'
__submodules__ = {
'modal': None,
......
......@@ -341,7 +341,7 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig):
@classmethod
def cli(cls, data=None, default=None, argv=None, strict=True,
cmdline=True, autocomplete='auto'):
cmdline=True, autocomplete='auto', special_options=True):
"""
Create a commandline aware config instance.
......@@ -377,6 +377,10 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig):
autocomplete (bool | str):
if True try to enable argcomplete.
special_options (bool, default=True):
adds special scriptconfig options, namely: --config, --dumps,
and --dump. In the future this default will change to False.
"""
if cmdline and argv is not None:
cmdline = argv
......@@ -390,7 +394,7 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig):
# prevents adding clean options for control flow.
self = cls(_dont_call_post_init=True)
self.load(data, cmdline=cmdline, default=default, strict=strict,
autocomplete=autocomplete)
autocomplete=autocomplete, special_options=special_options)
return self
@classmethod
......@@ -564,7 +568,8 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig):
self._alias_map = None
def load(self, data=None, cmdline=False, mode=None, default=None,
strict=False, autocomplete=False, _dont_call_post_init=False):
strict=False, autocomplete=False, _dont_call_post_init=False,
special_options=True):
"""
Updates the configuration from a given data source.
......@@ -581,6 +586,7 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig):
If a list of strings that used instead of sys.argv.
If a string, then that is parsed using shlex and used instead
of sys.argv.
DO NOT USE dictionary form. It is deprecated.
If a dictionary grants fine grained controls over the args
passed to :func:`Config._read_argv`. Can contain:
* strict (bool): defaults to False
......@@ -606,6 +612,10 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig):
if True, attempts to use the autocomplete package if it is
available if reading from sys.argv. Defaults to False.
special_options (bool, default=False):
adds special scriptconfig options, namely: --config, --dumps,
and --dump. Prefer using this over cmdline.
Note:
if cmdline=True, this will create an argument parser.
......@@ -738,12 +748,15 @@ class Config(ub.NiceRepr, DictLike, metaclass=MetaConfig):
# should override them IF they exist on in sys.argv, but not if
# they don't?
read_argv_kwargs = {
'special_options': True,
'special_options': special_options,
'strict': strict,
'autocomplete': autocomplete,
'argv': None,
}
if isinstance(cmdline, dict):
ub.schedule_deprecation('scriptconfig', 'cmdline', 'parameter as a dictionary',
migration='The API should expose any special params explicitly',
deprecate='0.7.15', error='0.8.0', remove='0.9.0')
read_argv_kwargs.update(cmdline)
elif ub.iterable(cmdline) or isinstance(cmdline, str):
read_argv_kwargs['argv'] = cmdline
......
......@@ -56,7 +56,7 @@ class Value(ub.NiceRepr):
short_alias (List[str] | None):
other short names (that will be prefixed with '-') that will be
accepted by the argparse CLI.
accepted by the argparse CLI. e.g. ``short_alias=['n']``
group (str | None):
Impacts display of underlying argparse object by grouping values
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment