Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19b3e00

Browse files
committed
Fix the suspicious builder not to write CRLF, update suspicious file and add instructions to Makefile.
1 parent 682d7e0 commit 19b3e00

3 files changed

Lines changed: 191 additions & 27 deletions

File tree

Doc/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,27 @@ changes: build
8787

8888
linkcheck: BUILDER = linkcheck
8989
linkcheck: build
90-
@echo "Link check complete; look for any errors in the above output " \
90+
@echo "Link check complete; look for any errors in the above output" \
9191
"or in build/$(BUILDER)/output.txt"
9292

9393
suspicious: BUILDER = suspicious
9494
suspicious: build
95-
@echo "Suspicious check complete; look for any errors in the above output " \
96-
"or in build/$(BUILDER)/suspicious.txt"
95+
@echo "Suspicious check complete; look for any errors in the above output" \
96+
"or in build/$(BUILDER)/suspicious.csv. If all issues are false" \
97+
"positives, append that file to tools/sphinxext/susp-ignored.csv."
9798

9899
coverage: BUILDER = coverage
99100
coverage: build
100101
@echo "Coverage finished; see c.txt and python.txt in build/coverage"
101102

102103
doctest: BUILDER = doctest
103104
doctest: build
104-
@echo "Testing of doctests in the sources finished, look at the " \
105+
@echo "Testing of doctests in the sources finished, look at the" \
105106
"results in build/doctest/output.txt"
106107

107108
pydoc-topics: BUILDER = pydoc-topics
108109
pydoc-topics: build
109-
@echo "Building finished; now copy build/pydoc-topics/topics.py " \
110+
@echo "Building finished; now copy build/pydoc-topics/topics.py" \
110111
"to Lib/pydoc_data/topics.py"
111112

112113
htmlview: html

