Skip to content

Commit a98461a

Browse files
author
Jon Wayne Parrott
authored
Add a staging area for new tutorials (pypa#333)
1 parent 645e936 commit a98461a

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

scripts/linkmonitor/ignored.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
sources:
2+
- glob: new-tutorials/*
3+
reason: new tutorial staging
4+
urls:
15
- url: plugin_discovery.html#plugin-creation-and-discovery
26
reason: named link to first header
37
- url: single_source_version.html#single-sourcing-the-project-version

scripts/linkmonitor/linkmonitor.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# http://creativecommons.org/licenses/by-sa/3.0.
55

66
import argparse
7+
from fnmatch import fnmatch
78
from glob import glob
89
import io
910
import os
@@ -18,9 +19,9 @@
1819
IGNORED_FILENAME = os.path.join(HERE, 'ignored.yaml')
1920
ROOT = os.path.abspath(os.path.join(HERE, '..', '..'))
2021
HTML_DIR = os.path.join(ROOT, 'build', 'html')
21-
IGNORED_FILES = [
22+
IGNORED_FILES = set([
2223
'genindex.html'
23-
]
24+
])
2425

2526

2627
def find_all_named_anchors(filename):
@@ -61,9 +62,13 @@ def find_all_named_anchors_in_files(files):
6162
return links
6263

6364

64-
def find_links():
65+
def find_links(ignored_files):
6566
files = glob('**/*.html', recursive=True)
66-
files = filter(lambda name: name not in IGNORED_FILES, files)
67+
ignored_files = ignored_files | IGNORED_FILES
68+
files = [
69+
filename for filename in files
70+
if not any(
71+
[fnmatch(filename, pattern) for pattern in ignored_files])]
6772
return find_all_named_anchors_in_files(files)
6873

6974

@@ -87,7 +92,9 @@ def load_redirects():
8792
def load_ignored():
8893
with io.open(IGNORED_FILENAME, 'r') as ignored_file:
8994
raw = yaml.load(ignored_file)
90-
return set([entry['url'] for entry in raw])
95+
sources = set([entry['glob'] for entry in raw['sources']])
96+
urls = set([entry['url'] for entry in raw['urls']])
97+
return sources, urls
9198

9299

93100
def expand_redirects(redirects, inventory, ignored):
@@ -152,11 +159,11 @@ def check_command(args):
152159
# TODO: Add another file to list currently defined redirects.
153160
inventory = load_inventory()
154161
redirects = load_redirects()
155-
ignored = load_ignored()
156-
links = find_links()
162+
ignored_sources, ignored_urls = load_ignored()
163+
links = find_links(ignored_sources)
157164

158165
valid_redirects, missing_redirects = expand_redirects(
159-
redirects, inventory, ignored)
166+
redirects, inventory, ignored_urls)
160167
if missing_redirects:
161168
print(
162169
'The following redirects are missing deep link anchors in the '
@@ -169,7 +176,7 @@ def check_command(args):
169176

170177
ignored_links = set()
171178
for link in missing_links:
172-
for source_url in ignored:
179+
for source_url in ignored_urls:
173180
if link.startswith(source_url):
174181
ignored_links.add(link)
175182

source/new-tutorials/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:orphan:
2+
3+
New Tutorials
4+
=============
5+
6+
.. warning:: This section is for work-in-progress tutorials! These will
7+
eventually be promoted to the :doc:`/tutorials/index` section.
8+
Do not link to these pages!

0 commit comments

Comments
 (0)