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
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Fixed
<https://github.com/omni-us/jsonargparse/pull/756>`__).
- Some deprecations not shown in the API documentation (`#760
<https://github.com/omni-us/jsonargparse/pull/760>`__).
- Environment variable names not shown in help for positional arguments when
``default_env`` is true (`#763
<https://github.com/omni-us/jsonargparse/pull/763>`__).

Changed
^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion jsonargparse/_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def _format_action_invocation(self, action: Action) -> str:
if parser.default_env:
value = f"ENV: {get_env_var(self, action)}\n\n {value}"
return value
if action.option_strings == [] or not parser.default_env:
if not parser.default_env:
return super()._format_action_invocation(action)
extr = ""
if not isinstance(action, (_ActionHelpClassPath, _ActionPrintConfig, ShtabAction, _HelpAction)):
Expand Down
9 changes: 9 additions & 0 deletions jsonargparse_tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ def test_parse_env_config(parser):
pytest.raises(ArgumentError, lambda: parser.parse_env({"APP_CFG": '{"undefined": True}'}))


def test_parse_env_positional():
parser = ArgumentParser(prog="app", exit_on_error=False, default_env=True)
parser.add_argument("pos", type=int)
with patch.dict(os.environ, {"APP_POS": "1"}):
assert parser.parse_env() == Namespace(pos=1)
with pytest.raises(ArgumentError, match="Got value: 1.1"):
parser.parse_env({"APP_POS": "1.1"})


def test_parse_env_positional_nargs_plus(parser):
parser.env_prefix = "app"
parser.add_argument("req", nargs="+")
Expand Down
7 changes: 7 additions & 0 deletions jsonargparse_tests/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def test_help_action_config_file(parser):
assert "APP_PRINT_CONFIG" not in help_str


def test_help_positional(parser):
parser.add_argument("pos")
help_str = get_parser_help(parser)
assert "ARG: pos" in help_str
assert "ENV: APP_POS" in help_str


def test_help_required_and_default(parser):
parser.add_argument("--v1", help="Option v1.", default="v1", required=True)
help_str = get_parser_help(parser)
Expand Down