Skip to content

Commit 2fcd54e

Browse files
Fix jsonargparse ValueError on Windows CI by using custom ArgumentGroup
Refactor jap_wrapper.py to explicitly define a custom ArgumentGroup class instead of relying on jsonargparse's dynamic subclass generation. jsonargparse attempts to create an ArgumentGroup subclass that inherits add_argument from the parser by reading source code with inspect.getsource(). This mechanism is fragile and can fail on Windows CI (and likely frozen binaries), causing it to fall back to the standard ArgumentGroup. When falling back, the standard ArgumentGroup lacks our add_argument wrapper that strips type when action is present. This results in ValueError: Providing both type and action not allowed because jsonargparse forbids this combination. By explicitly defining ArgumentGroup with our mixin and setting self._group_class, we ensure our compatibility logic is always used.
1 parent 7c35724 commit 2fcd54e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/borg/helpers/jap_wrapper.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import argparse
1919

2020
from jsonargparse import ArgumentParser as _JAPArgumentParser
21+
from jsonargparse._core import ArgumentGroup as _JAPArgumentGroup
2122

2223

2324
def _is_highlander_action(action):
@@ -56,8 +57,8 @@ def __call__(self, parser, namespace, values, option_string=None):
5657
return TypeConvertingAction
5758

5859

59-
class ArgumentParser(_JAPArgumentParser):
60-
"""ArgumentParser bridging Borg's argparse patterns with jsonargparse."""
60+
class BorgAddArgumentMixin:
61+
"""Mixin to provide Borg's add_argument logic to ArgumentParser and ArgumentGroup."""
6162

6263
def add_argument(self, *args, **kwargs):
6364
"""Handle type+action combination that jsonargparse forbids.
@@ -108,6 +109,22 @@ class BoundHighlander(action_cls):
108109
return super().add_argument(*args, **kwargs)
109110

110111

112+
class ArgumentGroup(BorgAddArgumentMixin, _JAPArgumentGroup):
113+
"""ArgumentGroup that supports Borg's add_argument patterns."""
114+
115+
pass
116+
117+
118+
class ArgumentParser(BorgAddArgumentMixin, _JAPArgumentParser):
119+
"""ArgumentParser bridging Borg's argparse patterns with jsonargparse."""
120+
121+
def __init__(self, *args, **kwargs):
122+
super().__init__(*args, **kwargs)
123+
# Force jsonargparse to use our ArgumentGroup class instead of trying to
124+
# auto-generate one from source code (which is fragile and fails on Windows CI).
125+
self._group_class = ArgumentGroup
126+
127+
111128
def flatten_namespace(args):
112129
"""Flatten jsonargparse's nested namespace into a flat one.
113130

0 commit comments

Comments
 (0)