Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/utils/docs.py: 21%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

29 statements  

1# Licensed to the Apache Software Foundation (ASF) under one 

2# or more contributor license agreements. See the NOTICE file 

3# distributed with this work for additional information 

4# regarding copyright ownership. The ASF licenses this file 

5# to you under the Apache License, Version 2.0 (the 

6# "License"); you may not use this file except in compliance 

7# with the License. You may obtain a copy of the License at 

8# 

9# http://www.apache.org/licenses/LICENSE-2.0 

10# 

11# Unless required by applicable law or agreed to in writing, 

12# software distributed under the License is distributed on an 

13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 

14# KIND, either express or implied. See the License for the 

15# specific language governing permissions and limitations 

16# under the License. 

17from __future__ import annotations 

18 

19import sys 

20 

21if sys.version_info >= (3, 10): 

22 from importlib import metadata 

23else: 

24 import importlib_metadata as metadata # type: ignore[no-redef] 

25 

26 

27def get_docs_url(page: str | None = None) -> str: 

28 """Prepare link to Airflow documentation.""" 

29 from airflow.version import version 

30 

31 if any(suffix in version for suffix in ["dev", "a", "b"]): 

32 result = ( 

33 "http://apache-airflow-docs.s3-website.eu-central-1.amazonaws.com/docs/apache-airflow/stable/" 

34 ) 

35 else: 

36 result = f"https://airflow.apache.org/docs/apache-airflow/{version}/" 

37 if page: 

38 result = result + page 

39 return result 

40 

41 

42def get_doc_url_for_provider(provider_name: str, provider_version: str) -> str: 

43 """Prepare link to Airflow Provider documentation.""" 

44 try: 

45 metadata_items = metadata.metadata(provider_name).get_all("Project-URL") 

46 if isinstance(metadata_items, str): 

47 metadata_items = [metadata_items] 

48 if metadata_items: 

49 for item in metadata_items: 

50 if item.lower().startswith("documentation"): 

51 _, _, url = item.partition(",") 

52 if url: 

53 return url.strip() 

54 except metadata.PackageNotFoundError: 

55 pass 

56 # Fallback if provider is apache one 

57 if provider_name.startswith("apache-airflow"): 

58 return f"https://airflow.apache.org/docs/{provider_name}/{provider_version}/" 

59 return "https://airflow.apache.org/docs/apache-airflow-providers/index.html#creating-your-own-providers"