Doc/tools/sphinxext/susp-ignored.csv

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,160 @@ whatsnew/2.4,,:System,
164164
whatsnew/2.5,,:memory,:memory:
165165
whatsnew/2.5,,:step,[start:stop:step]
166166
whatsnew/2.5,,:stop,[start:stop:step]
167+
distutils/examples,267,`,This is the description of the ``foobar`` package.
168+
documenting/fromlatex,39,:func,:func:`str(object)`
169+
documenting/fromlatex,39,`,:func:`str(object)`
170+
documenting/fromlatex,39,`,``str(object)``
171+
documenting/fromlatex,55,.. deprecated:,.. deprecated:: 2.5
172+
documenting/fromlatex,66,.. note:,.. note::
173+
documenting/fromlatex,76,:samp,":samp:`open({filename}, {mode})`"
174+
documenting/fromlatex,76,`,":samp:`open({filename}, {mode})`"
175+
documenting/fromlatex,80,`,``'c'``
176+
documenting/fromlatex,80,`,`Title <URL>`_
177+
documenting/fromlatex,80,`,``code``
178+
documenting/fromlatex,80,`,`Title <URL>`_
179+
documenting/fromlatex,99,:file,:file:`C:\\Temp\\my.tmp`
180+
documenting/fromlatex,99,`,:file:`C:\\Temp\\my.tmp`
181+
documenting/fromlatex,99,`,"``open(""C:\Temp\my.tmp"")``"
182+
documenting/fromlatex,129,.. function:,.. function:: do_foo(bar)
183+
documenting/fromlatex,141,.. function:,".. function:: open(filename[, mode[, buffering]])"
184+
documenting/fromlatex,152,.. function:,.. function:: foo_*
185+
documenting/fromlatex,152,:noindex,:noindex:
186+
documenting/fromlatex,162,.. describe:,.. describe:: a == b
187+
documenting/fromlatex,168,.. cmdoption:,.. cmdoption:: -O
188+
documenting/fromlatex,168,.. envvar:,.. envvar:: PYTHONINSPECT
189+
documenting/markup,33,.. sectionauthor:,.. sectionauthor:: Guido van Rossum <[email protected]>
190+
documenting/markup,42,:mod,:mod:`parrot` -- Dead parrot access
191+
documenting/markup,42,`,:mod:`parrot` -- Dead parrot access
192+
documenting/markup,42,.. module:,.. module:: parrot
193+
documenting/markup,42,:platform,":platform: Unix, Windows"
194+
documenting/markup,42,:synopsis,:synopsis: Analyze and reanimate dead parrots.
195+
documenting/markup,42,.. moduleauthor:,.. moduleauthor:: Eric Cleese <[email protected]>
196+
documenting/markup,42,.. moduleauthor:,.. moduleauthor:: John Idle <[email protected]>
197+
documenting/markup,88,:noindex,:noindex:
198+
documenting/markup,95,.. function:,.. function:: spam(eggs)
199+
documenting/markup,95,:noindex,:noindex:
200+
documenting/markup,101,.. method:,.. method:: FileInput.input(...)
201+
documenting/markup,121,:function,c:function
202+
documenting/markup,121,.. c:,".. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)"
203+
documenting/markup,121,::,".. c:function:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)"
204+
documenting/markup,131,:member,c:member
205+
documenting/markup,131,.. c:,.. c:member:: PyObject* PyTypeObject.tp_bases
206+
documenting/markup,131,::,.. c:member:: PyObject* PyTypeObject.tp_bases
207+
documenting/markup,139,:macro,c:macro
208+
documenting/markup,143,:type,c:type
209+
documenting/markup,150,:var,c:var
210+
documenting/markup,150,.. cvar:,.. cvar:: PyObject* PyClass_Type
211+
documenting/markup,179,.. function:,".. function:: Timer.repeat([repeat=3[, number=1000000]])"
212+
documenting/markup,210,.. decorator:,.. decorator:: removename
213+
documenting/markup,210,.. decorator:,.. decorator:: setnewname(name)
214+
documenting/markup,210,:func,:func:
215+
documenting/markup,233,:meth,:meth:
216+
documenting/markup,246,.. cmdoption:,.. cmdoption:: -m <module>
217+
documenting/markup,264,.. describe:,.. describe:: opcode
218+
documenting/markup,293,.. highlightlang:,.. highlightlang:: c
219+
documenting/markup,313,.. literalinclude:,.. literalinclude:: example.py
220+
documenting/markup,328,:rolename,:rolename:`content`
221+
documenting/markup,328,`,:rolename:`content`
222+
documenting/markup,333,:role,:role:`title <target>`
223+
documenting/markup,333,`,:role:`title <target>`
224+
documenting/markup,339,:meth,:meth:`~Queue.Queue.get`
225+
documenting/markup,339,`,:meth:`~Queue.Queue.get`
226+
documenting/markup,387,:func,:func:`filter`
227+
documenting/markup,387,`,:func:`filter`
228+
documenting/markup,387,:func,:func:`foo.filter`
229+
documenting/markup,387,`,:func:`foo.filter`
230+
documenting/markup,393,:func,:func:`open`
231+
documenting/markup,393,`,:func:`open`
232+
documenting/markup,393,:func,:func:`.open`
233+
documenting/markup,393,`,:func:`.open`
234+
documenting/markup,409,:data,c:data
235+
documenting/markup,413,:func,c:func
236+
documenting/markup,417,:macro,c:macro
237+
documenting/markup,421,:type,c:type
238+
documenting/markup,426,:member,c:member
239+
documenting/markup,476,:file,... is installed in :file:`/usr/lib/python2.{x}/site-packages` ...
240+
documenting/markup,476,`,... is installed in :file:`/usr/lib/python2.{x}/site-packages` ...
241+
documenting/markup,495,:kbd,:kbd:`C-x C-f`
242+
documenting/markup,495,`,:kbd:`C-x C-f`
243+
documenting/markup,495,:kbd,:kbd:`Control-x Control-f`
244+
documenting/markup,495,`,:kbd:`Control-x Control-f`
245+
documenting/markup,509,:mailheader,:mailheader:`Content-Type`
246+
documenting/markup,509,`,:mailheader:`Content-Type`
247+
documenting/markup,518,:manpage,:manpage:`ls(1)`
248+
documenting/markup,518,`,:manpage:`ls(1)`
249+
documenting/markup,534,:menuselection,:menuselection:`Start --> Programs`
250+
documenting/markup,534,`,:menuselection:`Start --> Programs`
251+
documenting/markup,549,`,``code``
252+
documenting/markup,567,:file,:file:
253+
documenting/markup,567,`,``code``
254+
documenting/markup,602,:ref,:ref:`label-name`
255+
documenting/markup,602,`,:ref:`label-name`
256+
documenting/markup,606,:ref,"It refers to the section itself, see :ref:`my-reference-label`."
257+
documenting/markup,606,`,"It refers to the section itself, see :ref:`my-reference-label`."
258+
documenting/markup,615,:ref,:ref:
259+
documenting/markup,636,.. note:,.. note::
260+
documenting/markup,663,.. versionadded:,.. versionadded:: 3.1
261+
documenting/markup,688,::,.. impl-detail::
262+
documenting/markup,688,::,.. impl-detail:: This shortly mentions an implementation detail.
263+
documenting/markup,708,.. seealso:,.. seealso::
264+
documenting/markup,708,:mod,Module :mod:`zipfile`
265+
documenting/markup,708,`,Module :mod:`zipfile`
266+
documenting/markup,708,:mod,Documentation of the :mod:`zipfile` standard module.
267+
documenting/markup,708,`,Documentation of the :mod:`zipfile` standard module.
268+
documenting/markup,708,`,"`GNU tar manual, Basic Tar Format <http://link>`_"
269+
documenting/markup,722,.. centered:,.. centered::
270+
documenting/markup,767,.. toctree:,.. toctree::
271+
documenting/markup,767,:maxdepth,:maxdepth: 2
272+
documenting/markup,783,.. index:,.. index::
273+
documenting/markup,813,.. index:,".. index:: BNF, grammar, syntax, notation"
274+
documenting/markup,844,`,"unaryneg ::= ""-"" `integer`"
275+
documenting/markup,849,.. productionlist:,.. productionlist::
276+
documenting/markup,849,`,"try1_stmt: ""try"" "":"" `suite`"
277+
documenting/markup,849,`,": (""except"" [`expression` ["","" `target`]] "":"" `suite`)+"
278+
documenting/markup,849,`,": [""else"" "":"" `suite`]"
279+
documenting/markup,849,`,": [""finally"" "":"" `suite`]"
280+
documenting/markup,849,`,"try2_stmt: ""try"" "":"" `suite`"
281+
documenting/markup,849,`,": ""finally"" "":"" `suite`"
282+
documenting/rest,33,`,``text``
283+
documenting/rest,47,:rolename,:rolename:`content`
284+
documenting/rest,47,`,:rolename:`content`
285+
documenting/rest,103,::,This is a normal text paragraph. The next paragraph is a code sample::
286+
documenting/rest,130,`,`Link text <http://target>`_
287+
documenting/rest,187,.. function:,.. function:: foo(x)
288+
documenting/rest,187,:bar,:bar: no
289+
documenting/rest,208,.. rubric:,.. rubric:: Footnotes
290+
faq/programming,762,:reduce,"print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,"
291+
faq/programming,762,:reduce,"Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,"
292+
faq/programming,762,:chr,">=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr("
293+
faq/programming,1047,::,for x in sequence[::-1]:
294+
faq/windows,229,:EOF,@setlocal enableextensions & python -x %~f0 %* & goto :EOF
295+
faq/windows,393,:REG,.py :REG_SZ: c:\<path to python>\python.exe -u %s %s
296+
library/bisect,32,:hi,all(val >= x for val in a[i:hi])
297+
library/bisect,42,:hi,all(val > x for val in a[i:hi])
298+
library/http.client,52,:port,host:port
299+
library/nntplib,272,:bytes,:bytes
300+
library/nntplib,272,:lines,:lines
301+
library/nntplib,272,:lines,"['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject']"
302+
library/nntplib,272,:bytes,"['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject']"
303+
library/pickle,567,:memory,"conn = sqlite3.connect("":memory:"")"
304+
library/profile,293,:lineno,"(sort by filename:lineno),"
305+
library/socket,261,::,"(10, 1, 6, '', ('2001:888:2000:d::a2', 80, 0, 0))]"
306+
library/stdtypes,1026,:end,s[start:end]
307+
library/stdtypes,1195,:end,s[start:end]
308+
library/urllib.request,64,:close,Connection:close
309+
library/urllib.request,901,:password,"""joe:[email protected]"""
310+
library/urllib.request,1064,:lang,"xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en"">\n\n<head>\n"
311+
library/xmlrpc.client,103,:pass,http://user:pass@host:port/path
312+
library/xmlrpc.client,103,:port,http://user:pass@host:port/path
313+
library/xmlrpc.client,103,:pass,user:pass
314+
license,717,`,* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
315+
license,717,`,* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
316+
license,879,`,"``Software''), to deal in the Software without restriction, including"
317+
license,879,`,"THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,"
318+
reference/lexical_analysis,704,`,$ ? `
319+
whatsnew/2.7,735,:Sunday,'2009:4:Sunday'
320+
whatsnew/2.7,862,::,"export PYTHONWARNINGS=all,error:::Cookie:0"
321+
whatsnew/2.7,862,:Cookie,"export PYTHONWARNINGS=all,error:::Cookie:0"
322+
whatsnew/2.7,1619,::,>>> urlparse.urlparse('http://[1080::8:800:200C:417A]/foo')
323+
whatsnew/2.7,1619,::,"ParseResult(scheme='http', netloc='[1080::8:800:200C:417A]',"

