diff --git a/.github/scripts/find-unused-caches.py b/.github/scripts/find-unused-caches.py index cbeeb836..ffe11080 100644 --- a/.github/scripts/find-unused-caches.py +++ b/.github/scripts/find-unused-caches.py @@ -87,7 +87,7 @@ def main(repository: str, token: str, age_days: float = 7, output_file: str = "u from jsonargparse import auto_cli, set_parsing_settings set_parsing_settings(parse_optionals_as_positionals=True) - auto_cli(main) + auto_cli(main, as_positional=False) except ImportError: import sys diff --git a/CHANGELOG.md b/CHANGELOG.md index bfa9dd58..cc278a74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +--- + +## [Unreleased] - 2025-08-DD + +### Changed + +- + + +### Fixed + +- Scripts: fix CLI parsing ([#419](https://github.com/Lightning-AI/utilities/pull/419)) + + --- ## [0.15.0] - 2025-07-26 diff --git a/scripts/adjust-torch-versions.py b/scripts/adjust-torch-versions.py index d8a542f5..91c408a5 100644 --- a/scripts/adjust-torch-versions.py +++ b/scripts/adjust-torch-versions.py @@ -204,7 +204,7 @@ def main(requirements_path: str, torch_version: Optional[str] = None) -> None: from jsonargparse import auto_cli, set_parsing_settings set_parsing_settings(parse_optionals_as_positionals=True) - auto_cli(main) + auto_cli(main, as_positional=False) except (ModuleNotFoundError, ImportError): logging.warning( "Expected `jsonargparse` is not installed," diff --git a/scripts/inject-selector-script.py b/scripts/inject-selector-script.py index f6c203cf..663558f2 100644 --- a/scripts/inject-selector-script.py +++ b/scripts/inject-selector-script.py @@ -42,7 +42,7 @@ def main(folder: str, selector_name: str) -> None: from jsonargparse import auto_cli, set_parsing_settings set_parsing_settings(parse_optionals_as_positionals=True) - auto_cli(main) + auto_cli(main, as_positional=False) except (ModuleNotFoundError, ImportError): logging.warning( "Expected `jsonargparse` is not installed," diff --git a/tests/scripts/test_adjust_torch_versions.py b/tests/scripts/test_adjust_torch_versions.py index c7d58b62..2e4e440f 100644 --- a/tests/scripts/test_adjust_torch_versions.py +++ b/tests/scripts/test_adjust_torch_versions.py @@ -3,6 +3,8 @@ import subprocess import sys +import pytest + from scripts import _PATH_SCRIPTS REQUIREMENTS_SAMPLE = """ @@ -29,13 +31,22 @@ """ -def test_adjust_torch_versions_call(tmp_path) -> None: +@pytest.mark.parametrize("args", ["positional", "optional", "mixed"]) +def test_adjust_torch_versions_call(args, tmp_path) -> None: path_script = os.path.join(_PATH_SCRIPTS, "adjust-torch-versions.py") path_req_file = str(tmp_path / "requirements.txt") with open(path_req_file, "w", encoding="utf8") as fopen: fopen.write(REQUIREMENTS_SAMPLE) - return_code = subprocess.call([sys.executable, path_script, path_req_file, "1.10.0"]) # noqa: S603 + main_params = (("requirements_path", path_req_file), ("torch_version", "1.10.0")) + cli_call = [sys.executable, path_script] + if args == "positional": + cli_call += [value for _, value in main_params] + elif args == "optional": + cli_call += [f"--{key}={value}" for key, value in main_params] + elif args == "mixed": + cli_call += [main_params[0][1], f"--{main_params[1][0]}={main_params[1][1]}"] + return_code = subprocess.call(cli_call) # noqa: S603 assert return_code == 0 with open(path_req_file, encoding="utf8") as fopen: