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 7064a95a64 Fallback Provider's doc URL to "Documentation" meta-data
(#23012)
7064a95a64 is described below
commit 7064a95a648286a4190a452425626c159e467d6e
Author: Jarek Potiuk <[email protected]>
AuthorDate: Fri Apr 22 15:21:47 2022 +0200
Fallback Provider's doc URL to "Documentation" meta-data (#23012)
When Airflow displays provider's Doc URLs it builds the
URL to documentation for community providers but for third party
providers it was wrong.
With this change:
* if provider already has Documentation standard Project-URL
metadata, Airflow will use it
* if provider is an "apache-airflow" one, it will dynamically
build the URL from provider info
* if neither of two is available it will direct user to the
place in documentation where requirements for custom providers
are explained
Fixes: ##22248
---
airflow/utils/docs.py | 22 +++++++++++++++++++++-
docs/apache-airflow-providers/index.rst | 3 +++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/airflow/utils/docs.py b/airflow/utils/docs.py
index 5ff0c946dd..6b50beed5f 100644
--- a/airflow/utils/docs.py
+++ b/airflow/utils/docs.py
@@ -19,6 +19,11 @@ from typing import Optional
from airflow import version
+try:
+ import importlib_metadata
+except ImportError:
+ from importlib import metadata as importlib_metadata # type:
ignore[no-redef]
+
def get_docs_url(page: Optional[str] = None) -> str:
"""Prepare link to Airflow documentation."""
@@ -35,4 +40,19 @@ def get_docs_url(page: Optional[str] = None) -> str:
def get_doc_url_for_provider(provider_name: str, provider_version: str) -> str:
"""Prepare link to Airflow Provider documentation."""
- return
f'https://airflow.apache.org/docs/{provider_name}/{provider_version}/'
+ try:
+ metadata_items =
importlib_metadata.metadata(provider_name).get_all("Project-URL")
+ if isinstance(metadata_items, str):
+ metadata_items = [metadata_items]
+ if metadata_items:
+ for item in metadata_items:
+ if item.lower().startswith('documentation'):
+ _, _, url = item.partition(",")
+ if url:
+ return url.strip()
+ except importlib_metadata.PackageNotFoundError:
+ pass
+ # Fallback if provider is apache one
+ if provider_name.startswith("apache-airflow"):
+ return
f'https://airflow.apache.org/docs/{provider_name}/{provider_version}/'
+ return
"https://airflow.apache.org/docs/apache-airflow-providers/index.html#creating-your-own-providers"
diff --git a/docs/apache-airflow-providers/index.rst
b/docs/apache-airflow-providers/index.rst
index cda13cbdab..9577e694b9 100644
--- a/docs/apache-airflow-providers/index.rst
+++ b/docs/apache-airflow-providers/index.rst
@@ -280,6 +280,9 @@ You need to do the following to turn an existing Python
package into a provider
the required provider metadata
* Create the function that you refer to in the first step as part of your
package: this functions returns a
dictionary that contains all meta-data about your provider package
+* If you want Airflow to link to documentation of your Provider in the
providers page, make sure
+ to add "project-url/documentation" `metadata
<https://peps.python.org/pep-0621/#example>`_ to your package.
+ This will also add link to your documentation in PyPI.
* note that the dictionary should be compliant with
``airflow/provider_info.schema.json`` JSON-schema
specification. The community-managed providers have more fields there that
are used to build
documentation, but the requirement for runtime information only contains
several fields which are defined