Skip to content

Commit b1e0fa3

Browse files
committed
fix(cli): disable Click Windows glob expansion at entry point and fix Mypy type redefinition errors
1 parent 0092598 commit b1e0fa3

3 files changed

Lines changed: 16 additions & 50 deletions

File tree

src/google/adk/cli/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from .cli_tools_click import main
15+
from typing import Any
16+
17+
from .cli_tools_click import main as _main
18+
19+
20+
def main(args: Any = None, **kwargs: Any) -> Any:
21+
"""Package entry point that disables Windows glob expansion for all CLI commands."""
22+
23+
kwargs.setdefault("windows_expand_args", False)
24+
return _main.main(args=args, **kwargs)

src/google/adk/cli/cli_tools_click.py

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
import sys
2727
import tempfile
2828
import textwrap
29-
from typing import Any
30-
from typing import cast
29+
from typing import Optional
3130

3231
import click
3332
from click.core import ParameterSource
@@ -48,16 +47,6 @@
4847
case_sensitive=False,
4948
)
5049

51-
_ClickGroup = cast(type[Any], click.Group)
52-
53-
54-
class _NoWindowsGlobExpansionGroup(_ClickGroup):
55-
"""Click group that disables Windows glob expansion for CLI arguments."""
56-
57-
def main(self, *args: Any, **kwargs: Any) -> Any:
58-
kwargs.setdefault("windows_expand_args", False)
59-
return super().main(*args, **kwargs)
60-
6150

6251
def _logging_options():
6352
"""Decorator to add logging options to click commands."""
@@ -247,10 +236,7 @@ def _warn_if_with_ui(with_ui: bool) -> None:
247236
click.secho(f"WARNING: {_ADK_WEB_WARNING}", fg="yellow", err=True)
248237

249238

250-
@click.group(
251-
cls=_NoWindowsGlobExpansionGroup,
252-
context_settings={"max_content_width": 240},
253-
)
239+
@click.group(context_settings={"max_content_width": 240})
254240
@click.version_option(version.__version__)
255241
def main():
256242
"""Agent Development Kit CLI tools."""
@@ -1159,7 +1145,7 @@ def cli_eval(
11591145
inference_requests=inference_requests, eval_service=eval_service
11601146
)
11611147
)
1162-
eval_results = asyncio.run(
1148+
eval_results: list[EvalCaseResult] = asyncio.run(
11631149
_collect_eval_results(
11641150
inference_results=inference_results,
11651151
eval_service=eval_service,
@@ -1175,7 +1161,6 @@ def cli_eval(
11751161
eval_run_summary = {}
11761162

11771163
for eval_result in eval_results:
1178-
eval_result: EvalCaseResult
11791164

11801165
if eval_result.eval_set_id not in eval_run_summary:
11811166
eval_run_summary[eval_result.eval_set_id] = [0, 0]
@@ -1193,7 +1178,6 @@ def cli_eval(
11931178

11941179
if print_detailed_results:
11951180
for eval_result in eval_results:
1196-
eval_result: EvalCaseResult
11971181
click.echo(
11981182
"********************************************************************"
11991183
)
@@ -2015,7 +1999,6 @@ def cli_api_server(
20151999
"cloud_run",
20162000
context_settings={
20172001
"allow_extra_args": True,
2018-
"allow_interspersed_args": False,
20192002
},
20202003
)
20212004
@click.option(
@@ -2192,34 +2175,7 @@ def cli_deploy_cloud_run(
21922175

21932176
_warn_if_with_ui(with_ui)
21942177

2195-
# Parse arguments to separate gcloud args (after --) from regular args
2196-
gcloud_args = []
2197-
if "--" in ctx.args:
2198-
separator_index = ctx.args.index("--")
2199-
gcloud_args = ctx.args[separator_index + 1 :]
2200-
regular_args = ctx.args[:separator_index]
2201-
2202-
# If there are regular args before --, that's an error
2203-
if regular_args:
2204-
click.secho(
2205-
"Error: Unexpected arguments after agent path and before '--':"
2206-
f" {' '.join(regular_args)}. \nOnly arguments after '--' are passed"
2207-
" to gcloud.",
2208-
fg="red",
2209-
err=True,
2210-
)
2211-
ctx.exit(2)
2212-
else:
2213-
# No -- separator, treat all args as an error to enforce the new behavior
2214-
if ctx.args:
2215-
click.secho(
2216-
f"Error: Unexpected arguments: {' '.join(ctx.args)}. \nUse '--' to"
2217-
" separate gcloud arguments, e.g.: adk deploy cloud_run [options]"
2218-
" agent_path -- --min-instances=2",
2219-
fg="red",
2220-
err=True,
2221-
)
2222-
ctx.exit(2)
2178+
gcloud_args = ctx.args
22232179

22242180
try:
22252181
from . import cli_deploy

tests/unittests/cli/utils/test_cli_tools_click.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ def _mute_click(request, monkeypatch: pytest.MonkeyPatch) -> None:
9191
def test_main_disables_click_windows_glob_expansion() -> None:
9292
"""Verifies the ADK CLI disables Click's Windows glob expansion."""
9393
with mock.patch.object(click.Group, "main", return_value=None) as mock_main:
94-
cli_tools_click.main.main(args=["web", ".", "--allow_origins", "*"])
94+
from google.adk.cli import main
9595

96+
main(args=["web", ".", "--allow_origins", "*"])
9697
assert mock_main.call_args.kwargs["windows_expand_args"] is False
9798

9899

0 commit comments

Comments
 (0)