Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
6a5cf429
Commit
6a5cf429
authored
Dec 21, 2012
by
Tiago Peixoto
Browse files
Update sphinx files to python3
parent
e29e4ce5
Changes
12
Hide whitespace changes
Inline
Side-by-side
doc/conf.py
View file @
6a5cf429
...
...
@@ -26,8 +26,10 @@ sys.path.append(os.path.abspath('.'))
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions
=
[
'sphinx.ext.autodoc'
,
'sphinx.ext.doctest'
,
'sphinx.ext.intersphinx'
,
'mathjax'
,
'sphinx.ext.autosummary'
,
'sphinxext.numpydoc'
,
'sphinx.ext.extlinks'
,
'matplotlib.sphinxext.plot_directive'
]
'sphinxext.numpydoc'
,
'sphinx.ext.extlinks'
,
#'matplotlib.sphinxext.plot_directive'
]
mathjax_path
=
"MathJax/MathJax.js"
...
...
doc/pyenv.py
View file @
6a5cf429
...
...
@@ -27,8 +27,8 @@ rcParams["ps.useafm"] = True
rcParams
[
"path.simplify"
]
=
True
rcParams
[
"text.latex.preamble"
]
=
[
#"\usepackage{times}",
#"\usepackage{euler}",
"\usepackage{amssymb}"
,
"\usepackage{amsmath}"
]
r
"\usepackage{amssymb}"
,
r
"\usepackage{amsmath}"
]
from
numpy
import
*
import
scipy
...
...
doc/sphinxext/LICENSE.txt
View file @
6a5cf429
-------------------------------------------------------------------------------
The files
- numpydoc.py
- autosummary.py
- autosummary_generate.py
- docscrape.py
- docscrape_sphinx.py
- phantom_import.py
...
...
@@ -71,10 +69,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
The files
- only_directives.py
The file
- plot_directive.py
originate from Matplotlib (http://matplotlib.sf.net/) which has
originate
s
from Matplotlib (http://matplotlib.sf.net/) which has
the following license:
Copyright (c) 2002-2008 John D. Hunter; All Rights Reserved.
...
...
doc/sphinxext/__init__.py
View file @
6a5cf429
from
numpydoc
import
setup
from
.
numpydoc
import
setup
doc/sphinxext/comment_eater.py
View file @
6a5cf429
from
cStringIO
import
StringIO
from
io
import
StringIO
import
compiler
import
inspect
import
textwrap
import
tokenize
from
compiler_unparse
import
unparse
from
.
compiler_unparse
import
unparse
class
Comment
(
object
):
...
...
@@ -68,7 +68,7 @@ class CommentBlocker(object):
def
process_file
(
self
,
file
):
""" Process a file object.
"""
for
token
in
tokenize
.
generate_tokens
(
file
.
next
):
for
token
in
tokenize
.
generate_tokens
(
file
.
__
next
__
):
self
.
process_token
(
*
token
)
self
.
make_index
()
...
...
doc/sphinxext/compiler_unparse.py
View file @
6a5cf429
...
...
@@ -12,11 +12,11 @@
"""
import
sys
import
cStringIO
import
io
from
compiler.ast
import
Const
,
Name
,
Tuple
,
Div
,
Mul
,
Sub
,
Add
def
unparse
(
ast
,
single_line_functions
=
False
):
s
=
cStringIO
.
StringIO
()
s
=
io
.
StringIO
()
UnparseCompilerAst
(
ast
,
s
,
single_line_functions
)
return
s
.
getvalue
().
lstrip
()
...
...
@@ -258,7 +258,7 @@ class UnparseCompilerAst:
self
.
_dispatch
(
t
.
decorators
)
self
.
_fill
(
"def "
+
t
.
name
+
"("
)
defaults
=
[
None
]
*
(
len
(
t
.
argnames
)
-
len
(
t
.
defaults
))
+
list
(
t
.
defaults
)
for
i
,
arg
in
enumerate
(
zip
(
t
.
argnames
,
defaults
)):
for
i
,
arg
in
enumerate
(
list
(
zip
(
t
.
argnames
,
defaults
))
)
:
self
.
_write
(
arg
[
0
])
if
arg
[
1
]
is
not
None
:
self
.
_write
(
'='
)
...
...
@@ -504,7 +504,7 @@ class UnparseCompilerAst:
# Check if parenthesis are needed on left side and then dispatch
has_paren
=
False
left_class
=
str
(
t
.
left
.
__class__
)
if
(
left_class
in
op_precedence
.
keys
()
and
if
(
left_class
in
list
(
op_precedence
.
keys
()
)
and
op_precedence
[
left_class
]
<
op_precedence
[
str
(
t
.
__class__
)]):
has_paren
=
True
if
has_paren
:
...
...
@@ -517,7 +517,7 @@ class UnparseCompilerAst:
# Check if parenthesis are needed on the right side and then dispatch
has_paren
=
False
right_class
=
str
(
t
.
right
.
__class__
)
if
(
right_class
in
op_precedence
.
keys
()
and
if
(
right_class
in
list
(
op_precedence
.
keys
()
)
and
op_precedence
[
right_class
]
<
op_precedence
[
str
(
t
.
__class__
)]):
has_paren
=
True
if
has_paren
:
...
...
doc/sphinxext/docscrape.py
View file @
6a5cf429
...
...
@@ -6,8 +6,9 @@ import inspect
import
textwrap
import
re
import
pydoc
from
StringIO
import
StringIO
from
io
import
StringIO
from
warnings
import
warn
import
collections
class
Reader
(
object
):
"""A line-based string reader.
...
...
@@ -113,7 +114,7 @@ class NumpyDocString(object):
return
self
.
_parsed_data
[
key
]
def
__setitem__
(
self
,
key
,
val
):
if
not
self
.
_parsed_data
.
has_key
(
key
)
:
if
key
not
in
self
.
_parsed_data
:
warn
(
"Unknown section %s"
%
key
)
else
:
self
.
_parsed_data
[
key
]
=
val
...
...
@@ -370,7 +371,7 @@ class NumpyDocString(object):
idx
=
self
[
'index'
]
out
=
[]
out
+=
[
'.. index:: %s'
%
idx
.
get
(
'default'
,
''
)]
for
section
,
references
in
idx
.
iter
items
():
for
section
,
references
in
idx
.
items
():
if
section
==
'default'
:
continue
out
+=
[
' :%s: %s'
%
(
section
,
', '
.
join
(
references
))]
...
...
@@ -428,7 +429,7 @@ class FunctionDoc(NumpyDocString):
argspec
=
inspect
.
formatargspec
(
*
argspec
)
argspec
=
argspec
.
replace
(
'*'
,
'\*'
)
signature
=
'%s%s'
%
(
func_name
,
argspec
)
except
TypeError
,
e
:
except
TypeError
as
e
:
signature
=
'%s()'
%
func_name
self
[
'Signature'
]
=
signature
...
...
@@ -450,8 +451,8 @@ class FunctionDoc(NumpyDocString):
'meth'
:
'method'
}
if
self
.
_role
:
if
not
roles
.
has_key
(
self
.
_role
)
:
print
"Warning: invalid role %s"
%
self
.
_role
if
self
.
_role
not
in
roles
:
print
(
"Warning: invalid role %s"
%
self
.
_role
)
out
+=
'.. %s:: %s
\n
\n\n
'
%
(
roles
.
get
(
self
.
_role
,
''
),
func_name
)
...
...
@@ -460,6 +461,9 @@ class FunctionDoc(NumpyDocString):
class
ClassDoc
(
NumpyDocString
):
extra_public_methods
=
[
'__call__'
]
def
__init__
(
self
,
cls
,
doc
=
None
,
modulename
=
''
,
func_doc
=
FunctionDoc
,
config
=
{}):
if
not
inspect
.
isclass
(
cls
)
and
cls
is
not
None
:
...
...
@@ -490,7 +494,9 @@ class ClassDoc(NumpyDocString):
if
self
.
_cls
is
None
:
return
[]
return
[
name
for
name
,
func
in
inspect
.
getmembers
(
self
.
_cls
)
if
not
name
.
startswith
(
'_'
)
and
callable
(
func
)]
if
((
not
name
.
startswith
(
'_'
)
or
name
in
self
.
extra_public_methods
)
and
isinstance
(
func
,
collections
.
Callable
))]
@
property
def
properties
(
self
):
...
...
doc/sphinxext/docscrape_sphinx.py
View file @
6a5cf429
import
re
,
inspect
,
textwrap
,
pydoc
import
sphinx
from
docscrape
import
NumpyDocString
,
FunctionDoc
,
ClassDoc
from
.docscrape
import
NumpyDocString
,
FunctionDoc
,
ClassDoc
import
collections
class
SphinxDocString
(
NumpyDocString
):
def
__init__
(
self
,
docstring
,
config
=
{}):
...
...
@@ -127,7 +128,7 @@ class SphinxDocString(NumpyDocString):
return
out
out
+=
[
'.. index:: %s'
%
idx
.
get
(
'default'
,
''
)]
for
section
,
references
in
idx
.
iter
items
():
for
section
,
references
in
idx
.
items
():
if
section
==
'default'
:
continue
elif
section
==
'refguide'
:
...
...
@@ -212,7 +213,7 @@ def get_doc_object(obj, what=None, doc=None, config={}):
what
=
'class'
elif
inspect
.
ismodule
(
obj
):
what
=
'module'
elif
c
allable
(
obj
):
elif
isinstance
(
obj
,
collections
.
C
allable
):
what
=
'function'
else
:
what
=
'object'
...
...
doc/sphinxext/numpydoc.py
View file @
6a5cf429
...
...
@@ -12,17 +12,18 @@ It will:
- Renumber references.
- Extract the signature from the docstring, if it can't be determined otherwise.
.. [1] http://
projects.scipy.org/numpy/wiki/CodingStyleGuidelines#docstring-standard
.. [1] http
s
://
github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
"""
import
sphinx
import
collections
if
sphinx
.
__version__
<
'1.0.1'
:
raise
RuntimeError
(
"Sphinx 1.0.1 or newer is required"
)
import
os
,
re
,
pydoc
from
docscrape_sphinx
import
get_doc_object
,
SphinxDocString
from
.
docscrape_sphinx
import
get_doc_object
,
SphinxDocString
from
sphinx.util.compat
import
Directive
import
inspect
...
...
@@ -34,28 +35,28 @@ def mangle_docstrings(app, what, name, obj, options, lines,
if
what
==
'module'
:
# Strip top title
title_re
=
re
.
compile
(
u
r
'^\s*[#*=]{4,}\n[a-z0-9 -]+\n[#*=]{4,}\s*'
,
title_re
=
re
.
compile
(
r
'^\s*[#*=]{4,}\n[a-z0-9 -]+\n[#*=]{4,}\s*'
,
re
.
I
|
re
.
S
)
lines
[:]
=
title_re
.
sub
(
u
''
,
u
"
\n
"
.
join
(
lines
)).
split
(
u
"
\n
"
)
lines
[:]
=
title_re
.
sub
(
''
,
"
\n
"
.
join
(
lines
)).
split
(
"
\n
"
)
else
:
doc
=
get_doc_object
(
obj
,
what
,
u
"
\n
"
.
join
(
lines
),
config
=
cfg
)
lines
[:]
=
unicode
(
doc
).
split
(
u
"
\n
"
)
doc
=
get_doc_object
(
obj
,
what
,
"
\n
"
.
join
(
lines
),
config
=
cfg
)
lines
[:]
=
str
(
doc
).
split
(
"
\n
"
)
if
app
.
config
.
numpydoc_edit_link
and
hasattr
(
obj
,
'__name__'
)
and
\
obj
.
__name__
:
if
hasattr
(
obj
,
'__module__'
):
v
=
dict
(
full_name
=
u
"%s.%s"
%
(
obj
.
__module__
,
obj
.
__name__
))
v
=
dict
(
full_name
=
"%s.%s"
%
(
obj
.
__module__
,
obj
.
__name__
))
else
:
v
=
dict
(
full_name
=
obj
.
__name__
)
lines
+=
[
u
''
,
u
'.. htmlonly::'
,
''
]
lines
+=
[
u
' %s'
%
x
for
x
in
lines
+=
[
''
,
'.. htmlonly::'
,
''
]
lines
+=
[
' %s'
%
x
for
x
in
(
app
.
config
.
numpydoc_edit_link
%
v
).
split
(
"
\n
"
)]
# replace reference numbers so that there are no duplicates
references
=
[]
for
line
in
lines
:
line
=
line
.
strip
()
m
=
re
.
match
(
u
r
'^.. \[([a-z0-9_.-])\]'
,
line
,
re
.
I
)
m
=
re
.
match
(
r
'^.. \[([a-z0-9_.-])\]'
,
line
,
re
.
I
)
if
m
:
references
.
append
(
m
.
group
(
1
))
...
...
@@ -64,14 +65,14 @@ def mangle_docstrings(app, what, name, obj, options, lines,
if
references
:
for
i
,
line
in
enumerate
(
lines
):
for
r
in
references
:
if
re
.
match
(
u
r
'^\d+$'
,
r
):
new_r
=
u
"R%d"
%
(
reference_offset
[
0
]
+
int
(
r
))
if
re
.
match
(
r
'^\d+$'
,
r
):
new_r
=
"R%d"
%
(
reference_offset
[
0
]
+
int
(
r
))
else
:
new_r
=
u
"%s%d"
%
(
r
,
reference_offset
[
0
])
lines
[
i
]
=
lines
[
i
].
replace
(
u
'[%s]_'
%
r
,
u
'[%s]_'
%
new_r
)
lines
[
i
]
=
lines
[
i
].
replace
(
u
'.. [%s]'
%
r
,
u
'.. [%s]'
%
new_r
)
new_r
=
"%s%d"
%
(
r
,
reference_offset
[
0
])
lines
[
i
]
=
lines
[
i
].
replace
(
'[%s]_'
%
r
,
'[%s]_'
%
new_r
)
lines
[
i
]
=
lines
[
i
].
replace
(
'.. [%s]'
%
r
,
'.. [%s]'
%
new_r
)
reference_offset
[
0
]
+=
len
(
references
)
...
...
@@ -82,13 +83,13 @@ def mangle_signature(app, what, name, obj, options, sig, retann):
'initializes x; see '
in
pydoc
.
getdoc
(
obj
.
__init__
))):
return
''
,
''
if
not
(
c
allable
(
obj
)
or
hasattr
(
obj
,
'__argspec_is_invalid_'
)):
return
if
not
(
isinstance
(
obj
,
collections
.
C
allable
)
or
hasattr
(
obj
,
'__argspec_is_invalid_'
)):
return
if
not
hasattr
(
obj
,
'__doc__'
):
return
doc
=
SphinxDocString
(
pydoc
.
getdoc
(
obj
))
if
doc
[
'Signature'
]:
sig
=
re
.
sub
(
u
"^[^(]*"
,
u
""
,
doc
[
'Signature'
])
return
sig
,
u
''
sig
=
re
.
sub
(
"^[^(]*"
,
""
,
doc
[
'Signature'
])
return
sig
,
''
def
setup
(
app
,
get_doc_object_
=
get_doc_object
):
global
get_doc_object
...
...
@@ -120,7 +121,7 @@ class ManglingDomainBase(object):
self
.
wrap_mangling_directives
()
def
wrap_mangling_directives
(
self
):
for
name
,
objtype
in
self
.
directive_mangling_map
.
items
():
for
name
,
objtype
in
list
(
self
.
directive_mangling_map
.
items
()
)
:
self
.
directives
[
name
]
=
wrap_mangling_directive
(
self
.
directives
[
name
],
objtype
)
...
...
doc/sphinxext/phantom_import.py
View file @
6a5cf429
...
...
@@ -23,7 +23,7 @@ def setup(app):
def
initialize
(
app
):
fn
=
app
.
config
.
phantom_import_file
if
(
fn
and
os
.
path
.
isfile
(
fn
)):
print
"[numpydoc] Phantom importing modules from"
,
fn
,
"..."
print
(
"[numpydoc] Phantom importing modules from"
,
fn
,
"..."
)
import_phantom_module
(
fn
)
#------------------------------------------------------------------------------
...
...
@@ -129,7 +129,7 @@ def import_phantom_module(xml_file):
doc
=
"%s%s
\n\n
%s"
%
(
funcname
,
argspec
,
doc
)
obj
=
lambda
:
0
obj
.
__argspec_is_invalid_
=
True
obj
.
func
_name
=
funcname
obj
.
_
_name
__
=
funcname
obj
.
__name__
=
name
obj
.
__doc__
=
doc
if
inspect
.
isclass
(
object_cache
[
parent
]):
...
...
doc/sphinxext/setup.py
View file @
6a5cf429
from
distutils.core
import
setup
import
setuptools
import
sys
,
os
version
=
"0.4"
setup
(
name
=
"numpydoc"
,
packages
=
[
"numpydoc"
],
package_dir
=
{
"numpydoc"
:
""
},
package_dir
=
{
"numpydoc"
:
"
.
"
},
version
=
version
,
description
=
"Sphinx extension to support docstrings in Numpy format"
,
# classifiers from http://pypi.python.org/pypi?%3Aaction=list_classifiers
...
...
@@ -20,12 +18,6 @@ setup(
author_email
=
"pav@iki.fi"
,
url
=
"http://github.com/numpy/numpy/tree/master/doc/sphinxext"
,
license
=
"BSD"
,
zip_safe
=
False
,
install_requires
=
[
"Sphinx >= 1.0.1"
],
package_data
=
{
'numpydoc'
:
'tests'
,
''
:
''
},
entry_points
=
{
"console_scripts"
:
[
"autosummary_generate = numpydoc.autosummary_generate:main"
,
],
},
requires
=
[
"sphinx (>= 1.0.1)"
],
package_data
=
{
'numpydoc'
:
[
'tests/test_*.py'
]},
)
doc/sphinxext/traitsdoc.py
View file @
6a5cf429
...
...
@@ -18,13 +18,14 @@ import inspect
import
os
import
pydoc
import
docscrape
import
docscrape_sphinx
from
docscrape_sphinx
import
SphinxClassDoc
,
SphinxFunctionDoc
,
SphinxDocString
from
.
import
docscrape
from
.
import
docscrape_sphinx
from
.
docscrape_sphinx
import
SphinxClassDoc
,
SphinxFunctionDoc
,
SphinxDocString
import
numpydoc
from
.
import
numpydoc
import
comment_eater
from
.
import
comment_eater
import
collections
class
SphinxTraitsDoc
(
SphinxClassDoc
):
def
__init__
(
self
,
cls
,
modulename
=
''
,
func_doc
=
SphinxFunctionDoc
):
...
...
@@ -117,7 +118,7 @@ def get_doc_object(obj, what=None, config=None):
what
=
'class'
elif
inspect
.
ismodule
(
obj
):
what
=
'module'
elif
c
allable
(
obj
):
elif
isinstance
(
obj
,
collections
.
C
allable
):
what
=
'function'
else
:
what
=
'object'
...
...
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