This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 879fd34e97 aDd documentation generation for CLI commands from
executors (#33081)
879fd34e97 is described below
commit 879fd34e97a5343e6d2bbf3d5373831b9641b5ad
Author: Jarek Potiuk <[email protected]>
AuthorDate: Fri Aug 4 19:26:49 2023 +0200
aDd documentation generation for CLI commands from executors (#33081)
The #29055 moved relevant CLI command definition to executors but
it automatically removed the command from generated documentation.
This PR brings it back for both Celery and Cncf Kubernetes provider
Closes: #27932
---
airflow/executors/base_executor.py | 17 ++++++++++++++-
.../providers/celery/executors/celery_executor.py | 9 ++++++++
.../kubernetes/executors/kubernetes_executor.py | 9 ++++++++
docs/apache-airflow-providers-celery/cli-ref.rst | 24 ++++++++++++++++++++++
docs/apache-airflow-providers-celery/index.rst | 1 +
.../cli-ref.rst | 24 ++++++++++++++++++++++
.../index.rst | 1 +
7 files changed, 84 insertions(+), 1 deletion(-)
diff --git a/airflow/executors/base_executor.py
b/airflow/executors/base_executor.py
index 999125afe7..81b5364479 100644
--- a/airflow/executors/base_executor.py
+++ b/airflow/executors/base_executor.py
@@ -17,6 +17,7 @@
"""Base executor - this is the base class for all the implemented executors."""
from __future__ import annotations
+import argparse
import logging
import sys
import warnings
@@ -27,7 +28,7 @@ from typing import TYPE_CHECKING, Any, List, Optional,
Sequence, Tuple
import pendulum
-from airflow.cli.cli_config import GroupCommand
+from airflow.cli.cli_config import DefaultHelpParser, GroupCommand
from airflow.configuration import conf
from airflow.exceptions import RemovedInAirflow3Warning
from airflow.stats import Stats
@@ -489,3 +490,17 @@ class BaseExecutor(LoggingMixin):
be commands to setup/teardown the executor, inspect state, etc.
"""
return []
+
+ @classmethod
+ def _get_parser(cls) -> argparse.ArgumentParser:
+ """This method is used by Sphinx argparse to generate documentation.
+
+ :meta private:
+ """
+ from airflow.cli.cli_parser import AirflowHelpFormatter, _add_command
+
+ parser = DefaultHelpParser(prog="airflow",
formatter_class=AirflowHelpFormatter)
+ subparsers = parser.add_subparsers(dest="subcommand",
metavar="GROUP_OR_COMMAND")
+ for group_command in cls.get_cli_commands():
+ _add_command(subparsers, group_command)
+ return parser
diff --git a/airflow/providers/celery/executors/celery_executor.py
b/airflow/providers/celery/executors/celery_executor.py
index 51287f3c1b..ba1af78ec4 100644
--- a/airflow/providers/celery/executors/celery_executor.py
+++ b/airflow/providers/celery/executors/celery_executor.py
@@ -23,6 +23,7 @@
"""
from __future__ import annotations
+import argparse
import logging
import math
import operator
@@ -480,3 +481,11 @@ class CeleryExecutor(BaseExecutor):
subcommands=CELERY_COMMANDS,
),
]
+
+
+def _get_parser() -> argparse.ArgumentParser:
+ """This method is used by Sphinx to generate documentation.
+
+ :meta private:
+ """
+ return CeleryExecutor._get_parser()
diff --git a/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py
b/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py
index a5aa36d981..d9f281813b 100644
--- a/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py
+++ b/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py
@@ -23,6 +23,7 @@ KubernetesExecutor.
"""
from __future__ import annotations
+import argparse
import json
import logging
import multiprocessing
@@ -727,3 +728,11 @@ class KubernetesExecutor(BaseExecutor):
subcommands=KUBERNETES_COMMANDS,
)
]
+
+
+def _get_parser() -> argparse.ArgumentParser:
+ """This method is used by Sphinx to generate documentation.
+
+ :meta private:
+ """
+ return KubernetesExecutor._get_parser()
diff --git a/docs/apache-airflow-providers-celery/cli-ref.rst
b/docs/apache-airflow-providers-celery/cli-ref.rst
new file mode 100644
index 0000000000..4a3b4074be
--- /dev/null
+++ b/docs/apache-airflow-providers-celery/cli-ref.rst
@@ -0,0 +1,24 @@
+ .. 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.
+
+Celery Executor Commands
+------------------------
+
+.. argparse::
+ :module: airflow.providers.celery.executors.celery_executor
+ :func: _get_parser
+ :prog: airflow
diff --git a/docs/apache-airflow-providers-celery/index.rst
b/docs/apache-airflow-providers-celery/index.rst
index 88a2a0ddd3..af6371aa53 100644
--- a/docs/apache-airflow-providers-celery/index.rst
+++ b/docs/apache-airflow-providers-celery/index.rst
@@ -35,6 +35,7 @@
:caption: References
Configuration <configurations-ref>
+ CLI <cli-ref>
Python API <_api/airflow/providers/celery/index>
PyPI Repository <https://pypi.org/project/apache-airflow-providers-celery/>
Installing from sources <installing-providers-from-sources>
diff --git a/docs/apache-airflow-providers-cncf-kubernetes/cli-ref.rst
b/docs/apache-airflow-providers-cncf-kubernetes/cli-ref.rst
new file mode 100644
index 0000000000..88497a1748
--- /dev/null
+++ b/docs/apache-airflow-providers-cncf-kubernetes/cli-ref.rst
@@ -0,0 +1,24 @@
+ .. 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.
+
+Kubernetes Executor Commands
+============================
+
+.. argparse::
+ :module: airflow.providers.cncf.kubernetes.executors.kubernetes_executor
+ :func: _get_parser
+ :prog: airflow
diff --git a/docs/apache-airflow-providers-cncf-kubernetes/index.rst
b/docs/apache-airflow-providers-cncf-kubernetes/index.rst
index 59af13dd9f..61ce4fb714 100644
--- a/docs/apache-airflow-providers-cncf-kubernetes/index.rst
+++ b/docs/apache-airflow-providers-cncf-kubernetes/index.rst
@@ -43,6 +43,7 @@
:caption: References
Configuration <configurations-ref>
+ CLI <cli-ref>
Python API <_api/airflow/providers/cncf/kubernetes/index>
.. toctree::