annotate doc/ext.py @ 1355:ba8a32b71356

icml07 - added comment
author James Bergstra <bergstrj@iro.umontreal.ca>
date Fri, 05 Nov 2010 13:29:07 -0400
parents 7edb78ba4c5b
children
rev   line source
912
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
1
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
2 import sys
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
3 import re
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
4 import os
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
5 from docutils import nodes, utils
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
6 from docutils.parsers.rst import roles
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
7 import epydoc.docwriter.xlink as xlink
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
8
913
7edb78ba4c5b Changed epy.doc slightly; commented a part concerning a wiki which does not seem to exist anymore; changed THEANO_API_ROOT to PYLEARN_API_ROOT
fsavard
parents: 912
diff changeset
9 #def role_fn(name, rawtext, text, lineno, inliner,
7edb78ba4c5b Changed epy.doc slightly; commented a part concerning a wiki which does not seem to exist anymore; changed THEANO_API_ROOT to PYLEARN_API_ROOT
fsavard
parents: 912
diff changeset
10 # options={}, content=[]):
7edb78ba4c5b Changed epy.doc slightly; commented a part concerning a wiki which does not seem to exist anymore; changed THEANO_API_ROOT to PYLEARN_API_ROOT
fsavard
parents: 912
diff changeset
11 # node = nodes.reference(rawtext, text, refuri = "http://pylearn.org/theano/wiki/%s" % text)
7edb78ba4c5b Changed epy.doc slightly; commented a part concerning a wiki which does not seem to exist anymore; changed THEANO_API_ROOT to PYLEARN_API_ROOT
fsavard
parents: 912
diff changeset
12 # return [node], []
912
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
13
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
14
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
15 _TARGET_RE = re.compile(r'^(.*?)\s*<(?:URI:|URL:)?([^<>]+)>$')
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
16 def create_api_role(name, problematic):
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
17 """
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
18 Create and register a new role to create links for an API documentation.
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
19
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
20 Create a role called `name`, which will use the URL resolver registered as
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
21 ``name`` in `api_register` to create a link for an object.
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
22
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
23 :Parameters:
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
24 `name` : `str`
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
25 name of the role to create.
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
26 `problematic` : `bool`
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
27 if True, the registered role will create problematic nodes in
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
28 case of failed references. If False, a warning will be raised
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
29 anyway, but the output will appear as an ordinary literal.
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
30 """
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
31 def resolve_api_name(n, rawtext, text, lineno, inliner,
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
32 options={}, content=[]):
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
33
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
34 # Check if there's separate text & targets
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
35 m = _TARGET_RE.match(text)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
36 if m: text, target = m.groups()
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
37 else: target = text
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
38
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
39 # node in monotype font
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
40 text = utils.unescape(text)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
41 node = nodes.literal(rawtext, text, **options)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
42
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
43 # Get the resolver from the register and create an url from it.
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
44 try:
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
45 url = xlink.api_register[name].get_url(target)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
46 except IndexError, exc:
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
47 msg = inliner.reporter.warning(str(exc), line=lineno)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
48 if problematic:
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
49 prb = inliner.problematic(rawtext, text, msg)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
50 return [prb], [msg]
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
51 else:
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
52 return [node], []
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
53
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
54 if url is not None:
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
55 node = nodes.reference(rawtext, '', node, refuri=url, **options)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
56 return [node], []
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
57
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
58 roles.register_local_role(name, resolve_api_name)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
59
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
60
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
61 def setup(app):
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
62
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
63 try:
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
64 xlink.set_api_file('api', os.path.join(app.outdir, 'api', 'api-objects.txt'))
913
7edb78ba4c5b Changed epy.doc slightly; commented a part concerning a wiki which does not seem to exist anymore; changed THEANO_API_ROOT to PYLEARN_API_ROOT
fsavard
parents: 912
diff changeset
65 apiroot = os.getenv('PYLEARN_API_ROOT')
912
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
66 if not apiroot:
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
67 apiroot = os.path.join(os.path.realpath('api'), '')
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
68 xlink.set_api_root('api', apiroot)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
69 #xlink.create_api_role('api', True)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
70 create_api_role('api', True)
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
71 except IOError:
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
72 print >>sys.stderr, 'WARNING: Could not find api file! API links will not work.'
0354b682c289 Added ext.py from Theano/doc, with some changes
fsavard
parents:
diff changeset
73
913
7edb78ba4c5b Changed epy.doc slightly; commented a part concerning a wiki which does not seem to exist anymore; changed THEANO_API_ROOT to PYLEARN_API_ROOT
fsavard
parents: 912
diff changeset
74 #app.add_role("wiki", role_fn)
7edb78ba4c5b Changed epy.doc slightly; commented a part concerning a wiki which does not seem to exist anymore; changed THEANO_API_ROOT to PYLEARN_API_ROOT
fsavard
parents: 912
diff changeset
75