Skip to content

AIP-81 Transition of Version Command #50919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
30 changes: 28 additions & 2 deletions airflow-ctl/src/airflowctl/ctl/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@


def lazy_load_command(import_path: str) -> Callable:
print("lazy load")
"""Create a lazy loader for command."""
_, _, name = import_path.rpartition(".")

Expand All @@ -55,11 +56,13 @@ def command(*args, **kwargs):
return func(*args, **kwargs)

command.__name__ = name
print(f"{command} and {command.__name__}")

return command


def safe_call_command(function: Callable, args: Iterable[Arg]) -> None:
print("safe")
try:
function(args)
except AirflowCtlCredentialNotFoundException as e:
Expand All @@ -75,7 +78,10 @@ class DefaultHelpParser(argparse.ArgumentParser):

def _check_value(self, action, value):
"""Override _check_value and check conditionally added command."""
print("chk value")
print(f"{action} value : {value}")
super()._check_value(action, value)
print("chk value afterrr")

def error(self, message):
"""Override error and use print_help instead of print_usage."""
Expand Down Expand Up @@ -110,6 +116,7 @@ def __init__(
self.kwargs[k] = v

def add_to_parser(self, parser: argparse.ArgumentParser):
print("add_to+parser")
"""Add this argument to an ArgumentParser."""
if "metavar" in self.kwargs and "type" not in self.kwargs:
if self.kwargs["metavar"] == "DIRPATH":
Expand All @@ -121,8 +128,10 @@ def type(x):
parser.add_argument(*self.flags, **self.kwargs)

def _is_valid_directory(self, parser, arg):
print("is valid")
if not os.path.isdir(arg):
parser.error(f"The directory '{arg}' does not exist!")
print(f"not excluded{arg}")
return arg


Expand Down Expand Up @@ -198,7 +207,6 @@ def __call__(self, parser, namespace, values, option_string=None):
nargs="?",
)


class ActionCommand(NamedTuple):
"""Single CLI command."""

Expand Down Expand Up @@ -233,6 +241,7 @@ class GroupCommandParser(NamedTuple):

@classmethod
def from_group_command(cls, group_command: GroupCommand) -> GroupCommandParser:
print(f"grop command parser{group_command.name} , {group_command.subcommands}")
"""Create GroupCommandParser from GroupCommand."""
return cls(
name=group_command.name,
Expand Down Expand Up @@ -300,7 +309,7 @@ def get_function_details(node: ast.FunctionDef, parent_node: ast.ClassDef) -> di
with open(self.file_path, encoding="utf-8") as file:
tree = ast.parse(file.read(), filename=self.file_path)

exclude_operation_names = ["LoginOperations"]
exclude_operation_names = ["LoginOperations", "VersionOperations"]
exclude_method_names = [
"error",
"__init__",
Expand Down Expand Up @@ -525,6 +534,8 @@ def merge_commands(
for command in commands_will_be_merged:
if isinstance(command, GroupCommand):
merge_command_map[command.name] = command
if isinstance(command, ActionCommand):
merge_command_map[command.name] = command
new_commands: list[CLICommand] = []
merged_commands = []
# Common commands
Expand Down Expand Up @@ -581,8 +592,23 @@ def merge_commands(
"Either pass token from environment variable/parameter or pass username and password.",
subcommands=AUTH_COMMANDS,
),
GroupCommand(
name = "version22",
help = "get latest ersion",
subcommands = "",
),
ActionCommand(
name="version",
help="Show version information",
description="Show version information",
func=lazy_load_command("airflowctl.ctl.commands.version_command.version_info"),
args=()
),

]
# Add generated group commands
core_commands = merge_commands(
base_commands=command_factory.group_commands, commands_will_be_merged=core_commands
)


33 changes: 33 additions & 0 deletions airflow-ctl/src/airflowctl/ctl/commands/version_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

from airflow.version import version
from airflow.utils.platform import get_airflow_git_version
from airflowctl.api.client import NEW_API_CLIENT, ClientKind, provide_api_client


@provide_api_client(kind=ClientKind.CLI)
def version_info(arg,api_client=NEW_API_CLIENT):
version_dict = {
"airflow_version": version,
"git_version": get_airflow_git_version(),
"airflowctl_version": version,
}

for name, value in version_dict.items():
print(f"{name} : {value}")
Loading