Skip to content

Commit

Permalink
Basic vfunc support; Add fixed local toc menu and remove some unneede…
Browse files Browse the repository at this point in the history
…d headlines
  • Loading branch information
lazka committed Mar 5, 2014
1 parent 9d98aa0 commit b581de7
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 51 deletions.
46 changes: 39 additions & 7 deletions data/theme.patch
@@ -1,7 +1,7 @@
diff -Nur sphinx_rtd_theme/breadcrumbs.html theme/breadcrumbs.html
--- sphinx_rtd_theme/breadcrumbs.html 2014-03-04 19:47:00.606021609 +0100
+++ theme/breadcrumbs.html 2014-02-02 23:34:03.626687092 +0100
@@ -6,13 +6,7 @@
--- sphinx_rtd_theme/breadcrumbs.html 2014-03-05 00:38:28.311631703 +0100
+++ theme/breadcrumbs.html 2014-03-05 00:14:12.734943596 +0100
@@ -6,14 +6,12 @@
{% endfor %}
<li>{{ title }}</li>
<li class="wy-breadcrumbs-aside">
Expand All @@ -16,9 +16,14 @@ diff -Nur sphinx_rtd_theme/breadcrumbs.html theme/breadcrumbs.html
</li>
</ul>
<hr/>
</div>
+
+<div class="local-toc">
+ {{ toc }}
+</div>
diff -Nur sphinx_rtd_theme/layout.html theme/layout.html
--- sphinx_rtd_theme/layout.html 2014-03-04 19:47:00.606021609 +0100
+++ theme/layout.html 2014-03-04 19:53:29.726220076 +0100
--- sphinx_rtd_theme/layout.html 2014-03-05 00:38:28.311631703 +0100
+++ theme/layout.html 2014-03-05 00:27:20.963314565 +0100
@@ -14,7 +14,13 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand All @@ -34,11 +39,38 @@ diff -Nur sphinx_rtd_theme/layout.html theme/layout.html
{% endblock %}

