Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
943195a7
Commit
943195a7
authored
Jan 14, 2012
by
Sandro Tosi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update part of sphinxext
parent
159c22cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
27 deletions
+118
-27
Doc/tools/sphinxext/pyspecific.py
Doc/tools/sphinxext/pyspecific.py
+116
-25
Doc/tools/sphinxext/static/copybutton.js
Doc/tools/sphinxext/static/copybutton.js
+2
-2
No files found.
Doc/tools/sphinxext/pyspecific.py
View file @
943195a7
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
Sphinx extension with Python doc-specific markup.
Sphinx extension with Python doc-specific markup.
:copyright: 2008
-2011
by Georg Brandl.
:copyright: 2008
, 2009, 2010
by Georg Brandl.
:license: Python license.
:license: Python license.
"""
"""
...
@@ -13,6 +13,7 @@ ISSUE_URI = 'http://bugs.python.org/issue%s'
...
@@ -13,6 +13,7 @@ ISSUE_URI = 'http://bugs.python.org/issue%s'
SOURCE_URI
=
'http://hg.python.org/cpython/file/2.7/%s'
SOURCE_URI
=
'http://hg.python.org/cpython/file/2.7/%s'
from
docutils
import
nodes
,
utils
from
docutils
import
nodes
,
utils
from
sphinx.util.nodes
import
split_explicit_title
# monkey-patch reST parser to disable alphabetic and roman enumerated lists
# monkey-patch reST parser to disable alphabetic and roman enumerated lists
from
docutils.parsers.rst.states
import
Body
from
docutils.parsers.rst.states
import
Body
...
@@ -48,8 +49,10 @@ def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
...
@@ -48,8 +49,10 @@ def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
# Support for linking to Python source files easily
# Support for linking to Python source files easily
def
source_role
(
typ
,
rawtext
,
text
,
lineno
,
inliner
,
options
=
{},
content
=
[]):
def
source_role
(
typ
,
rawtext
,
text
,
lineno
,
inliner
,
options
=
{},
content
=
[]):
path
=
utils
.
unescape
(
text
)
has_t
,
title
,
target
=
split_explicit_title
(
text
)
refnode
=
nodes
.
reference
(
path
,
path
,
refuri
=
SOURCE_URI
%
path
)
title
=
utils
.
unescape
(
title
)
target
=
utils
.
unescape
(
target
)
refnode
=
nodes
.
reference
(
title
,
title
,
refuri
=
SOURCE_URI
%
target
)
return
[
refnode
],
[]
return
[
refnode
],
[]
...
@@ -81,26 +84,85 @@ class ImplementationDetail(Directive):
...
@@ -81,26 +84,85 @@ class ImplementationDetail(Directive):
return
[
pnode
]
return
[
pnode
]
# Support for documenting decorators
from
sphinx
import
addnodes
from
sphinx.domains.python
import
PyModulelevel
,
PyClassmember
class
PyDecoratorMixin
(
object
):
def
handle_signature
(
self
,
sig
,
signode
):
ret
=
super
(
PyDecoratorMixin
,
self
).
handle_signature
(
sig
,
signode
)
signode
.
insert
(
0
,
addnodes
.
desc_addname
(
'@'
,
'@'
))
return
ret
def
needs_arglist
(
self
):
return
False
class
PyDecoratorFunction
(
PyDecoratorMixin
,
PyModulelevel
):
def
run
(
self
):
# a decorator function is a function after all
self
.
name
=
'py:function'
return
PyModulelevel
.
run
(
self
)
class
PyDecoratorMethod
(
PyDecoratorMixin
,
PyClassmember
):
def
run
(
self
):
self
.
name
=
'py:method'
return
PyClassmember
.
run
(
self
)
# Support for documenting version of removal in deprecations
from
sphinx.locale
import
versionlabels
from
sphinx.util.compat
import
Directive
versionlabels
[
'deprecated-removed'
]
=
\
'Deprecated since version %s, will be removed in version %s'
class
DeprecatedRemoved
(
Directive
):
has_content
=
True
required_arguments
=
2
optional_arguments
=
1
final_argument_whitespace
=
True
option_spec
=
{}
def
run
(
self
):
node
=
addnodes
.
versionmodified
()
node
.
document
=
self
.
state
.
document
node
[
'type'
]
=
'deprecated-removed'
version
=
(
self
.
arguments
[
0
],
self
.
arguments
[
1
])
node
[
'version'
]
=
version
if
len
(
self
.
arguments
)
==
3
:
inodes
,
messages
=
self
.
state
.
inline_text
(
self
.
arguments
[
2
],
self
.
lineno
+
1
)
node
.
extend
(
inodes
)
if
self
.
content
:
self
.
state
.
nested_parse
(
self
.
content
,
self
.
content_offset
,
node
)
ret
=
[
node
]
+
messages
else
:
ret
=
[
node
]
env
=
self
.
state
.
document
.
settings
.
env
env
.
note_versionchange
(
'deprecated'
,
version
[
0
],
node
,
self
.
lineno
)
return
ret
# Support for building "topic help" for pydoc
# Support for building "topic help" for pydoc
pydoc_topic_labels
=
[
pydoc_topic_labels
=
[
'assert'
,
'assignment'
,
'atom-identifiers'
,
'atom-literals'
,
'assert'
,
'assignment'
,
'atom-identifiers'
,
'atom-literals'
,
'attribute-access'
,
'attribute-references'
,
'augassign'
,
'binary'
,
'attribute-access'
,
'attribute-references'
,
'augassign'
,
'binary'
,
'bitwise'
,
'bltin-code-objects'
,
'bltin-ellipsis-object'
,
'bitwise'
,
'bltin-code-objects'
,
'bltin-ellipsis-object'
,
'bltin-file-objects'
,
'bltin-null-object'
,
'bltin-type-objects'
,
'booleans'
,
'bltin-null-object'
,
'bltin-type-objects'
,
'booleans'
,
'break'
,
'callable-types'
,
'calls'
,
'class'
,
'coercion-rules'
,
'break'
,
'callable-types'
,
'calls'
,
'class'
,
'comparisons'
,
'compound'
,
'comparisons'
,
'compound'
,
'context-managers'
,
'continue'
,
'conversions'
,
'context-managers'
,
'continue'
,
'conversions'
,
'customization'
,
'debugger'
,
'customization'
,
'debugger'
,
'del'
,
'dict'
,
'dynamic-features'
,
'else'
,
'del'
,
'dict'
,
'dynamic-features'
,
'else'
,
'exceptions'
,
'execmodel'
,
'exceptions'
,
'exec'
,
'execmodel'
,
'exprlists'
,
'floating'
,
'for'
,
'exprlists'
,
'floating'
,
'for'
,
'formatstrings'
,
'function'
,
'global'
,
'formatstrings'
,
'function'
,
'global'
,
'id-classes'
,
'identifiers'
,
'if'
,
'id-classes'
,
'identifiers'
,
'if'
,
'imaginary'
,
'import'
,
'in'
,
'integers'
,
'imaginary'
,
'import'
,
'in'
,
'integers'
,
'lambda'
,
'lists'
,
'naming'
,
'lambda'
,
'lists'
,
'naming'
,
'nonlocal'
,
'numbers'
,
'numeric-types'
,
'numbers'
,
'numeric-types'
,
'objects'
,
'operator-summary'
,
'pass'
,
'power'
,
'objects'
,
'operator-summary'
,
'pass'
,
'power'
,
'raise'
,
'return'
,
'print'
,
'raise'
,
'return'
,
'sequence-methods'
,
'sequence-types'
,
'sequence-types'
,
'shifting'
,
'slicings'
,
'specialattrs'
,
'specialnames'
,
'shifting'
,
'slicings'
,
'specialattrs'
,
'specialnames'
,
'string-methods'
,
'strings'
,
'subscriptions'
,
'truth'
,
'try'
,
'types'
,
'string-conversions'
,
'string-methods'
,
'strings'
,
'subscriptions'
,
'truth'
,
'typesfunctions'
,
'typesmapping'
,
'typesmethods'
,
'typesmodules'
,
'try'
,
'types'
,
'typesfunctions'
,
'typesmapping'
,
'typesmethods'
,
'typesseq'
,
'typesseq-mutable'
,
'unary'
,
'while'
,
'with'
,
'yield'
'typesmodules'
,
'typesseq'
,
'typesseq-mutable'
,
'unary'
,
'while'
,
'with'
,
'yield'
]
]
from
os
import
path
from
os
import
path
...
@@ -130,16 +192,16 @@ class PydocTopicsBuilder(Builder):
...
@@ -130,16 +192,16 @@ class PydocTopicsBuilder(Builder):
for
label
in
self
.
status_iterator
(
pydoc_topic_labels
,
for
label
in
self
.
status_iterator
(
pydoc_topic_labels
,
'building topics... '
,
'building topics... '
,
length
=
len
(
pydoc_topic_labels
)):
length
=
len
(
pydoc_topic_labels
)):
if
label
not
in
self
.
env
.
labels
:
if
label
not
in
self
.
env
.
domaindata
[
'std'
][
'labels'
]
:
self
.
warn
(
'label %r not in documentation'
%
label
)
self
.
warn
(
'label %r not in documentation'
%
label
)
continue
continue
docname
,
labelid
,
sectname
=
self
.
env
.
labels
[
label
]
docname
,
labelid
,
sectname
=
self
.
env
.
domaindata
[
'std'
][
'labels'
]
[
label
]
doctree
=
self
.
env
.
get_and_resolve_doctree
(
docname
,
self
)
doctree
=
self
.
env
.
get_and_resolve_doctree
(
docname
,
self
)
document
=
new_document
(
'<section node>'
)
document
=
new_document
(
'<section node>'
)
document
.
append
(
doctree
.
ids
[
labelid
])
document
.
append
(
doctree
.
ids
[
labelid
])
destination
=
StringOutput
(
encoding
=
'utf-8'
)
destination
=
StringOutput
(
encoding
=
'utf-8'
)
writer
.
write
(
document
,
destination
)
writer
.
write
(
document
,
destination
)
self
.
topics
[
label
]
=
writer
.
output
self
.
topics
[
label
]
=
str
(
writer
.
output
)
def
finish
(
self
):
def
finish
(
self
):
f
=
open
(
path
.
join
(
self
.
outdir
,
'topics.py'
),
'w'
)
f
=
open
(
path
.
join
(
self
.
outdir
,
'topics.py'
),
'w'
)
...
@@ -158,9 +220,8 @@ import suspicious
...
@@ -158,9 +220,8 @@ import suspicious
# Support for documenting Opcodes
# Support for documenting Opcodes
import
re
import
re
from
sphinx
import
addnodes
opcode_sig_re
=
re
.
compile
(
r'(\
w+(?:
\+\
d)?)
\s*\
((.*)
\)
'
)
opcode_sig_re
=
re
.
compile
(
r'(\
w+(?:
\+\
d)?)
(?:
\s*\
((.*)
\))?
'
)
def
parse_opcode_signature
(
env
,
sig
,
signode
):
def
parse_opcode_signature
(
env
,
sig
,
signode
):
"""Transform an opcode signature into RST nodes."""
"""Transform an opcode signature into RST nodes."""
...
@@ -169,18 +230,48 @@ def parse_opcode_signature(env, sig, signode):
...
@@ -169,18 +230,48 @@ def parse_opcode_signature(env, sig, signode):
raise
ValueError
raise
ValueError
opname
,
arglist
=
m
.
groups
()
opname
,
arglist
=
m
.
groups
()
signode
+=
addnodes
.
desc_name
(
opname
,
opname
)
signode
+=
addnodes
.
desc_name
(
opname
,
opname
)
paramlist
=
addnodes
.
desc_parameterlist
()
if
arglist
is
not
None
:
signode
+=
paramlist
paramlist
=
addnodes
.
desc_parameterlist
()
paramlist
+=
addnodes
.
desc_parameter
(
arglist
,
arglist
)
signode
+=
paramlist
paramlist
+=
addnodes
.
desc_parameter
(
arglist
,
arglist
)
return
opname
.
strip
()
return
opname
.
strip
()
# Support for documenting pdb commands
pdbcmd_sig_re
=
re
.
compile
(
r'([a-z()!]+)\
s*(.*)
')
# later...
#pdbargs_tokens_re = re.compile(r'''[a-zA-Z]+ | # identifiers
# [.,:]+ | # punctuation
# [\
[
\]()] | # parens
# \
s+ # whi
tespace
# ''', re.X)
def parse_pdb_command(env, sig, signode):
"""Transform a pdb command signature into RST nodes."""
m = pdbcmd_sig_re.match(sig)
if m is None:
raise ValueError
name, args = m.groups()
fullname = name.replace('
(
', '').replace('
)
', '')
signode += addnodes.desc_name(name, name)
if args:
signode += addnodes.desc_addname('
'+args, '
'+args)
return fullname
def setup(app):
def setup(app):
app.add_role('
issue
', issue_role)
app.add_role('
issue
', issue_role)
app.add_role('
source
', source_role)
app.add_role('
source
', source_role)
app.add_directive('
impl
-
detail
', ImplementationDetail)
app.add_directive('
impl
-
detail
', ImplementationDetail)
app.add_directive('
deprecated
-
removed
', DeprecatedRemoved)
app.add_builder(PydocTopicsBuilder)
app.add_builder(PydocTopicsBuilder)
app.add_builder(suspicious.CheckSuspiciousMarkupBuilder)
app.add_builder(suspicious.CheckSuspiciousMarkupBuilder)
app.add_description_unit('
opcode
', '
opcode
', '
%
s
(
opcode
)
',
app.add_description_unit('
opcode
', '
opcode
', '
%
s
(
opcode
)
',
parse_opcode_signature)
parse_opcode_signature)
app.add_description_unit('
pdbcommand
', '
pdbcmd
', '
%
s
(
pdb
command
)
',
parse_pdb_command)
app.add_description_unit('
2
to3fixer
', '
2
to3fixer
', '
%
s
(
2
to3
fixer
)
')
app.add_description_unit('
2
to3fixer
', '
2
to3fixer
', '
%
s
(
2
to3
fixer
)
')
app.add_directive_to_domain('
py
', '
decorator
', PyDecoratorFunction)
app.add_directive_to_domain('
py
', '
decoratormethod
', PyDecoratorMethod)
Doc/tools/sphinxext/static/copybutton.js
View file @
943195a7
...
@@ -8,8 +8,8 @@ $(document).ready(function() {
...
@@ -8,8 +8,8 @@ $(document).ready(function() {
// get the styles from the current theme
// get the styles from the current theme
pre
.
parent
().
parent
().
css
(
'
position
'
,
'
relative
'
);
pre
.
parent
().
parent
().
css
(
'
position
'
,
'
relative
'
);
var
hide_text
=
'
Hide the prompts and ouput
'
;
var
hide_text
=
'
Hide the prompts and ou
t
put
'
;
var
show_text
=
'
Show the prompts and ouput
'
;
var
show_text
=
'
Show the prompts and ou
t
put
'
;
var
border_width
=
pre
.
css
(
'
border-top-width
'
);
var
border_width
=
pre
.
css
(
'
border-top-width
'
);
var
border_style
=
pre
.
css
(
'
border-top-style
'
);
var
border_style
=
pre
.
css
(
'
border-top-style
'
);
var
border_color
=
pre
.
css
(
'
border-top-color
'
);
var
border_color
=
pre
.
css
(
'
border-top-color
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment