|
| 1 | +## sphobjinv: Manipulate and inspect Sphinx objects.inv files |
| 2 | + |
| 3 | + |
| 4 | +#### Current Development Version |
| 5 | + |
| 6 | +[![GitHub Workflow Status][workflow badge]][workflow link target] |
| 7 | +[![Codecov Coverage][codecov badge]][codecov target] |
| 8 | + |
| 9 | +#### Most Recent Stable Release |
| 10 | + |
| 11 | +[![PyPI Version][pypi badge]][pypi link target] |
| 12 | +![Python Versions][python versions badge] |
| 13 | + |
| 14 | +#### Info |
| 15 | + |
| 16 | +[![ReadTheDocs status][readthedocs badge]][readthedocs link target] |
| 17 | +[![gitter chat][gitter badge]][gitter link target] |
| 18 | + |
| 19 | +[![MIT License][license badge]][license link target] |
| 20 | +[![black formatted][black badge]][black link target] |
| 21 | +[![PePY stats][pepy badge]][pepy link target] |
| 22 | + |
| 23 | +---- |
| 24 | + |
| 25 | +### Using Sphinx? |
| 26 | + |
| 27 | +#### Having trouble writing cross-references? |
| 28 | + |
| 29 | +`sphobjinv` (short for '**sph**inx **obj**ects.**inv**') can help! |
| 30 | + |
| 31 | +The syntax required for a functional Sphinx cross-reference is highly |
| 32 | +non-obvious in many cases. Sometimes Sphinx can guess correctly what |
| 33 | +you mean, but it's pretty hit-or-miss. The best approach is to provide |
| 34 | +Sphinx with a completely specified cross-reference, and that's where |
| 35 | +`sphobjinv` comes in. |
| 36 | + |
| 37 | +After a `pip install sphobjinv` (or `pipx install sphobjinv`), find the |
| 38 | +documentation set you want to cross-reference into, and pass it to |
| 39 | +`sphobjinv suggest`. |
| 40 | + |
| 41 | +For internal cross-references, locate `objects.inv` within `build/html`: |
| 42 | + |
| 43 | +```none |
| 44 | +$ sphobjinv suggest doc/build/html/objects.inv as_rst -st 58 |
| 45 | +
|
| 46 | +------------------------------------------------ |
| 47 | +
|
| 48 | +Cannot infer intersphinx_mapping from a local objects.inv. |
| 49 | +
|
| 50 | +------------------------------------------------ |
| 51 | +
|
| 52 | +Project: sphobjinv |
| 53 | +Version: 2.3 |
| 54 | +
|
| 55 | +220 objects in inventory. |
| 56 | +
|
| 57 | +------------------------------------------------ |
| 58 | +
|
| 59 | +11 results found at/above current threshold of 58. |
| 60 | +
|
| 61 | +
|
| 62 | + Name Score |
| 63 | +--------------------------------------------------- ------- |
| 64 | +:py:property:`sphobjinv.data.SuperDataObj.as_rst` 60 |
| 65 | +:py:class:`sphobjinv.cli.parser.PrsConst` 59 |
| 66 | +:py:class:`sphobjinv.data.DataFields` 59 |
| 67 | +:py:class:`sphobjinv.data.DataObjBytes` 59 |
| 68 | +:py:class:`sphobjinv.data.DataObjStr` 59 |
| 69 | +:py:class:`sphobjinv.data.SuperDataObj` 59 |
| 70 | +:py:class:`sphobjinv.enum.HeaderFields` 59 |
| 71 | +:py:class:`sphobjinv.enum.SourceTypes` 59 |
| 72 | +:py:function:`sphobjinv.fileops.writebytes` 59 |
| 73 | +:py:function:`sphobjinv.fileops.writejson` 59 |
| 74 | +:py:class:`sphobjinv.inventory.Inventory` 59 |
| 75 | +``` |
| 76 | + |
| 77 | +The `-s` argument in the above shell command indicates to print the |
| 78 | +`fuzzywuzzy` match score along with each search result, and `-t 50` |
| 79 | +changes the reporting threshold for the match score. |
| 80 | + |
| 81 | +For external references, find the API documentation wherever it lives on |
| 82 | +the web, and pass `sphobjinv suggest` a URL from within the documentation set |
| 83 | +with the `--url/-u` flag. For example, say I need to know how to |
| 84 | +cross-reference the `linspace` function from numpy (see |
| 85 | +[here][numpy linspace]): |
| 86 | + |
| 87 | +```none |
| 88 | +$ sphobjinv suggest https://numpy.org/doc/1.26/reference/index.html linspace -su |
| 89 | +
|
| 90 | +Attempting https://numpy.org/doc/1.26/reference/index.html ... |
| 91 | + ... no recognized inventory. |
| 92 | +Attempting "https://numpy.org/doc/1.26/reference/index.html/objects.inv" ... |
| 93 | + ... HTTP error: 404 Not Found. |
| 94 | +Attempting "https://numpy.org/doc/1.26/reference/objects.inv" ... |
| 95 | + ... HTTP error: 404 Not Found. |
| 96 | +Attempting "https://numpy.org/doc/1.26/objects.inv" ... |
| 97 | + ... inventory found. |
| 98 | +
|
| 99 | +---------------------------------------------------------------------------------- |
| 100 | +
|
| 101 | +The intersphinx_mapping for this docset is LIKELY: |
| 102 | +
|
| 103 | + (https://numpy.org/doc/1.26/, None) |
| 104 | +
|
| 105 | +---------------------------------------------------------------------------------- |
| 106 | +
|
| 107 | +Project: NumPy |
| 108 | +Version: 1.26 |
| 109 | +
|
| 110 | +8152 objects in inventory. |
| 111 | +
|
| 112 | +---------------------------------------------------------------------------------- |
| 113 | +
|
| 114 | +8 results found at/above current threshold of 75. |
| 115 | +
|
| 116 | + Name Score |
| 117 | +-------------------------------------------------------------- ------- |
| 118 | +:py:function:`numpy.linspace` 90 |
| 119 | +:py:method:`numpy.polynomial.chebyshev.Chebyshev.linspace` 90 |
| 120 | +:py:method:`numpy.polynomial.hermite.Hermite.linspace` 90 |
| 121 | +:py:method:`numpy.polynomial.hermite_e.HermiteE.linspace` 90 |
| 122 | +:py:method:`numpy.polynomial.laguerre.Laguerre.linspace` 90 |
| 123 | +:py:method:`numpy.polynomial.legendre.Legendre.linspace` 90 |
| 124 | +:py:method:`numpy.polynomial.polynomial.Polynomial.linspace` 90 |
| 125 | +:std:doc:`reference/generated/numpy.linspace` 90 |
| 126 | +``` |
| 127 | + |
| 128 | +**NOTE** that the results from `sphobjinv suggest` are printed using the |
| 129 | +longer *block directives*, whereas cross-references must be composed using the |
| 130 | +*inline directives*. Thus, the above `linspace()` function must be |
| 131 | +cross-referenced as ``` :func:`numpy.linspace` ``` , **not** |
| 132 | +``` :function:`numpy.linspace` ```. |
| 133 | + |
| 134 | +**Need to edit an inventory after it's created, or compose one from scratch?** |
| 135 | + |
| 136 | +`sphobjinv` can help with that, too. |
| 137 | + |
| 138 | +`objects.inv` files can be decompressed to plaintext at the commandline: |
| 139 | + |
| 140 | +```none |
| 141 | +$ sphobjinv convert plain -o doc/build/html/objects.inv doc/scratch/ |
| 142 | +Conversion completed. |
| 143 | +'...objects.inv' converted to '...objects.txt' (plain). |
| 144 | +``` |
| 145 | + |
| 146 | +JSON output is supported (`sphobjinv convert json ...`), and |
| 147 | +inventories can be re-compressed to the |
| 148 | +partially-zlib-compressed form that `intersphinx` reads |
| 149 | +(`sphobjinv convert zlib ...`). |
| 150 | + |
| 151 | +Alternatively, `sphobjinv` exposes an API to enable automation of |
| 152 | +inventory creation/modification: |
| 153 | + |
| 154 | +```python |
| 155 | +>>> import sphobjinv as soi |
| 156 | +>>> inv = soi.Inventory('doc/build/html/objects.inv') |
| 157 | +>>> print(inv) |
| 158 | +<Inventory (fname_zlib): sphobjinv v2.3, 220 objects> |
| 159 | +>>> inv.project |
| 160 | +'sphobjinv' |
| 161 | +>>> inv.version |
| 162 | +'2.3' |
| 163 | +>>> inv.objects[0] |
| 164 | +DataObjStr(name='sphobjinv.cli.convert', domain='py', role='module', priority='0', uri='cli/implementation/convert.html#module-$', dispname='-') |
| 165 | + |
| 166 | +``` |
| 167 | + |
| 168 | +The API also enables straightforward re-export of an inventory, for subsequent |
| 169 | +use with `intersphinx` cross-references. See [the docs][soi docs inv export] for |
| 170 | +more details. |
| 171 | + |
| 172 | +---- |
| 173 | + |
| 174 | +Full documentation is hosted at [Read The Docs][readthedocs link target]. |
| 175 | + |
| 176 | +Available on [PyPI][pypi link target] (`pip install sphobjinv`). |
| 177 | + |
| 178 | +Source on [GitHub][github repo]. Bug reports and feature requests are welcomed |
| 179 | +at the [Issues][github issue tracker] page there. |
| 180 | + |
| 181 | +Copyright (c) Brian Skinn 2016-2024 |
| 182 | + |
| 183 | +The `sphobjinv` documentation (including docstrings and README) is licensed |
| 184 | +under a [Creative Commons Attribution 4.0 International License][cc-by 4.0] |
| 185 | +(CC-BY). The `sphobjinv` codebase is released under the [MIT License]. See |
| 186 | +[`LICENSE.txt`][license link target] for full license terms. |
| 187 | + |
| 188 | + |
| 189 | +[black badge]: https://img.shields.io/badge/code%20style-black-000000.svg |
| 190 | +[black link target]: https://github.com/psf/black |
| 191 | +[cc-by 4.0]: http://creativecommons.org/licenses/by/4.0/ |
| 192 | +[codecov badge]: https://codecov.io/gh/bskinn/sphobjinv/branch/main/graph/badge.svg |
| 193 | +[codecov target]: https://codecov.io/gh/bskinn/sphobjinv |
| 194 | +[soi docs inv export]: http://sphobjinv.readthedocs.io/en/latest/api_usage.html#exporting-an-inventory |
| 195 | +[github issue tracker]: https://github.com/bskinn/sphobjinv/issues |
| 196 | +[github repo]: https://github.com/bskinn/sphobjinv |
| 197 | +[gitter badge]: https://badges.gitter.im/sphobjinv/community.svg |
| 198 | +[gitter link target]: https://gitter.im/sphobjinv/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge |
| 199 | +[license badge]: https://img.shields.io/github/license/mashape/apistatus.svg |
| 200 | +[license link target]: https://github.com/bskinn/sphobjinv/blob/stable/LICENSE.txt |
| 201 | +[mit license]: https://opensource.org/licenses/MIT |
| 202 | +[numpy linspace]: https://numpy.org/doc/1.26/reference/generated/numpy.linspace.html |
| 203 | +[pepy badge]: https://pepy.tech/badge/sphobjinv/month |
| 204 | +[pepy link target]: https://pepy.tech/project/sphobjinv?versions=2.0.1&versions=2.1&versions=2.2.2&versions=2.3&versions=2.3.1 |
| 205 | +[pypi badge]: https://img.shields.io/pypi/v/sphobjinv.svg?logo=pypi] |
| 206 | +[pypi link target]: https://pypi.org/project/sphobjinv |
| 207 | +[python versions badge]: https://img.shields.io/pypi/pyversions/sphobjinv.svg?logo=python |
| 208 | +[readthedocs badge]: https://img.shields.io/readthedocs/sphobjinv/latest.svg |
| 209 | +[readthedocs link target]: http://sphobjinv.readthedocs.io/en/latest/ |
| 210 | +[workflow badge]: https://img.shields.io/github/actions/workflow/status/bskinn/sphobjinv/ci_tests.yml?logo=github&branch=main |
| 211 | +[workflow link target]: https://github.com/bskinn/sphobjinv/actions |
0 commit comments