{# FAVICON #}
@@ -25,6 +31,36 @@
@@ -25,6 +31,63 @@
{# CSS #}
<link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

+<style>
+
+.local-toc {
+ display: none;
+}
+
+@media screen and (min-width: 768px){
+ .local-toc {
+ position:fixed;
+ right: 1em;
+ bottom: 1em;
+ display: block;
+ }
+
+ .local-toc li
+ {
+ display:block;
+ text-align:right;
+ padding:0.3em 0;
+ text-transform:uppercase;
+ font-size: 0.9em;
+ }
+}
+
+.wy-nav-content {
+ margin: 0 !important;
+}
+
+.wy-side-nav-search, .wy-nav-top {
+ background-color: #75507b !important;
+}
Expand Down Expand Up @@ -71,7 +103,7 @@ diff -Nur sphinx_rtd_theme/layout.html theme/layout.html
{# OPENSEARCH #}
{% if not embedded %}
{% if use_opensearch %}
@@ -87,7 +123,7 @@
@@ -87,7 +150,7 @@
</div>

<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
Expand Down
4 changes: 4 additions & 0 deletions data/theme/breadcrumbs.html
Expand Up @@ -11,3 +11,7 @@
</ul>
<hr/>
</div>

<div class="local-toc">
{{ toc }}
</div>
27 changes: 27 additions & 0 deletions data/theme/layout.html
Expand Up @@ -32,6 +32,33 @@
<link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

<style>

.local-toc {
display: none;
}

@media screen and (min-width: 768px){
.local-toc {
position:fixed;
right: 1em;
bottom: 1em;
display: block;
}

.local-toc li
{
display:block;
text-align:right;
padding:0.3em 0;
text-transform:uppercase;
font-size: 0.9em;
}
}

.wy-nav-content {
margin: 0 !important;
}

.wy-side-nav-search, .wy-nav-top {
background-color: #75507b !important;
}
Expand Down
2 changes: 2 additions & 0 deletions pgi-docgen-build.py
Expand Up @@ -78,3 +78,5 @@ def png_optimize_dir(dir_, pool_size=6):
png_optimize_dir(dir_)
else:
print "optipng missing, skipping compression"

print "Done. See file://%s/index.html" % os.path.abspath(build_dir)
4 changes: 1 addition & 3 deletions pgidocgen/enum.py
Expand Up @@ -54,17 +54,15 @@ def write(self):
""")

for cls in classes:
title = util.make_rest_title(cls.__name__, "-")
handle.write("""
%s
.. autoclass:: %s
:show-inheritance:
:members:
:undoc-members:
:private-members:
""" % (title, cls.__module__ + "." + cls.__name__))
""" % (cls.__module__ + "." + cls.__name__))

for cls in classes:
code = self._enums[cls]
Expand Down
2 changes: 0 additions & 2 deletions pgidocgen/flags.py
Expand Up @@ -56,8 +56,6 @@ def write(self):
""")

for cls in classes:
title = util.make_rest_title(cls.__name__, "^")
handle.write(title + "\n")
if util.is_base(cls):
handle.write("""
.. autoclass:: %s
Expand Down
44 changes: 41 additions & 3 deletions pgidocgen/klass.py
Expand Up @@ -24,6 +24,7 @@ def __init__(self, dir_, module_fileobj):

self._classes = {} # cls -> code
self._methods = {} # cls -> code
self._vfuncs = {}
self._props = {} # cls -> [prop]
self._sigs = {} # cls -> [sig]

Expand All @@ -44,6 +45,15 @@ def add_method(self, cls_obj, obj, code):
else:
self._methods[cls_obj] = [(obj, code)]

def add_vfunc(self, cls_obj, obj, code):
if isinstance(code, unicode):
code = code.encode("utf-8")

if cls_obj in self._vfuncs:
self._vfuncs[cls_obj].append((obj, code))
else:
self._vfuncs[cls_obj] = [(obj, code)]

def add_properties(self, cls, props):
assert cls not in self._props

Expand Down Expand Up @@ -107,12 +117,19 @@ def indent(c):
# write the code
for cls in classes:
self._module.write(self._classes[cls])
methods = self._methods.get(cls, [])

# sort static methods first, then by name
def sort_func(e):
return util.is_normalmethod(e[0]), e[0].__name__

methods = self._methods.get(cls, [])[:]
methods.sort(key=sort_func)

vfuncs = self._vfuncs.get(cls, [])[:]
vfuncs.sort(key=sort_func)

methods.extend(vfuncs)

for obj, code in methods:
self._module.write(indent(code) + "\n")

Expand Down Expand Up @@ -172,6 +189,27 @@ def sort_func(e):
for obj, code in methods:
h.write(" " + cls_name + "." + obj.__name__ + "\n")

# VFUNC

h.write("""
Virtual Methods
---------------
""")

methods = self._vfuncs.get(cls, [])
if not methods:
h.write("None\n\n")
else:
h.write(".. autosummary::\n\n")

# sort static methods first, then by name
def sort_func(e):
return util.is_normalmethod(e[0]), e[0].__name__
methods.sort(key=sort_func)
for obj, code in methods:
h.write(" " + cls_name + "." + obj.__name__ + "\n")

# PROPERTIES

h.write("""
Expand Down Expand Up @@ -242,8 +280,8 @@ def sort_func(e):
self.write_field_table(cls, h)

h.write("""
Details
-------
Class Details
-------------
""")

if util.is_base(cls):
Expand Down
16 changes: 12 additions & 4 deletions pgidocgen/module.py
Expand Up @@ -130,10 +130,18 @@ def write(self):
continue

if callable(attr_obj):
func_key = name + "." + attr
code = repo.parse_function(func_key, obj, attr_obj)
if code:
class_gen.add_method(obj, attr_obj, code)
if not util.is_virtualmethod(attr_obj):
func_key = name + "." + attr
code = repo.parse_function(
func_key, obj, attr_obj)
if code:
class_gen.add_method(obj, attr_obj, code)
else:
func_key = name + "." + attr
code = repo.parse_function(
func_key, obj, attr_obj)
if code:
class_gen.add_vfunc(obj, attr_obj, code)

elif util.is_flags(obj):
code = repo.parse_flags(name, obj)
Expand Down
72 changes: 40 additions & 32 deletions pgidocgen/namespace.py
Expand Up @@ -231,35 +231,37 @@ def _parse_docs(dom):
signals = {}
properties = {}
fields = {}

tag_names = {
("glib:signal",): signals,
("field",): fields,
("property",): properties,
("parameter", "glib:signal"): sparas,
("parameter", "function"): parameters,
("parameter", "method"): parameters,
("parameter", "callback"): parameters,
("parameter", "constructor"): parameters,
("instance-parameter", "method"): parameters,
("return-value", "callback"): returns,
("return-value", "method"): returns,
("return-value", "function"): returns,
("return-value", "constructor"): returns,
("return-value", "glib:signal"): sreturns,
("interface",): all_,
("method",): all_,
("function",): all_,
("constant",): all_,
("record",): all_,
("enumeration",): all_,
("member",): all_,
("callback",): all_,
("alias",): all_,
("constructor",): all_,
("class",): all_,
("bitfield",): all_,
}
vfuncs = {}

tag_names = [
[("glib:signal",), signals],
[("field",), fields],
[("property",), properties],
[("parameter", "glib:signal"), sparas],
[("parameter", "function"), parameters],
[("parameter", "method"), parameters],
[("parameter", "callback"), parameters],
[("parameter", "constructor"), parameters],
[("instance-parameter", "method"), parameters],
[("return-value", "callback"), returns],
[("return-value", "method"), returns],
[("return-value", "function"), returns],
[("return-value", "constructor"), returns],
[("return-value", "glib:signal"), sreturns],
[("interface",), all_],
[("method",), all_],
[("function",), all_],
[("constant",), all_],
[("record",), all_],
[("enumeration",), all_],
[("member",), all_],
[("callback",), all_],
[("alias",), all_],
[("constructor",), all_],
[("class",), all_],
[("bitfield",), all_],
[("virtual-method",), all_],
]

def get_child_by_tag(node, tag_name):
for sub in node.childNodes:
Expand All @@ -272,7 +274,7 @@ def get_child_by_tag(node, tag_name):
path_seen = set()
path_done = set()

for target, result in tag_names.items():
for target, result in tag_names:
tag = target[0]
needed = target[1:]

Expand All @@ -284,7 +286,10 @@ def get_child_by_tag(node, tag_name):
deprecated_version = e.getAttribute("deprecated-version")

def get_name(elm):
return elm.getAttribute("name") or elm.getAttribute("glib:name")
n = elm.getAttribute("name") or elm.getAttribute("glib:name")
if elm.tagName == "virtual-method":
n = "do_" + n
return n

l = []
tags = []
Expand Down Expand Up @@ -318,7 +323,10 @@ def get_name(elm):
new = (docs, version, deprecated_version, deprecated)
# Atspi-2.0 has some things declared twice, so
# don't be too strict here.
assert key not in result or new == result[key], key

# We prefix vfuncs with "do_", but this could still clash here
if tag != "virtual-method":
assert key not in result or new == result[key], key
result[key] = new

# print path_seen - path_done
Expand Down
6 changes: 6 additions & 0 deletions pgidocgen/util.py
Expand Up @@ -239,6 +239,12 @@ def is_classmethod(obj):
return False


def is_virtualmethod(obj):
assert callable(obj)

return getattr(obj, "_is_virtual", False)


def is_normalmethod(obj):
return not is_staticmethod(obj) and not is_classmethod(obj)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_repo.py
Expand Up @@ -52,6 +52,12 @@ def test_returns(self):
ret = repo.lookup_return_docs("Gio.File.load_contents_finish")
self.assertTrue(ret.strip())

def test_vfuns(self):
repo = Repository("Gtk", "3.0")

ret = repo.lookup_attr_docs("Gtk.TreeModel.do_get_iter")
self.assertTrue(ret.strip())

def test_other(self):
Repository("GLib", "2.0")
Repository("GObject", "2.0")
Expand Down

0 comments on commit b581de7

Please sign in to comment.