build_docs gh-linkcheck: Use Python, ignore links to master branch SUPPORT_POLICY.md
This commit is contained in:
parent
775448c792
commit
4bfd004c83
1 changed files with 22 additions and 17 deletions
|
@ -309,29 +309,34 @@ def call_linkcheck(entry):
|
||||||
return sphinx_call(*entry, buildername="linkcheck")
|
return sphinx_call(*entry, buildername="linkcheck")
|
||||||
|
|
||||||
|
|
||||||
GH_LINK_FILTER = ["https://github.com/espressif/esp-idf/tree",
|
# https://github.com/espressif/esp-idf/tree/
|
||||||
"https://github.com/espressif/esp-idf/blob",
|
# https://github.com/espressif/esp-idf/blob/
|
||||||
"https://github.com/espressif/esp-idf/raw"]
|
# https://github.com/espressif/esp-idf/raw/
|
||||||
|
GH_LINK_RE = r"https://github.com/espressif/esp-idf/(?:tree|blob|raw)/[^\s]+"
|
||||||
|
|
||||||
|
# we allow this one link, because we always want users to see the latest support policy
|
||||||
|
GH_LINK_ALLOWED = [ "https://github.com/espressif/esp-idf/blob/master/SUPPORT_POLICY.md" ]
|
||||||
|
|
||||||
def action_gh_linkcheck(args):
|
def action_gh_linkcheck(args):
|
||||||
print("Checking for hardcoded GitHub links\n")
|
print("Checking for hardcoded GitHub links\n")
|
||||||
|
|
||||||
find_args = ['find',
|
github_links = []
|
||||||
os.path.join(os.path.abspath(os.path.dirname(__file__)), ".."),
|
|
||||||
'-name',
|
|
||||||
'*.rst']
|
|
||||||
grep_args = ['xargs',
|
|
||||||
'grep',
|
|
||||||
r'\|'.join(GH_LINK_FILTER)]
|
|
||||||
|
|
||||||
p1 = subprocess.Popen(find_args, stdout=subprocess.PIPE)
|
docs_dir = os.path.relpath(os.path.dirname(__file__))
|
||||||
p2 = subprocess.Popen(grep_args, stdin=p1.stdout, stdout=subprocess.PIPE)
|
for root, _, files in os.walk(docs_dir):
|
||||||
p1.stdout.close()
|
if "_build" in root:
|
||||||
found_gh_links, _ = p2.communicate()
|
continue
|
||||||
if found_gh_links:
|
files = [ os.path.join(root, f) for f in files if f.endswith(".rst") ]
|
||||||
print(found_gh_links)
|
for path in files:
|
||||||
print("WARNINIG: Some .rst files contain hardcoded Github links.")
|
with open(path, "r") as f:
|
||||||
|
for link in re.findall(GH_LINK_RE, f.read()):
|
||||||
|
if link not in GH_LINK_ALLOWED:
|
||||||
|
github_links.append((path, link))
|
||||||
|
|
||||||
|
if github_links:
|
||||||
|
for path, link in github_links:
|
||||||
|
print("%s: %s" % (path, link))
|
||||||
|
print("WARNING: Some .rst files contain hardcoded Github links.")
|
||||||
print("Please check above output and replace links with one of the following:")
|
print("Please check above output and replace links with one of the following:")
|
||||||
print("- :idf:`dir` - points to directory inside ESP-IDF")
|
print("- :idf:`dir` - points to directory inside ESP-IDF")
|
||||||
print("- :idf_file:`file` - points to file inside ESP-IDF")
|
print("- :idf_file:`file` - points to file inside ESP-IDF")
|
||||||
|
|
Loading…
Reference in a new issue