mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-12 13:27:36 +00:00
ci: Add python types hints
This commit is contained in:
@@ -16,6 +16,7 @@ import urllib.error
|
||||
import urllib.request
|
||||
from collections import defaultdict, namedtuple
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
EXCLUDE_DOCS_LIST = ['examples/peripherals/secure_element/atecc608_ecdsa/components/esp-cryptoauthlib/cryptoauthlib/**']
|
||||
|
||||
@@ -26,28 +27,28 @@ Link = namedtuple('Link', ['file', 'url'])
|
||||
|
||||
|
||||
class ReadmeLinkError(Exception):
|
||||
def __init__(self, file, url):
|
||||
def __init__(self, file: str, url: str) -> None:
|
||||
self.file = file
|
||||
self.url = url
|
||||
|
||||
|
||||
class RelativeLinkError(ReadmeLinkError):
|
||||
def __str__(self):
|
||||
def __str__(self) -> str:
|
||||
return 'Relative link error, file - {} not found, linked from {}'.format(self.url, self.file)
|
||||
|
||||
|
||||
class UrlLinkError(ReadmeLinkError):
|
||||
def __init__(self, file, url, error_code):
|
||||
def __init__(self, file: str, url: str, error_code: str):
|
||||
self.error_code = error_code
|
||||
super().__init__(file, url)
|
||||
|
||||
def __str__(self):
|
||||
def __str__(self) -> str:
|
||||
files = [str(f) for f in self.file]
|
||||
return 'URL error, url - {} in files - {} is not accessible, request returned {}'.format(self.url, ', '.join(files), self.error_code)
|
||||
|
||||
|
||||
# we do not want a failed test just due to bad network conditions, for non 404 errors we simply print a warning
|
||||
def check_url(url, files, timeout):
|
||||
def check_url(url: str, files: str, timeout: float) -> None:
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=timeout):
|
||||
return
|
||||
@@ -60,7 +61,7 @@ def check_url(url, files, timeout):
|
||||
print('Unable to access {}, err = {}'.format(url, str(e)))
|
||||
|
||||
|
||||
def check_web_links(web_links):
|
||||
def check_web_links(web_links: defaultdict) -> List:
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
|
||||
errors = []
|
||||
@@ -74,7 +75,7 @@ def check_web_links(web_links):
|
||||
return errors
|
||||
|
||||
|
||||
def check_file_links(file_links):
|
||||
def check_file_links(file_links: List) -> List:
|
||||
errors = []
|
||||
|
||||
for link in file_links:
|
||||
@@ -87,10 +88,13 @@ def check_file_links(file_links):
|
||||
return errors
|
||||
|
||||
|
||||
def get_md_links(folder):
|
||||
def get_md_links(folder: str) -> List:
|
||||
MD_LINK_RE = r'\[.+?\]\((.+?)(#.+)?\)'
|
||||
|
||||
idf_path = Path(os.getenv('IDF_PATH'))
|
||||
idf_path_str = os.getenv('IDF_PATH')
|
||||
if idf_path_str is None:
|
||||
raise RuntimeError("Environment variable 'IDF_PATH' wasn't set.")
|
||||
idf_path = Path(idf_path_str)
|
||||
links = []
|
||||
|
||||
for path in (idf_path / folder).rglob('*.md'):
|
||||
@@ -110,7 +114,7 @@ def get_md_links(folder):
|
||||
return links
|
||||
|
||||
|
||||
def check_readme_links(args):
|
||||
def check_readme_links(args: argparse.Namespace) -> int:
|
||||
|
||||
links = get_md_links('examples')
|
||||
print('Found {} links'.format(len(links)))
|
||||
|
Reference in New Issue
Block a user