From 54a31c5a6f5a21778ac6b09c0699cf799df5062a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 13 Jan 2010 20:45:34 +0100 Subject: [PATCH] Change naming convention in doc_read_data to "domain:key". --- sphinx/directives/other.py | 3 ++- sphinx/domains/python.py | 28 ++++++++++++++-------------- sphinx/domains/std.py | 8 ++++---- sphinx/environment.py | 4 ++-- sphinx/ext/autodoc.py | 20 ++++++++++---------- sphinx/ext/autosummary/__init__.py | 2 +- sphinx/ext/inheritance_diagram.py | 2 +- tests/test_autodoc.py | 24 ++++++++++++------------ 8 files changed, 46 insertions(+), 45 deletions(-) diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index a347970c9..1ba6e3bcc 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -215,7 +215,8 @@ class VersionChange(Directive): env = self.state.document.settings.env env.versionchanges.setdefault(node['version'], []).append( (node['type'], env.doc_read_data['docname'], self.lineno, - env.doc_read_data.get('py_module'), + # XXX: python domain specific + env.doc_read_data.get('py:module'), env.doc_read_data.get('object'), node.astext())) return ret diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 46b938981..cec571880 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -67,7 +67,7 @@ class PyObject(ObjectDescription): raise ValueError classname, name, arglist, retann = m.groups() - currclass = self.env.doc_read_data.get('py_class') + currclass = self.env.doc_read_data.get('py:class') if currclass: add_module = False if classname and classname.startswith(currclass): @@ -95,7 +95,7 @@ class PyObject(ObjectDescription): # 'exceptions' module. elif add_module and self.env.config.add_module_names: modname = self.options.get( - 'module', self.env.doc_read_data.get('py_module')) + 'module', self.env.doc_read_data.get('py:module')) if modname and modname != 'exceptions': nodetext = modname + '.' signode += addnodes.desc_addname(nodetext, nodetext) @@ -140,7 +140,7 @@ class PyObject(ObjectDescription): def add_target_and_index(self, name_cls, sig, signode): modname = self.options.get( - 'module', self.env.doc_read_data.get('py_module')) + 'module', self.env.doc_read_data.get('py:module')) fullname = (modname and modname + '.' or '') + name_cls[0] # note target if fullname not in self.state.document.ids: @@ -169,7 +169,7 @@ class PyObject(ObjectDescription): def after_content(self): if self.clsname_set: - self.env.doc_read_data['py_class'] = None + self.env.doc_read_data['py:class'] = None class PyModulelevel(PyObject): @@ -214,7 +214,7 @@ class PyClasslike(PyObject): def before_content(self): PyObject.before_content(self) if self.names: - self.env.doc_read_data['py_class'] = self.names[0][0] + self.env.doc_read_data['py:class'] = self.names[0][0] self.clsname_set = True @@ -292,8 +292,8 @@ class PyClassmember(PyObject): def before_content(self): PyObject.before_content(self) lastname = self.names and self.names[-1][1] - if lastname and not self.env.doc_read_data.get('py_class'): - self.env.doc_read_data['py_class'] = lastname.strip('.') + if lastname and not self.env.doc_read_data.get('py:class'): + self.env.doc_read_data['py:class'] = lastname.strip('.') self.clsname_set = True @@ -317,7 +317,7 @@ class PyModule(Directive): env = self.state.document.settings.env modname = self.arguments[0].strip() noindex = 'noindex' in self.options - env.doc_read_data['py_module'] = modname + env.doc_read_data['py:module'] = modname env.domaindata['py']['modules'][modname] = \ (env.docname, self.options.get('synopsis', ''), self.options.get('platform', ''), 'deprecated' in self.options) @@ -361,16 +361,16 @@ class PyCurrentModule(Directive): env = self.state.document.settings.env modname = self.arguments[0].strip() if modname == 'None': - env.doc_read_data['py_module'] = None + env.doc_read_data['py:module'] = None else: - env.doc_read_data['py_module'] = modname + env.doc_read_data['py:module'] = modname return [] class PyXRefRole(XRefRole): def process_link(self, env, refnode, has_explicit_title, title, target): - refnode['py_module'] = env.doc_read_data.get('py_module') - refnode['py_class'] = env.doc_read_data.get('py_class') + refnode['py:module'] = env.doc_read_data.get('py:module') + refnode['py:class'] = env.doc_read_data.get('py:class') if not has_explicit_title: title = title.lstrip('.') # only has a meaning for the target target = target.lstrip('~') # only has a meaning for the title @@ -497,8 +497,8 @@ class PythonDomain(Domain): return make_refnode(builder, fromdocname, docname, 'module-' + target, contnode, title) else: - modname = node.get('py_module') - clsname = node.get('py_class') + modname = node.get('py:module') + clsname = node.get('py:class') searchorder = node.hasattr('refspecific') and 1 or 0 name, obj = self.find_obj(env, modname, clsname, target, typ, searchorder) diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 38a181981..16de4277f 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -146,7 +146,7 @@ class Cmdoption(ObjectDescription): def add_target_and_index(self, name, sig, signode): targetname = name.replace('/', '-') - currprogram = self.env.doc_read_data.get('std_program') + currprogram = self.env.doc_read_data.get('std:program') if currprogram: targetname = '-' + currprogram + targetname targetname = 'cmdoption' + targetname @@ -175,9 +175,9 @@ class Program(Directive): env = self.state.document.settings.env program = ws_re.sub('-', self.arguments[0].strip()) if program == 'None': - env.doc_read_data['std_program'] = None + env.doc_read_data['std:program'] = None else: - env.doc_read_data['std_program'] = program + env.doc_read_data['std:program'] = program return [] @@ -185,7 +185,7 @@ class OptionXRefRole(XRefRole): innernodeclass = addnodes.literal_emphasis def process_link(self, env, refnode, has_explicit_title, title, target): - program = env.doc_read_data.get('std_program') + program = env.doc_read_data.get('std:program') if not has_explicit_title: if ' ' in title and not (title.startswith('/') or title.startswith('-')): diff --git a/sphinx/environment.py b/sphinx/environment.py index 9626924f6..2ce3cc983 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -713,12 +713,12 @@ class BuildEnvironment: @property def currmodule(self): """Backwards compatible alias.""" - return self.doc_read_data.get('py_module') + return self.doc_read_data.get('py:module') @property def currclass(self): """Backwards compatible alias.""" - return self.doc_read_data.get('py_class') + return self.doc_read_data.get('py:class') def new_serialno(self, category=''): """Return a serial number, e.g. for index entry targets.""" diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index b74b8f9be..53625dde8 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -562,9 +562,9 @@ class Documenter(object): do all members, else those given by *self.options.members*. """ # set current namespace for finding members - self.env.doc_read_data['autodoc_module'] = self.modname + self.env.doc_read_data['autodoc:module'] = self.modname if self.objpath: - self.env.doc_read_data['autodoc_class'] = self.objpath[0] + self.env.doc_read_data['autodoc:class'] = self.objpath[0] want_all = all_members or self.options.inherited_members or \ self.options.members is ALL @@ -605,8 +605,8 @@ class Documenter(object): check_module=members_check_module) # reset current objects - self.env.doc_read_data['autodoc_module'] = None - self.env.doc_read_data['autodoc_class'] = None + self.env.doc_read_data['autodoc:module'] = None + self.env.doc_read_data['autodoc:class'] = None def generate(self, more_content=None, real_modname=None, check_module=False, all_members=False): @@ -764,10 +764,10 @@ class ModuleLevelDocumenter(Documenter): else: # if documenting a toplevel object without explicit module, # it can be contained in another auto directive ... - modname = self.env.doc_read_data.get('autodoc_module') + modname = self.env.doc_read_data.get('autodoc:module') # ... or in the scope of a module directive if not modname: - modname = self.env.doc_read_data.get('py_module') + modname = self.env.doc_read_data.get('py:module') # ... else, it stays None, which means invalid return modname, parents + [base] @@ -786,10 +786,10 @@ class ClassLevelDocumenter(Documenter): # if documenting a class-level object without path, # there must be a current class, either from a parent # auto directive ... - mod_cls = self.env.doc_read_data.get('autodoc_class') + mod_cls = self.env.doc_read_data.get('autodoc:class') # ... or from a class directive if mod_cls is None: - mod_cls = self.env.doc_read_data.get('py_class') + mod_cls = self.env.doc_read_data.get('py:class') # ... if still None, there's no way to know if mod_cls is None: return None, [] @@ -797,9 +797,9 @@ class ClassLevelDocumenter(Documenter): parents = [cls] # if the module name is still missing, get it like above if not modname: - modname = self.env.doc_read_data.get('autodoc_module') + modname = self.env.doc_read_data.get('autodoc:module') if not modname: - modname = self.env.doc_read_data.get('py_module') + modname = self.env.doc_read_data.get('py:module') # ... else, it stays None, which means invalid return modname, parents + [base] diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 0e3bdf16e..99d895870 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -228,7 +228,7 @@ class Autosummary(Directive): env = self.state.document.settings.env prefixes = [''] - currmodule = env.doc_read_data.get('py_module') + currmodule = env.doc_read_data.get('py:module') if currmodule: prefixes.insert(0, currmodule) diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index 236a79335..1fb8b0b2f 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -284,7 +284,7 @@ class InheritanceDiagram(Directive): # Create a graph starting with the list of classes try: graph = InheritanceGraph(class_names, - env.doc_read_data.get('py_module')) + env.doc_read_data.get('py:module')) except InheritanceException, err: return [node.document.reporter.warning(err.args[0], line=self.lineno)] diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index c594b76af..b4dd2c449 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -97,28 +97,28 @@ def test_parse_name(): verify('function', 'util.raises', ('util', ['raises'], None, None)) verify('function', 'util.raises(exc) -> None', ('util', ['raises'], 'exc', 'None')) - directive.env.doc_read_data['autodoc_module'] = 'util' + directive.env.doc_read_data['autodoc:module'] = 'util' verify('function', 'raises', ('util', ['raises'], None, None)) - del directive.env.doc_read_data['autodoc_module'] - directive.env.doc_read_data['py_module'] = 'util' + del directive.env.doc_read_data['autodoc:module'] + directive.env.doc_read_data['py:module'] = 'util' verify('function', 'raises', ('util', ['raises'], None, None)) verify('class', 'TestApp', ('util', ['TestApp'], None, None)) # for members - directive.env.doc_read_data['py_module'] = 'foo' + directive.env.doc_read_data['py:module'] = 'foo' verify('method', 'util.TestApp.cleanup', ('util', ['TestApp', 'cleanup'], None, None)) - directive.env.doc_read_data['py_module'] = 'util' - directive.env.doc_read_data['py_class'] = 'Foo' - directive.env.doc_read_data['autodoc_class'] = 'TestApp' + directive.env.doc_read_data['py:module'] = 'util' + directive.env.doc_read_data['py:class'] = 'Foo' + directive.env.doc_read_data['autodoc:class'] = 'TestApp' verify('method', 'cleanup', ('util', ['TestApp', 'cleanup'], None, None)) verify('method', 'TestApp.cleanup', ('util', ['TestApp', 'cleanup'], None, None)) # and clean up - del directive.env.doc_read_data['py_module'] - del directive.env.doc_read_data['py_class'] - del directive.env.doc_read_data['autodoc_class'] + del directive.env.doc_read_data['py:module'] + del directive.env.doc_read_data['py:class'] + del directive.env.doc_read_data['autodoc:class'] def test_format_signature(): @@ -353,7 +353,7 @@ def test_generate(): 'function', 'util.foobar', more_content=None) # test auto and given content mixing - directive.env.doc_read_data['py_module'] = 'test_autodoc' + directive.env.doc_read_data['py:module'] = 'test_autodoc' assert_result_contains(' Function.', 'method', 'Class.meth') add_content = ViewList() add_content.append('Content.', '', 0) @@ -437,7 +437,7 @@ def test_generate(): 'attribute', 'test_autodoc.Class.descr') # test generation for C modules (which have no source file) - directive.env.doc_read_data['py_module'] = 'time' + directive.env.doc_read_data['py:module'] = 'time' assert_processes([('function', 'time.asctime')], 'function', 'asctime') assert_processes([('function', 'time.asctime')], 'function', 'asctime')