Skip to content

Commit 874ff85

Browse files
committed
check-links: don't check external links by default
check-links checks external links. External services can be flaky, so we don't want to check external links in CI. Add an --all option which implements the current behavior, and default to only checking internal links.
1 parent c65764f commit 874ff85

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/check-links

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ def check_response(url) -> None:
6666

6767
class Crawler:
6868
def __init__(
69-
self, site, allowed_file_ext_for_soup=allowed_file_ext_for_soup
69+
self, site, check_external, allowed_file_ext_for_soup=allowed_file_ext_for_soup
7070
) -> None:
7171
self.site = site
72+
self.check_external = check_external
7273
self.allowed_file_ext_for_soup = allowed_file_ext_for_soup
7374
self.site_namespace = urlparse(self.site).netloc
7475
self.visted_urls = list()
@@ -106,7 +107,8 @@ class Crawler:
106107

107108
def start_crawl(self) -> None:
108109
self.crawl_and_report(self.site, self.urls)
109-
self.check_external_links(self.external_links_to_check)
110+
if self.check_external:
111+
self.check_external_links(self.external_links_to_check)
110112

111113
def get_urls_to_crawl(self, packet) -> list:
112114
urls_from_page = list()
@@ -182,12 +184,13 @@ class Crawler:
182184

183185
def main() -> None:
184186
parser = argparse.ArgumentParser()
187+
parser.add_argument("--all", action="store_true", help="check external links too")
185188
parser.add_argument("url", type=str)
186189
if len(sys.argv) == 1:
187190
parser.print_help()
188191
sys.exit(1)
189192
args = parser.parse_args()
190-
crawler = Crawler(args.url)
193+
crawler = Crawler(args.url, check_external=args.all)
191194
crawler.start_crawl()
192195

193196
if len(crawler.broken_links) > 0:

0 commit comments

Comments
 (0)