Skip to content

Commit 32d6ef9

Browse files
authored
Updated sorting commands in Typer 0.13+ (#2065)
1 parent 8be6006 commit 32d6ef9

File tree

11 files changed

+177
-163
lines changed

11 files changed

+177
-163
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies = [
3737
"snowflake-connector-python[secure-local-storage]==3.13.2",
3838
'snowflake-snowpark-python>=1.15.0,<1.26.0;python_version < "3.12"',
3939
"tomlkit==0.13.2",
40-
"typer==0.12.5",
40+
"typer==0.15.1",
4141
"urllib3>=1.24.3,<2.4",
4242
"GitPython==3.1.44",
4343
"pip",

snyk/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ snowflake.core==1.0.2; python_version < "3.12"
1010
snowflake-connector-python[secure-local-storage]==3.13.2
1111
snowflake-snowpark-python>=1.15.0,<1.26.0;python_version < "3.12"
1212
tomlkit==0.13.2
13-
typer==0.12.5
13+
typer==0.15.1
1414
urllib3>=1.24.3,<2.4
1515
GitPython==3.1.44
1616
pip

src/snowflake/cli/_app/commands_registration/builtin_plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_builtin_plugin_name_to_plugin_spec():
3434
"connection": connection_plugin_spec,
3535
"helpers": migrate_plugin_spec,
3636
"spcs": spcs_plugin_spec,
37-
"nativeapp": nativeapp_plugin_spec,
37+
"app": nativeapp_plugin_spec,
3838
"object": object_plugin_spec,
3939
"snowpark": snowpark_plugin_spec,
4040
"stage": stage_plugin_spec,

src/snowflake/cli/_app/commands_registration/command_plugins_loader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def __init__(self):
4747
self._loaded_command_paths: Dict[CommandPath, LoadedCommandPlugin] = {}
4848

4949
def register_builtin_plugins(self) -> None:
50-
for plugin_name, plugin in get_builtin_plugin_name_to_plugin_spec().items():
50+
for plugin_name, plugin in sorted(
51+
get_builtin_plugin_name_to_plugin_spec().items()
52+
):
5153
try:
5254
self._plugin_manager.register(plugin=plugin, name=plugin_name)
5355
except Exception as ex:

src/snowflake/cli/api/commands/snow_typer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from functools import wraps
2020
from typing import Any, Callable, Dict, List, Optional, Tuple
2121

22+
import click
2223
import typer
2324
from click import ClickException
2425
from snowflake.cli.api.commands.decorators import (
@@ -35,10 +36,20 @@
3536
from snowflake.cli.api.sanitizers import sanitize_for_terminal
3637
from snowflake.cli.api.sql_execution import SqlExecutionMixin
3738
from snowflake.connector import DatabaseError
39+
from typer.core import TyperGroup
3840

3941
log = logging.getLogger(__name__)
4042

4143

44+
class SortedTyperGroup(TyperGroup):
45+
def list_commands(self, ctx: click.Context) -> List[str]:
46+
"""
47+
From Typer 0.13.0 help items are in order of definition, this function override that approach.
48+
Returns a list of subcommand names in the alphabetic order.
49+
"""
50+
return sorted(self.commands)
51+
52+
4253
class SnowTyper(typer.Typer):
4354
def __init__(self, /, **kwargs):
4455
self._sanitize_kwargs(kwargs)
@@ -49,6 +60,7 @@ def __init__(self, /, **kwargs):
4960
no_args_is_help=True,
5061
add_completion=True,
5162
rich_markup_mode="markdown",
63+
cls=SortedTyperGroup,
5264
)
5365

5466
@staticmethod

tests/__snapshots__/test_help_messages.ambr

Lines changed: 150 additions & 150 deletions
Large diffs are not rendered by default.

tests/__snapshots__/test_sql.ambr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# name: test_sql_help_if_no_query_file_or_stdin
33
'''
44

5-
Usage: default sql [OPTIONS]
5+
Usage: root sql [OPTIONS]
66

77
Executes Snowflake query.
88
Use either query, filename or input option. Query to execute can be specified

tests/api/commands/__snapshots__/test_flags.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# serializer version: 1
22
# name: test_format
33
'''
4-
Usage: default stage list-files [OPTIONS] STAGE_NAME
5-
Try 'default stage list-files --help' for help.
4+
Usage: root stage list-files [OPTIONS] STAGE_NAME
5+
Try 'root stage list-files --help' for help.
66
+- Error ----------------------------------------------------------------------+
77
| Invalid value for '--format': 'invalid_format' is not one of 'TABLE', |
88
| 'JSON'. |

tests/object/__snapshots__/test_object.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@
439439
# ---
440440
# name: test_replace_and_not_exists_cannot_be_used_together
441441
'''
442-
Usage: default object create [OPTIONS] OBJECT_TYPE [OBJECT_ATTRIBUTES]...
443-
Try 'default object create --help' for help.
442+
Usage: root object create [OPTIONS] OBJECT_TYPE [OBJECT_ATTRIBUTES]...
443+
Try 'root object create --help' for help.
444444
+- Error ----------------------------------------------------------------------+
445445
| Parameters '--if-not-exists' and '--replace' are incompatible and cannot be |
446446
| used simultaneously. |

tests/spcs/__snapshots__/test_image_repository.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# ---
1212
# name: test_create_cli_replace_and_if_not_exists_fails
1313
'''
14-
Usage: default spcs image-repository create [OPTIONS] NAME
15-
Try 'default spcs image-repository create --help' for help.
14+
Usage: root spcs image-repository create [OPTIONS] NAME
15+
Try 'root spcs image-repository create --help' for help.
1616
+- Error ----------------------------------------------------------------------+
1717
| Parameters '--if-not-exists' and '--replace' are incompatible and cannot be |
1818
| used simultaneously. |

0 commit comments

Comments
 (0)