Skip to content

Commit 1ee309c

Browse files
authored
Merge branch 'main' into dev/scriptconfig_integration
2 parents 936ed95 + 2f3cce5 commit 1ee309c

20 files changed

+329
-58
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 4.30.0
2+
current_version = 4.31.0
33
commit = True
44
tag = True
55
tag_name = v{new_version}

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
pull_request:
77
branches: [ "main" ]
88
schedule:
9-
- cron: "57 5 * * 3"
9+
- cron: "57 5 * * 3" # M H d m w (Every Wednesday at 5:57 AM)
1010

1111
jobs:
1212
analyze:

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
strategy:
2929
fail-fast: false
3030
matrix:
31-
python: [3.8, "3.10"]
31+
python: [3.8, "3.10", 3.12]
3232
steps:
3333
- uses: actions/checkout@v4
3434
- uses: actions/setup-python@v5
@@ -39,7 +39,7 @@ jobs:
3939
- run: tox -e py-all-extras
4040

4141
unittest-omegaconf:
42-
runs-on: ubuntu-20.04
42+
runs-on: ubuntu-latest
4343
steps:
4444
- uses: actions/checkout@v4
4545
- uses: actions/setup-python@v5
@@ -50,7 +50,7 @@ jobs:
5050
- run: tox -e omegaconf
5151

5252
doctest:
53-
runs-on: ubuntu-20.04
53+
runs-on: ubuntu-latest
5454
steps:
5555
- uses: actions/checkout@v4
5656
- uses: actions/setup-python@v5

.sonarcloud.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
sonar.sources=jsonargparse
2-
sonar.projectVersion=4.30.0
2+
sonar.projectVersion=4.31.0
33
sonar.python.version=3.7, 3.8, 3.9, 3.10, 3.11, 3.12

CHANGELOG.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@ The semantic versioning only considers the public API as described in
1212
paths are considered internals and can change in minor and patch releases.
1313

1414

15+
v4.32.0 (2024-07-??)
16+
--------------------
17+
18+
Added
19+
^^^^^
20+
- Support for ``MappingProxyType`` as a type and as default for mapping types
21+
(`#540 <https://github.com/omni-us/jsonargparse/pull/540>`__).
22+
23+
24+
v4.31.0 (2024-06-27)
25+
--------------------
26+
27+
Added
28+
^^^^^
29+
- Support async functions and methods in ``CLI`` (`#531
30+
<https://github.com/omni-us/jsonargparse/pull/531>`__).
31+
- Support for ``Protocol`` types only accepting exact matching signature of
32+
public methods (`#526
33+
<https://github.com/omni-us/jsonargparse/pull/526>`__).
34+
35+
Fixed
36+
^^^^^
37+
- Resolving of import paths for some ``torch`` functions not working (`#535
38+
<https://github.com/omni-us/jsonargparse/pull/535>`__).
39+
- ``--print_shtab`` crashing on failure to get signature parameters from one
40+
class (`lightning#10858 comment
41+
<https://github.com/Lightning-AI/pytorch-lightning/discussions/10858#discussioncomment-9846252>`__).
42+
43+
Changed
44+
^^^^^^^
45+
- Now ``--*.help`` output shows options without ``init_args`` (`#533
46+
<https://github.com/omni-us/jsonargparse/pull/533>`__).
47+
48+
1549
v4.30.0 (2024-06-18)
1650
--------------------
1751

DOCUMENTATION.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,9 @@ Some notes about this support are:
400400
:ref:`restricted-strings` and paths and URLs as explained in sections
401401
:ref:`parsing-paths` and :ref:`parsing-urls`.
402402

403-
- ``Dict``, ``Mapping``, ``MutableMapping``, and ``TypedDict`` are supported but
404-
only with ``str`` or ``int`` keys. For more details see :ref:`dict-items`.
403+
- ``Dict``, ``Mapping``, ``MutableMapping``, ``MappingProxyType``, and
404+
``TypedDict`` are supported but only with ``str`` or ``int`` keys. For more
405+
details see :ref:`dict-items`.
405406

406407
- ``Tuple``, ``Set`` and ``MutableSet`` are supported even though they can't be
407408
represented in json distinguishable from a list. Each ``Tuple`` element
@@ -421,6 +422,10 @@ Some notes about this support are:
421422
:py:meth:`.ArgumentParser.instantiate_classes` can be used to instantiate all
422423
classes in a config object. For more details see :ref:`sub-classes`.
423424

425+
- ``Protocol`` types are also supported the same as sub-classes. The protocols
426+
are not required to be ``runtime_checkable``. But the accepted classes must
427+
match exactly the signature of the protocol's public methods.
428+
424429
- ``dataclasses`` are supported even when nested. Final classes, attrs'
425430
``define`` decorator, and pydantic's ``dataclass`` decorator and ``BaseModel``
426431
classes are supported and behave like standard dataclasses. For more details

