Skip to content

Use jsonargparse#9336

Draft
ThomasWaldmann wants to merge 5 commits intoborgbackup:masterfrom
ThomasWaldmann:use-jsonargparse
Draft

Use jsonargparse#9336
ThomasWaldmann wants to merge 5 commits intoborgbackup:masterfrom
ThomasWaldmann:use-jsonargparse

Conversation

@ThomasWaldmann
Copy link
Member

WIP

Replace stdlib argparse with jsonargparse for enhanced argument parsing,
using a compatibility layer in _argparse.py.

Key changes:

- Add _argparse.py: ArgumentParser subclass bridging Borg's argparse
  patterns with jsonargparse (type+action handling, namespace flattening)

- Switch from add_subparsers/add_parser to add_subcommands/add_subcommand
  across all command modules

- Replace set_defaults(func=) with COMMAND_DISPATCH table and get_func()

- Highlander: handle type conversion internally (BoundHighlander pattern)
  since jsonargparse forbids combining type= and action=

- TypeConvertingAction: wrapper for standard actions (append, store) that
  need type conversion

- Pattern actions: handle None paths/patterns from jsonargparse

- flatten_namespace: convert jsonargparse's nested subcommand namespaces
  to the flat namespace Borg's command handlers expect

- Update argparsing_test.py for dispatch table (get_func vs args.func)

Implemented by AI: Claude Opus 4.6 (Thinking).
@codecov
Copy link

codecov bot commented Feb 15, 2026

Codecov Report

❌ Patch coverage is 91.72185% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.15%. Comparing base (94d56e1) to head (2fcd54e).
⚠️ Report is 11 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/borg/helpers/jap_wrapper.py 80.24% 11 Missing and 5 partials ⚠️
src/borg/archiver/__init__.py 84.00% 4 Missing and 4 partials ⚠️
src/borg/patterns.py 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9336      +/-   ##
==========================================
+ Coverage   75.93%   76.15%   +0.22%     
==========================================
  Files          86       86              
  Lines       14780    14902     +122     
  Branches     2202     2226      +24     
==========================================
+ Hits        11223    11349     +126     
+ Misses       2880     2870      -10     
- Partials      677      683       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.
@ThomasWaldmann ThomasWaldmann mentioned this pull request Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant