Skip to main content

sphobjinv: Manipulate and inspect Sphinx objects.inv files

Current Development Version

GitHub Workflow Status Codecov Coverage

Most Recent Stable Release

PyPI Version Python Versions

Info

ReadTheDocs status gitter chat

MIT License black formatted PePY stats


Using Sphinx?

Having trouble writing cross-references?

sphobjinv (short for 'sphinx objects.inv') can help!

The syntax required for a functional Sphinx cross-reference is highly non-obvious in many cases. Sometimes Sphinx can guess correctly what you mean, but it's pretty hit-or-miss. The best approach is to provide Sphinx with a completely specified cross-reference, and that's where sphobjinv comes in.

After a pip install sphobjinv (or pipx install sphobjinv), find the documentation set you want to cross-reference into, and pass it to sphobjinv suggest.

For internal cross-references, locate objects.inv within build/html:

$ sphobjinv suggest doc/build/html/objects.inv as_rst -st 58

------------------------------------------------

Cannot infer intersphinx_mapping from a local objects.inv.

------------------------------------------------

Project: sphobjinv
Version: 2.3

220 objects in inventory.

------------------------------------------------

11 results found at/above current threshold of 58.


  Name                                                Score
---------------------------------------------------  -------
:py:property:`sphobjinv.data.SuperDataObj.as_rst`      60
:py:class:`sphobjinv.cli.parser.PrsConst`              59
:py:class:`sphobjinv.data.DataFields`                  59
:py:class:`sphobjinv.data.DataObjBytes`                59
:py:class:`sphobjinv.data.DataObjStr`                  59
:py:class:`sphobjinv.data.SuperDataObj`                59
:py:class:`sphobjinv.enum.HeaderFields`                59
:py:class:`sphobjinv.enum.SourceTypes`                 59
:py:function:`sphobjinv.fileops.writebytes`            59
:py:function:`sphobjinv.fileops.writejson`             59
:py:class:`sphobjinv.inventory.Inventory`              59

The -s argument in the above shell command indicates to print the fuzzywuzzy match score along with each search result, and -t 50 changes the reporting threshold for the match score.

For external references, find the API documentation wherever it lives on the web, and pass sphobjinv suggest a URL from within the documentation set with the --url/-u flag. For example, say I need to know how to cross-reference the linspace function from numpy (see here):

$ sphobjinv suggest https://numpy.org/doc/1.26/reference/index.html linspace -su

Attempting https://numpy.org/doc/1.26/reference/index.html ...
  ... no recognized inventory.
Attempting "https://numpy.org/doc/1.26/reference/index.html/objects.inv" ...
  ... HTTP error: 404 Not Found.
Attempting "https://numpy.org/doc/1.26/reference/objects.inv" ...
  ... HTTP error: 404 Not Found.
Attempting "https://numpy.org/doc/1.26/objects.inv" ...
  ... inventory found.

----------------------------------------------------------------------------------

The intersphinx_mapping for this docset is LIKELY:

  (https://numpy.org/doc/1.26/, None)

----------------------------------------------------------------------------------

Project: NumPy
Version: 1.26

8152 objects in inventory.

----------------------------------------------------------------------------------

8 results found at/above current threshold of 75.

  Name                                                           Score
--------------------------------------------------------------  -------
:py:function:`numpy.linspace`                                     90
:py:method:`numpy.polynomial.chebyshev.Chebyshev.linspace`        90
:py:method:`numpy.polynomial.hermite.Hermite.linspace`            90
:py:method:`numpy.polynomial.hermite_e.HermiteE.linspace`         90
:py:method:`numpy.polynomial.laguerre.Laguerre.linspace`          90
:py:method:`numpy.polynomial.legendre.Legendre.linspace`          90
:py:method:`numpy.polynomial.polynomial.Polynomial.linspace`      90
:std:doc:`reference/generated/numpy.linspace`                     90

NOTE that the results from sphobjinv suggest are printed using the longer block directives, whereas cross-references must be composed using the inline directives. Thus, the above linspace() function must be cross-referenced as :func:`numpy.linspace` , not :function:`numpy.linspace`.

Need to edit an inventory after it's created, or compose one from scratch?

sphobjinv can help with that, too.

objects.inv files can be decompressed to plaintext at the commandline:

$ sphobjinv convert plain -o doc/build/html/objects.inv doc/scratch/
Conversion completed.
'...objects.inv' converted to '...objects.txt' (plain).

JSON output is supported (sphobjinv convert json ...), and inventories can be re-compressed to the partially-zlib-compressed form that intersphinx reads (sphobjinv convert zlib ...).

Alternatively, sphobjinv exposes an API to enable automation of inventory creation/modification:

>>> import sphobjinv as soi
>>> inv = soi.Inventory('doc/build/html/objects.inv')
>>> print(inv)
<Inventory (fname_zlib): sphobjinv v2.3, 220 objects>
>>> inv.project
'sphobjinv'
>>> inv.version
'2.3'
>>> inv.objects[0]
DataObjStr(name='sphobjinv.cli.convert', domain='py', role='module', priority='0', uri='cli/implementation/convert.html#module-$', dispname='-')

The API also enables straightforward re-export of an inventory, for subsequent use with intersphinx cross-references. See the docs for more details.


Full documentation is hosted at Read The Docs.

Available on PyPI (pip install sphobjinv).

Source on GitHub. Bug reports and feature requests are welcomed at the Issues page there.

Copyright (c) Brian Skinn 2016-2024

The sphobjinv documentation (including docstrings and README) is licensed under a Creative Commons Attribution 4.0 International License (CC-BY). The sphobjinv codebase is released under the MIT License. See LICENSE.txt for full license terms.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphobjinv-2.3.1.2.tar.gz (268.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphobjinv-2.3.1.2-py3-none-any.whl (50.8 kB view details)

Uploaded Python 3

File details

Details for the file sphobjinv-2.3.1.2.tar.gz.

File metadata

  • Download URL: sphobjinv-2.3.1.2.tar.gz
  • Upload date:
  • Size: 268.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for sphobjinv-2.3.1.2.tar.gz
Algorithm Hash digest
SHA256 1c874a368460851352d45c92afa172b5c42653b47e2e70d78d61dac93308aa9d
MD5 069226ea6bb15ed387360303961919fb
BLAKE2b-256 8c5ecf2c54fcc6cc999f64d3a34edeee1ca69d6e1f8aee40772c5f3f036296dc

See more details on using hashes here.

File details

Details for the file sphobjinv-2.3.1.2-py3-none-any.whl.

File metadata

  • Download URL: sphobjinv-2.3.1.2-py3-none-any.whl
  • Upload date:
  • Size: 50.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for sphobjinv-2.3.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 66478d1787d28ef3ebeeedad57c592fdea04cf10eeed0df56307c85ab4eee789
MD5 1d92a4013c7c3eb05ebe38fc0d1b9f74
BLAKE2b-256 9c4d103e541e2533df159e1070cd4372b447a0b689e08a49d271b7b950e21f92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page