mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Change naming convention in doc_read_data to "domain:key".
This commit is contained in:
parent
2a2a66a923
commit
54a31c5a6f
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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('-')):
|
||||
|
@ -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."""
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)]
|
||||
|
@ -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')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user