jsonargparse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@
7070
__all__ += _deprecated.__all__
7171

7272

73-
__version__ = "4.30.0"
73+
__version__ = "4.31.0"

jsonargparse/_actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
argument_error,
2121
change_to_path_dir,
2222
default_config_option_help,
23+
get_import_path,
2324
get_typehint_origin,
2425
import_object,
2526
indent_text,
@@ -387,8 +388,7 @@ def print_help(self, call_args, baseclass, dest):
387388
baseclasses = [baseclass]
388389
if not any(is_subclass(val_class, b) for b in baseclasses):
389390
raise TypeError(f'{option_string}: Class "{value}" is not a subclass of {self._basename}')
390-
dest += ".init_args"
391-
subparser = type(parser)()
391+
subparser = type(parser)(description=f"Help for {option_string}={get_import_path(val_class)}")
392392
subparser.add_class_arguments(val_class, dest, **self.sub_add_kwargs)
393393
remove_actions(subparser, (_HelpAction, _ActionPrintConfig, _ActionConfigLoad))
394394
args = self.get_args_after_opt(parser.args)

jsonargparse/_cli.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def CLI(
9292
deprecation_warning_cli_return_parser()
9393
return parser
9494
cfg = parser.parse_args(args)
95-
cfg_init = parser.instantiate_classes(cfg)
96-
return _run_component(components, cfg_init)
95+
init = parser.instantiate_classes(cfg)
96+
return _run_component(components, init)
9797

9898
elif isinstance(components, list):
9999
components = {c.__name__: c for c in components}
@@ -192,12 +192,13 @@ def _add_component_to_parser(
192192

193193
def _run_component(component, cfg):
194194
cfg.pop("config", None)
195-
if not inspect.isclass(component):
196-
return component(**cfg)
197195
subcommand = cfg.pop("subcommand")
198-
if not subcommand:
199-
return component(**cfg)
200-
subcommand_cfg = cfg.pop(subcommand, {})
201-
subcommand_cfg.pop("config", None)
202-
component_obj = component(**cfg)
203-
return getattr(component_obj, subcommand)(**subcommand_cfg)
196+
if inspect.isclass(component) and subcommand:
197+
subcommand_cfg = cfg.pop(subcommand, {})
198+
subcommand_cfg.pop("config", None)
199+
component_obj = component(**cfg)
200+
component = getattr(component_obj, subcommand)
201+
cfg = subcommand_cfg
202+
if inspect.iscoroutinefunction(component):
203+
return __import__("asyncio").run(component(**cfg))
204+
return component(**cfg)

jsonargparse/_completions.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
)
2626
from ._util import NoneType, Path, import_object, unique
2727

28-
shtab_shell: ContextVar = ContextVar("shtab_shell")
29-
shtab_prog: ContextVar = ContextVar("shtab_prog")
30-
shtab_preambles: ContextVar = ContextVar("shtab_preambles")
31-
3228

3329
def handle_completions(parser):
3430
if find_spec("argcomplete") and "_ARGCOMPLETE" in os.environ:
@@ -76,6 +72,10 @@ def argcomplete_warn_redraw_prompt(prefix, message):
7672

7773
# shtab
7874

75+
shtab_shell: ContextVar = ContextVar("shtab_shell")
76+
shtab_prog: ContextVar = ContextVar("shtab_prog")
77+
shtab_preambles: ContextVar = ContextVar("shtab_preambles")
78+
7979

8080
class ShtabAction(argparse.Action):
8181
def __init__(
@@ -236,7 +236,7 @@ def get_typehint_choices(typehint, prefix, parser, skip, choices=None, added_sub
236236
origin = get_typehint_origin(typehint)
237237
if origin == Union:
238238
for subtype in typehint.__args__:
239-
if subtype in added_subclasses:
239+
if subtype in added_subclasses or subtype is object:
240240
continue
241241
get_typehint_choices(subtype, prefix, parser, skip, choices, added_subclasses)
242242
elif ActionTypeHint.is_subclass_typehint(typehint):
@@ -261,8 +261,12 @@ def add_subactions_and_get_subclass_choices(typehint, prefix, parser, skip, adde
261261
subclasses = defaultdict(list)
262262
for path in paths:
263263
choices.append(path)
264-
cls = import_object(path)
265-
params = get_signature_parameters(cls)
264+
try:
265+
cls = import_object(path)
266+
params = get_signature_parameters(cls, None, parser._logger)
267+
except Exception as ex:
268+
parser._logger.debug(f"Unable to get signature parameters for '{path}': {ex}")
269+
continue
266270
num_skip = next((s for s in skip if isinstance(s, int)), 0)
267271
if num_skip > 0:
268272
params = params[num_skip:]

0 commit comments

Comments
 (0)