Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Fixed
values (`#773 <https://github.com/omni-us/jsonargparse/pull/773>`__).
- ``save`` with ``multifile=True`` not saving separate subconfigs for items in a
list (`#779 <https://github.com/omni-us/jsonargparse/pull/779>`__).
- ``omegaconf`` parser mode failing on spawned processes (`#784
<https://github.com/omni-us/jsonargparse/pull/784>`__).


v4.41.0 (2025-09-04)
Expand Down
8 changes: 3 additions & 5 deletions jsonargparse/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
get_loader_exceptions,
load_value,
loaders,
set_omegaconf_loader,
)
from ._namespace import (
Namespace,
Expand Down Expand Up @@ -1613,10 +1612,9 @@ def parser_mode(self) -> str:

@parser_mode.setter
def parser_mode(self, parser_mode: str):
if parser_mode in {"omegaconf", "omegaconf+"}:
set_omegaconf_loader(parser_mode)
if parser_mode not in loaders:
raise ValueError(f"The only accepted values for parser_mode are {set(loaders)}.")
accepted = set(loaders).union({"omegaconf", "omegaconf+"})
if parser_mode not in accepted:
raise ValueError(f"The only accepted values for parser_mode are {accepted}.")
if parser_mode == "jsonnet":
import_jsonnet("parser_mode=jsonnet")
self._parser_mode = parser_mode
Expand Down
4 changes: 3 additions & 1 deletion jsonargparse/_loaders_dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,12 @@ def load_value(value: str, simple_types: bool = False, **kwargs):
loaded_value = load_basic(value)

mode = get_load_value_mode()
if loaded_value is not_loaded and not loader_json_superset[mode]:
if loaded_value is not_loaded and not loader_json_superset.get(mode, True):
loaded_value = load_list_or_dict(value)

if loaded_value is not_loaded:
if mode not in loaders and mode in {"omegaconf", "omegaconf+"}:
set_omegaconf_loader(mode)
loader = loaders[mode]
load_kwargs = {}
if kwargs and mode in loader_params:
Expand Down
25 changes: 25 additions & 0 deletions jsonargparse_tests/test_omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import math
import multiprocessing
import os
from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -224,3 +225,27 @@ def test_omegaconf_absolute_to_relative_paths():
"h": "${.f[0]}",
}
assert omegaconf_absolute_to_relative_paths(data) == expected


def parse_in_spawned_process(queue, parser, args):
try:
cfg = parser.parse_args(args)
queue.put(cfg)
except Exception as ex:
queue.put(ex)


@skip_if_omegaconf_unavailable
def test_omegaconf_in_spawned_process(parser):
parser.parser_mode = "omegaconf"
parser.add_argument("--dict", type=dict)
assert parser.parse_args(['--dict={"x":1}']).dict == {"x": 1}

ctx = multiprocessing.get_context("spawn")
queue = ctx.Queue()
process = ctx.Process(target=parse_in_spawned_process, args=(queue, parser, ['--dict={"x":2}']))
process.start()
process.join()

cfg = queue.get()
assert cfg.dict == {"x": 2}