Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/airflow/utils/docs.py: 17%

29 statements  

« prev     ^ index     » next       coverage.py v7.0.1, created at 2022-12-25 06:11 +0000

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 

19try: 

20 import importlib_metadata 

21except ImportError: 

22 from importlib import metadata as importlib_metadata # type: ignore[no-redef] 

23 

24 

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

26 """Prepare link to Airflow documentation.""" 

27 from airflow.version import version 

28 

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

30 result = ( 

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

32 ) 

33 else: 

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

35 if page: 

36 result = result + page 

37 return result 

38 

39 

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

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

42 try: 

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

44 if isinstance(metadata_items, str): 

45 metadata_items = [metadata_items] 

46 if metadata_items: 

47 for item in metadata_items: 

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

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

50 if url: 

51 return url.strip() 

52 except importlib_metadata.PackageNotFoundError: 

53 pass 

54 # Fallback if provider is apache one 

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

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

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