-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from hynek/intersphinx
Use intersphinx files for symbol mining Fixes #27
- Loading branch information
Showing
13 changed files
with
203 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
include *.rst *.txt LICENSE tox.ini .travis.yml M | ||
recursive-include tests *.py *.html | ||
include *.rst *.txt LICENSE tox.ini .travis.yml | ||
recursive-include tests *.py *.html *.inv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import logging | ||
import os | ||
|
||
from six import iteritems | ||
from sphinx.ext.intersphinx import read_inventory_v2 | ||
|
||
from . import types | ||
from .base import _BaseParser | ||
from .sphinx import find_and_patch_entry | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
INV_TO_TYPE = { | ||
"attribute": types.ATTRIBUTE, | ||
"class": types.CLASS, | ||
"classmethod": types.METHOD, | ||
"data": types.VALUE, | ||
"envvar": types.ENV, | ||
"exception": types.EXCEPTION, | ||
"function": types.FUNCTION, | ||
"interface": types.INTERFACE, | ||
"macro": types.MACRO, | ||
"member": types.ATTRIBUTE, | ||
"method": types.METHOD, | ||
"module": types.PACKAGE, | ||
"opcode": types.OPCODE, | ||
"option": types.OPTION, | ||
"staticmethod": types.METHOD, | ||
"type": types.TYPE, | ||
"variable": types.VARIABLE, | ||
"var": types.VARIABLE, | ||
} | ||
|
||
|
||
class InterSphinxParser(_BaseParser): | ||
""" | ||
Parser for Sphinx-base documentation that generates an objects.inv file for | ||
the intersphinx extension. | ||
""" | ||
name = "intersphinx" | ||
|
||
DETECT_FILE = "objects.inv" | ||
DETECT_PATTERN = b"# Sphinx inventory version 2" | ||
|
||
def parse(self): | ||
""" | ||
Parse sphinx docs at self.docpath. | ||
yield tuples of symbol name, type and path | ||
""" | ||
log.info('Creating database...') | ||
with open(os.path.join(self.docpath, "objects.inv"), "rb") as inv_f: | ||
inv_f.readline() # skip version line that is verified in detection | ||
for t in _inv_to_elements( | ||
read_inventory_v2(inv_f, "", os.path.join) | ||
): # this is what Guido gave us `yield from` for :-| | ||
yield t | ||
|
||
def find_and_patch_entry(self, soup, entry): # pragma: nocover | ||
return find_and_patch_entry(soup, entry) | ||
|
||
|
||
def _inv_to_elements(inv): | ||
""" | ||
Iterate over a dictionary as returned from Sphinx's object.inv parser and | ||
yield `name, type, path` tuples. | ||
""" | ||
for type_key, val in iteritems(inv): | ||
try: | ||
t = INV_TO_TYPE[type_key.split(":")[-1]] | ||
for el, data in iteritems(val): | ||
yield el, t, data[2] | ||
except KeyError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
CLASS = 'cl' | ||
PACKAGE = 'Module' | ||
METHOD = 'clm' | ||
FUNCTION = 'func' | ||
ATTRIBUTE = 'Attribute' | ||
CONSTANT = 'clconst' | ||
ATTRIBUTE = "Attribute" | ||
CLASS = "Class" | ||
CONSTANT = "Constant" | ||
ENV = "Environment" | ||
EXCEPTION = "Exception" | ||
FUNCTION = "Function" | ||
INTERFACE = "Interface" | ||
MACRO = "Macro" | ||
METHOD = "Method" | ||
OPCODE = "Operator" | ||
OPTION = "Option" | ||
PACKAGE = "Module" | ||
TYPE = "Type" | ||
VALUE = "Value" | ||
VARIABLE = "Variable" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import os | ||
|
||
from doc2dash.parsers.intersphinx import InterSphinxParser | ||
|
||
|
||
HERE = os.path.dirname(__file__) | ||
|
||
|
||
class TestInterSphinxParser(object): | ||
def test_parses(self): | ||
""" | ||
Parsing does not fail. | ||
""" | ||
p = InterSphinxParser(os.path.join(HERE)) | ||
for t in p.parse(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.