mmdeploy/.github/scripts/doc_link_checker.py
tpoisonooo 5f59b4464f
docs(docs/zh_cn): update doc and link checker (#418)
* docs(docs/zh_cn): add doc and link checker

* docs(REAME): update

* docs(docs/zh_cn): update

* docs(benchmark): update table

* docs(zh_cn/benchmark): update link

* CI(docs): update link check

* ci(doc): update checker

* docs(zh_cn): update

* style(ci): remove useless para

* style(ci): update

* docs(zh_cn): update

* docs(benchmark.md): fix mobilnet link error

* docs(docs/zh_cn): add doc and link checker

* docs(REAME): update

* docs(docs/zh_cn): update

* docs(benchmark): update table

* docs(zh_cn/benchmark): update link

* CI(docs): update link check

* ci(doc): update checker

* docs(zh_cn): update

* style(ci): remove useless para

* style(ci): update

* docs(zh_cn): update

* docs(benchmark.md): fix mobilnet link error

* docs(zh_cn/do_regression_test.md): rebase

* docs(docs/zh_cn): add doc and link checker

* Update README_zh-CN.md

* Update README_zh-CN.md

* Update index.rst

* Update check-doc-link.yml

* [Fix] Fix ci (#426)

* fix ci

* add nvidia key

* remote torch

* recover pytorch

* ci(codecov): ignore ci

* docs(zh_cn): add get_started.md

* docs(zh_cn): fix review advice

* docs(readthedocs): update

* docs(zh_CN): update

* docs(zh_CN): revert

* fix(docs): review advices

* fix(docs): review advices

* fix(docs): review

Co-authored-by: q.yao <streetyao@live.com>
2022-05-09 10:18:10 +08:00

63 lines
1.8 KiB
Python

# Copyright (c) MegFlow. All rights reserved.
# /bin/python3
import argparse
import os
import re
def make_parser():
parser = argparse.ArgumentParser('Doc link checker')
parser.add_argument(
'--http', default=False, type=bool, help='check http or not ')
parser.add_argument(
'--dir', default='./docs', type=str, help='the directory to be check')
return parser
pattern = re.compile(r'\[.*?\]\(.*?\)')
def analyze_doc(home, path):
problem_list = []
with open(path) as f:
lines = f.readlines()
for line in lines:
if '[' in line and ']' in line and '(' in line and ')' in line:
all = pattern.findall(line)
for item in all:
start = item.find('(')
end = item.find(')')
ref = item[start + 1:end]
if ref.startswith('http') or ref.startswith('#'):
continue
if '.md#' in ref:
ref = ref[ref.find('#'):]
fullpath = os.path.join(home, ref)
if not os.path.exists(fullpath):
problem_list.append(ref)
else:
continue
if len(problem_list) > 0:
print(f'{path}:')
for item in problem_list:
print(f'\t {item}')
print('\n')
def traverse(_dir):
for home, dirs, files in os.walk(_dir):
if './target' in home or './.github' in home:
continue
for filename in files:
if filename.endswith('.md'):
path = os.path.join(home, filename)
if os.path.islink(path) is False:
analyze_doc(home, path)
if __name__ == '__main__':
args = make_parser().parse_args()
traverse(args.dir)