Doc/tools/sphinxext/suspicious.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141
4242
"""
4343

44-
import os, sys
45-
import csv
44+
import os
4645
import re
46+
import csv
47+
import sys
48+
4749
from docutils import nodes
4850
from sphinx.builders import Builder
4951

@@ -54,9 +56,10 @@
5456
(?<!\.)\.\.[ \t]*\w+: # .. foo: (but NOT ... else:)
5557
''', re.UNICODE | re.VERBOSE).finditer
5658

59+
5760
class Rule:
5861
def __init__(self, docname, lineno, issue, line):
59-
"A rule for ignoring issues"
62+
"""A rule for ignoring issues"""
6063
self.docname = docname # document to which this rule applies
6164
self.lineno = lineno # line number in the original source;
6265
# this rule matches only near that.
@@ -65,9 +68,15 @@ def __init__(self, docname, lineno, issue, line):
6568
self.line = line # text of the container element (single line only)
6669

6770

71+
72+
class dialect(csv.excel):
73+
"""Our dialect: uses only linefeed as newline."""
74+
lineterminator = '\n'
75+
76+
6877
class CheckSuspiciousMarkupBuilder(Builder):
6978
"""
70-
Checks for possibly invalid markup that may leak into the output
79+
Checks for possibly invalid markup that may leak into the output.
7180
"""
7281
name = 'suspicious'
7382

@@ -76,7 +85,8 @@ def init(self):
7685
self.log_file_name = os.path.join(self.outdir, 'suspicious.csv')
7786
open(self.log_file_name, 'w').close()
7887
# load database of previously ignored issues
79-
self.load_rules(os.path.join(os.path.dirname(__file__), 'susp-ignored.csv'))
88+
self.load_rules(os.path.join(os.path.dirname(__file__),
89+
'susp-ignored.csv'))
8090

8191
def get_outdated_docs(self):
8292
return self.env.found_docs
@@ -85,14 +95,11 @@ def get_target_uri(self, docname, typ=None):
8595
return ''
8696

8797
def prepare_writing(self, docnames):
88-
### PYTHON PROJECT SPECIFIC ###
89-
for name in set(docnames):
90-
if name.split('/', 1)[0] == 'documenting':
91-
docnames.remove(name)
92-
### PYTHON PROJECT SPECIFIC ###
98+
pass
9399

94100
def write_doc(self, docname, doctree):
95-
self.any_issue = False # set when any issue is encountered in this document
101+
# set when any issue is encountered in this document
102+
self.any_issue = False
96103
self.docname = docname
97104
visitor = SuspiciousVisitor(doctree, self)
98105
doctree.walk(visitor)
@@ -105,8 +112,7 @@ def check_issue(self, line, lineno, issue):
105112
self.report_issue(line, lineno, issue)
106113

107114
def is_ignored(self, line, lineno, issue):
108-
"""Determine whether this issue should be ignored.
109-
"""
115+
"""Determine whether this issue should be ignored."""
110116
docname = self.docname
111117
for rule in self.rules:
112118
if rule.docname != docname: continue
@@ -139,12 +145,11 @@ def report_issue(self, text, lineno, issue):
139145

140146
def write_log_entry(self, lineno, issue, text):
141147
f = open(self.log_file_name, 'ab')
142-
writer = csv.writer(f)
148+
writer = csv.writer(f, dialect)
143149
writer.writerow([self.docname.encode('utf-8'),
144-
lineno,
145-
issue.encode('utf-8'),
146-
text.strip().encode('utf-8')])
147-
del writer
150+
lineno,
151+
issue.encode('utf-8'),
152+
text.strip().encode('utf-8')])
148153
f.close()
149154

150155
def load_rules(self, filename):
@@ -159,7 +164,8 @@ def load_rules(self, filename):
159164
except IOError: return
160165
for i, row in enumerate(csv.reader(f)):
161166
if len(row) != 4:
162-
raise ValueError, "wrong format in %s, line %d: %s" % (filename, i+1, row)
167+
raise ValueError(
168+
"wrong format in %s, line %d: %s" % (filename, i+1, row))
163169
docname, lineno, issue, text = row
164170
docname = docname.decode('utf-8')
165171
if lineno: lineno = int(lineno)
@@ -173,7 +179,7 @@ def load_rules(self, filename):
173179

174180

175181
def get_lineno(node):
176-
"Obtain line number information for a node"
182+
"""Obtain line number information for a node."""
177183
lineno = None
178184
while lineno is None and node:
179185
node = node.parent
@@ -198,7 +204,8 @@ def extract_line(text, index):
198204
"""
199205
p = text.rfind('\n', 0, index) + 1
200206
q = text.find('\n', index)
201-
if q<0: q = len(text)
207+
if q < 0:
208+
q = len(text)
202209
return text[p:q]
203210

204211

@@ -217,7 +224,6 @@ def default_visit(self, node):
217224
self.lastlineno = lineno = max(get_lineno(node) or 0, self.lastlineno)
218225
seen = set() # don't report the same issue more than only once per line
219226
for match in detect_all(text):
220-
#import pdb; pdb.set_trace()
221227
issue = match.group()
222228
line = extract_line(text, match.start())
223229
if (issue, line) not in seen:

0 commit comments

Comments
 (0)