Skip to content

Commit c9f2ffe

Browse files
author
Sam Kleinman
committed
sphinx: improvements to link resolution and indexing
1 parent 065a937 commit c9f2ffe

File tree

1 file changed

+54
-42
lines changed

1 file changed

+54
-42
lines changed

bin/mongodb_domain.py

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -86,53 +86,55 @@ def add_target_and_index(self, name_obj, sig, signode):
8686
objectname = self.options.get(
8787
'object', self.env.temp_data.get('mongodb:object'))
8888

89-
if self.objtype == 'binary':
89+
if self.objtype == 'dbcommand':
90+
fullname = 'dbcmd.' + name_obj[0]
91+
elif self.objtype == 'binary':
9092
fullname = 'bin.' + name_obj[0]
93+
elif name_obj[0] in self.state.document.ids:
94+
fullname = 'iddup.' + name_obj[0]
9195
else:
9296
fullname = name_obj[0]
9397

94-
if fullname not in self.state.document.ids:
95-
signode['names'].append(fullname)
96-
signode['ids'].append(fullname.replace('$', '_S_'))
97-
signode['first'] = not self.names
98-
self.state.document.note_explicit_target(signode)
99-
objects = self.env.domaindata['mongodb']['objects']
100-
if fullname in objects:
101-
path = self.env.doc2path(self.env.domaindata['mongodb']['objects'][fullname][0])
102-
spath = basename(path)
103-
sspath = basename(self.state_machine.reporter.source)
104-
105-
if spath in composite_pages:
106-
pass
107-
elif sspath in composite_pages:
108-
pass
109-
elif spath == fullname:
110-
pass
111-
elif spath == fullname.lstrip('$'):
112-
pass
113-
elif spath == fullname.lstrip('_'):
114-
pass
115-
elif path == self.state_machine.reporter.source:
116-
pass
117-
elif fullname.startswith(spath):
118-
pass
119-
elif fullname == '$':
120-
pass
121-
# temporary: silencing the positional operator
122-
# warning, this is the namespace clash for
123-
# projection and query/update operators.
124-
else:
125-
self.state_machine.reporter.warning(
126-
'duplicate object description of "%s", ' % fullname +
127-
'other instance in ' + path,
128-
line=self.lineno)
129-
130-
if self.env.docname.rsplit('/', 1)[1] in composite_pages:
98+
signode['names'].append(fullname)
99+
signode['ids'].append(fullname.replace('$', '_S_'))
100+
signode['first'] = not self.names
101+
self.state.document.note_explicit_target(signode)
102+
objects = self.env.domaindata['mongodb']['objects']
103+
if fullname in objects:
104+
path = self.env.doc2path(self.env.domaindata['mongodb']['objects'][fullname][0])
105+
spath = basename(path)
106+
sspath = basename(self.state_machine.reporter.source)
107+
108+
if spath in composite_pages:
109+
pass
110+
elif sspath in composite_pages:
111+
pass
112+
elif spath == fullname:
113+
pass
114+
elif spath == fullname.lstrip('$'):
115+
pass
116+
elif spath == fullname.lstrip('_'):
117+
pass
118+
elif path == self.state_machine.reporter.source:
131119
pass
120+
elif fullname.startswith(spath):
121+
pass
122+
elif fullname == '$':
123+
pass
124+
# temporary: silencing the positional operator
125+
# warning, this is the namespace clash for
126+
# projection and query/update operators.
132127
else:
133-
objects[fullname] = self.env.docname, self.objtype
128+
self.state_machine.reporter.warning(
129+
'duplicate object description of "%s", ' % fullname +
130+
'other instance in ' + path,
131+
line=self.lineno)
132+
133+
if self.env.docname.rsplit('/', 1)[1] in composite_pages:
134+
pass
134135
else:
135-
print('[sphinx]: object "' + fullname + '" not cross reference-able because of collision')
136+
objects[fullname] = self.env.docname, self.objtype
137+
136138

137139
indextext = self.get_index_text(objectname, name_obj)
138140
if indextext:
@@ -294,6 +296,9 @@ def find_obj(self, env, obj, name, typ, searchorder=0):
294296
if typ == 'program':
295297
name = 'bin.' + name
296298
newname = name
299+
elif typ == 'dbcommand':
300+
name = 'dbcmd.' + name
301+
newname = name
297302

298303
searchorder = 1
299304

@@ -316,11 +321,18 @@ def resolve_xref(self, env, fromdocname, builder, typ, target, node,
316321
searchorder = node.hasattr('refspecific') and 1 or 0
317322
name, obj = self.find_obj(env, objectname, target, typ, searchorder)
318323

319-
if not obj:
320-
return None
324+
if obj is None:
325+
name, obj = self.find_obj(env, 'iddup' + name, target, typ, searchorder)
326+
if obj is None:
327+
return None
321328

322329
if name.startswith('bin.'):
323330
name = name.split('.', 1)[1]
331+
elif name.startswith('dbcmd.'):
332+
name = name.split('.', 1)[1]
333+
elif name.startswith('iddup.'):
334+
name = name.split('.', 1)[1]
335+
324336

325337
return make_refnode(builder, fromdocname, obj[0],
326338
name.replace('$', '_S_'), contnode, name)

0 commit comments

Comments
 (0)