Last active
January 5, 2021 01:00
-
-
Save acsr/fb7b5cf97627f70876ceeae031cd37f1 to your computer and use it in GitHub Desktop.
patch sphinx.ext.intersphinx output tweaking the main function to using almost csv compatible tab separators instead of columns adjusted by spaces
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
#!./bin/python | |
# -*- coding: utf-8 -*- | |
""" | |
inspect_objects | |
based on and requiring sphinx.ext.intersphinx | |
~~~~~~~~~~~~~~~~~~~~~~ | |
List links to objects documented in as build Sphinx documentation. | |
Usage: ./bin/python inspect_objects.py _build/html/objects.inv > objects_inventory.csv | |
This works as follows: | |
* Each Sphinx HTML build creates a file named "objects.inv" that contains a | |
mapping from object names to URIs relative to the HTML set's root. | |
* This is a modified call of the main function of intersphinx to export the | |
List of object as pure tab delimited file instead of the aligned text with | |
justified spaces. It is much better suitable for postproceessing than the | |
regular output aiming at programmers for a quick look during debugging. | |
* By default, the mapping file is assumed to be at the same location as the | |
rest of the documentation; however, the location of the mapping file can | |
also be specified individually, e.g. if the docs should be buildable | |
without Internet access. | |
:copyright: Copyright of the source sphinx.ext.intersphinx 2007-2018 by the Sphinx team, see AUTHORS. | |
:license: BSD, see LICENSE for details. | |
""" | |
from __future__ import print_function | |
import functools | |
import posixpath | |
import sys | |
import time | |
import warnings | |
from os import path | |
from docutils import nodes | |
from docutils.utils import relative_path | |
from six import PY3, iteritems, string_types | |
from six.moves.urllib.parse import urlsplit, urlunsplit | |
import sphinx | |
from sphinx.builders.html import INVENTORY_FILENAME | |
from sphinx.deprecation import RemovedInSphinx20Warning | |
from sphinx.locale import _, __ | |
from sphinx.util import requests, logging | |
from sphinx.util.inventory import InventoryFile | |
from sphinx.ext.intersphinx import * | |
if False: | |
# For type annotation | |
from typing import Any, Dict, IO, List, Tuple, Union # NOQA | |
from sphinx.application import Sphinx # NOQA | |
from sphinx.config import Config # NOQA | |
from sphinx.environment import BuildEnvironment # NOQA | |
if PY3: | |
unicode = str | |
Inventory = Dict[unicode, Dict[unicode, Tuple[unicode, unicode, unicode, unicode]]] | |
logger = logging.getLogger(__name__) | |
def inspect_main_csv(argv): | |
# type: (List[unicode]) -> None | |
"""Debug functionality to print out an inventory""" | |
if len(argv) < 1: | |
print("Print out an inventory file.\n" | |
"Error: must specify local path or URL to an inventory file.", | |
file=sys.stderr) | |
sys.exit(1) | |
class MockConfig(object): | |
intersphinx_timeout = None # type: int | |
tls_verify = False | |
class MockApp(object): | |
srcdir = '' | |
config = MockConfig() | |
def warn(self, msg): | |
# type: (unicode) -> None | |
print(msg, file=sys.stderr) | |
try: | |
filename = argv[0] | |
invdata = fetch_inventory(MockApp(), '', filename) # type: ignore | |
for key in sorted(invdata or {}): | |
print(key) | |
for entry, einfo in sorted(invdata[key].items()): | |
print('\t%s\t%s\t%s' % (entry, | |
einfo[3] != '-' and '%s' % einfo[3] or '', | |
einfo[2])) | |
except ValueError as exc: | |
print(exc.args[0] % exc.args[1:]) | |
except Exception as exc: | |
print('Unknown error: %r' % exc) | |
if __name__ == '__main__': | |
import logging # type: ignore | |
logging.basicConfig() # type: ignore | |
inspect_main_csv(argv=sys.argv[1:]) # type: ignore |
Changed the print output to create pure tab delimited output. (Compare to Gist revision 1 original version) https://gist.github.com/acsr/fb7b5cf97627f70876ceeae031cd37f1/revisions
Replaced the patched version of https://github.com/sphinx-doc/sphinx/blob/master/sphinx/ext/intersphinx.py by the inspect_objects.py script calling the regular module and tweak the main function during runtime.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initial commit of unchanged file from https://github.com/sphinx-doc/sphinx/blob/master/sphinx/ext/intersphinx.py to be changed at https://github.com/sphinx-doc/sphinx/blob/36d628929ef45c2e6225bfb5470080be77056629/sphinx/ext/intersphinx.py#L407