intersphinx-registry 0.2511.7__tar.gz → 0.2601.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: intersphinx_registry
3
+ Version: 0.2601.5
4
+ Summary: This package provides convenient utilities and data to write a sphinx config file.
5
+ Author-email: M Bussonnier <bussonniermatthias@gmail.com>
6
+ Description-Content-Type: text/markdown
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ License-File: LICENSE
9
+ Requires-Dist: intersphinx_registry[lookup] ; extra == "cli"
10
+ Requires-Dist: sphinx>=8 ; extra == "lookup"
11
+ Requires-Dist: requests ; extra == "lookup"
12
+ Requires-Dist: requests-cache ; extra == "lookup"
13
+ Requires-Dist: platformdirs ; extra == "lookup"
14
+ Requires-Dist: pytest>=7.0 ; extra == "tests"
15
+ Requires-Dist: pytest-xdist ; extra == "tests"
16
+ Requires-Dist: mypy ; extra == "tests"
17
+ Requires-Dist: types-requests ; extra == "tests"
18
+ Requires-Dist: intersphinx_registry[cli] ; extra == "tests"
19
+ Project-URL: Home, https://github.com/Quansight-labs/intersphinx_registry
20
+ Provides-Extra: cli
21
+ Provides-Extra: lookup
22
+ Provides-Extra: tests
23
+
24
+ # Intersphinx Registry
25
+
26
+ A simple utility package that provides a default intersphinx mapping for a large chunk of the Python ecosystem.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ # Core package only (for use in conf.py/Sphinx projects)
32
+ pip install intersphinx_registry
33
+
34
+ # With a command-line interface
35
+ pip install intersphinx_registry[cli]
36
+ # or
37
+ uv tool install intersphinx_registry[cli]
38
+ # or
39
+ pipx install intersphinx_registry[cli]
40
+ ```
41
+
42
+ You can also use it without installation:
43
+
44
+ ```bash
45
+ uvx intersphinx-registry[cli] lookup numpy,scipy array
46
+ ```
47
+
48
+ ## Usage in `conf.py`
49
+
50
+ ```python
51
+ from intersphinx_registry import get_intersphinx_mapping
52
+
53
+ # ...
54
+ intersphinx_mapping = get_intersphinx_mapping(
55
+ packages={"ipython", "matplotlib", "pandas", "python"}
56
+ )
57
+ intersphinx_mapping.update({
58
+ 'overwrite': ('<url>', None),
59
+ 'my-package': ('<url>', None),
60
+ })
61
+ ```
62
+
63
+ ## Command-line interface
64
+
65
+ The package provides a command-line interface for looking up intersphinx targets.
66
+
67
+ > [!NOTE]
68
+ > The CLI requires installing the `[cli]` extra: `pip install intersphinx_registry[cli]`
69
+
70
+ ```bash
71
+ $ intersphinx-registry --version
72
+ # or
73
+ $ intersphinx-registry -v
74
+ ```
75
+
76
+ ### quick lookup
77
+
78
+ You can use the lookup command to search for intersphinx targets and webpages across various packages.
79
+
80
+ Call without arguments to get help:
81
+
82
+ ```bash
83
+ $ intersphinx-registry lookup
84
+ ```
85
+
86
+ Basic usage:
87
+
88
+ ```bash
89
+ $ intersphinx-registry lookup <package>[,package] [search_term]
90
+ ```
91
+
92
+ Examples:
93
+
94
+ ```bash
95
+ $ intersphinx-registry lookup numpy,scipy array
96
+ $ intersphinx-registry lookup ipython formatters.html
97
+ ```
98
+
99
+ You can search multiple packages at once:
100
+
101
+ ```bash
102
+ $ intersphinx-registry lookup numpy,scipy Universal
103
+ std:label ufuncs NumPy 2.1 'Universal functions (ufunc)' https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs
104
+ std:label ufuncs-basics NumPy 2.1 'Universal functions (ufunc) basics' https://numpy.org/doc/stable/user/basics.ufuncs.html#ufuncs-basics
105
+ std:label ufuncs-internals NumPy 2.1 'Universal functions' https://numpy.org/doc/stable/dev/internals.code-explanations.html#ufuncs-internals
106
+ std:doc reference/ufuncs NumPy 2.1 'Universal functions (ufunc)' https://numpy.org/doc/stable/reference/ufuncs.html
107
+ std:doc user/basics.ufuncs NumPy 2.1 'Universal functions (ufunc) basics' https://numpy.org/doc/stable/user/basics.ufuncs.html
108
+ std:label non-uniform-random-number-sampling SciPy 1.14.1 'Universal Non-Uniform Random Number Sampling in SciPy' https://docs.scipy.org/doc/scipy/tutorial/stats/sampling.html#non-uniform-random-number-sampling
109
+ std:doc tutorial/stats/sampling SciPy 1.14.1 'Universal Non-Uniform Random Number Sampling in SciPy' https://docs.scipy.org/doc/scipy/tutorial/stats/sampling.html
110
+ ```
111
+
112
+ > [!WARNING]
113
+ > There is no cache; the lookup command downloads the inventory of each mentioned package every time.
114
+
115
+ You can also use the lookup functionality via the module interface:
116
+
117
+ ```bash
118
+ $ python -m intersphinx_registry.lookup <package>[,package] [search_term]
119
+ ```
120
+
121
+ ### reverse-lookup
122
+
123
+ Find which package a documentation URL belongs to and get its Sphinx reference.
124
+
125
+ ```bash
126
+ $ intersphinx-registry reverse-lookup <url> [url...]
127
+ ```
128
+
129
+ Examples:
130
+
131
+ ```bash
132
+ $ intersphinx-registry reverse-lookup https://numpy.org/doc/stable/reference/arrays.html
133
+ $ intersphinx-registry reverse-lookup https://docs.python.org/3/ https://numpy.org/doc/stable/
134
+ ```
135
+
136
+ This is useful when you have a link to documentation and want to know the corresponding Sphinx reference (`:domain:package:target`) that you can use in your own documentation with intersphinx.
137
+
138
+ ### rev-search
139
+
140
+ Scan `.rst` files in a directory for hardcoded URLs and suggest replacements with Sphinx references.
141
+
142
+ ```bash
143
+ $ intersphinx-registry rev-search <directory-or-file>
144
+ ```
145
+
146
+ Examples:
147
+
148
+ ```bash
149
+ $ intersphinx-registry rev-search docs/
150
+ $ intersphinx-registry rev-search docs/index.rst
151
+ ```
152
+
153
+ This command helps you convert hardcoded URLs in your reStructuredText documentation into proper intersphinx references. It scans your documentation files, finds URLs that match known packages in the registry, and shows you a diff-style output of the suggested changes.
154
+
155
+ ## Why ?
156
+
157
+ Sometimes, packages docs move and it's hard to keep track of them. We _try_ to keep the
158
+ registry up to date, so you do not have to ask yourself questions and update your
159
+ intersphinx-mapping.
160
+
161
+ You also might not want to think about adding intersphinx mapping when you refer
162
+ to dependencies.
163
+
164
+ ## A package url is wrong !
165
+
166
+ Please send a PR updating only this package in the `registry.json`. We try to
167
+ link only to _stable_ package, not dev versions.
168
+
169
+ ## A package is missing !
170
+
171
+ We can't do all packages, but if you think a package is widely used and missing,
172
+ please send a PR.
173
+
@@ -0,0 +1,149 @@
1
+ # Intersphinx Registry
2
+
3
+ A simple utility package that provides a default intersphinx mapping for a large chunk of the Python ecosystem.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Core package only (for use in conf.py/Sphinx projects)
9
+ pip install intersphinx_registry
10
+
11
+ # With a command-line interface
12
+ pip install intersphinx_registry[cli]
13
+ # or
14
+ uv tool install intersphinx_registry[cli]
15
+ # or
16
+ pipx install intersphinx_registry[cli]
17
+ ```
18
+
19
+ You can also use it without installation:
20
+
21
+ ```bash
22
+ uvx intersphinx-registry[cli] lookup numpy,scipy array
23
+ ```
24
+
25
+ ## Usage in `conf.py`
26
+
27
+ ```python
28
+ from intersphinx_registry import get_intersphinx_mapping
29
+
30
+ # ...
31
+ intersphinx_mapping = get_intersphinx_mapping(
32
+ packages={"ipython", "matplotlib", "pandas", "python"}
33
+ )
34
+ intersphinx_mapping.update({
35
+ 'overwrite': ('<url>', None),
36
+ 'my-package': ('<url>', None),
37
+ })
38
+ ```
39
+
40
+ ## Command-line interface
41
+
42
+ The package provides a command-line interface for looking up intersphinx targets.
43
+
44
+ > [!NOTE]
45
+ > The CLI requires installing the `[cli]` extra: `pip install intersphinx_registry[cli]`
46
+
47
+ ```bash
48
+ $ intersphinx-registry --version
49
+ # or
50
+ $ intersphinx-registry -v
51
+ ```
52
+
53
+ ### quick lookup
54
+
55
+ You can use the lookup command to search for intersphinx targets and webpages across various packages.
56
+
57
+ Call without arguments to get help:
58
+
59
+ ```bash
60
+ $ intersphinx-registry lookup
61
+ ```
62
+
63
+ Basic usage:
64
+
65
+ ```bash
66
+ $ intersphinx-registry lookup <package>[,package] [search_term]
67
+ ```
68
+
69
+ Examples:
70
+
71
+ ```bash
72
+ $ intersphinx-registry lookup numpy,scipy array
73
+ $ intersphinx-registry lookup ipython formatters.html
74
+ ```
75
+
76
+ You can search multiple packages at once:
77
+
78
+ ```bash
79
+ $ intersphinx-registry lookup numpy,scipy Universal
80
+ std:label ufuncs NumPy 2.1 'Universal functions (ufunc)' https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs
81
+ std:label ufuncs-basics NumPy 2.1 'Universal functions (ufunc) basics' https://numpy.org/doc/stable/user/basics.ufuncs.html#ufuncs-basics
82
+ std:label ufuncs-internals NumPy 2.1 'Universal functions' https://numpy.org/doc/stable/dev/internals.code-explanations.html#ufuncs-internals
83
+ std:doc reference/ufuncs NumPy 2.1 'Universal functions (ufunc)' https://numpy.org/doc/stable/reference/ufuncs.html
84
+ std:doc user/basics.ufuncs NumPy 2.1 'Universal functions (ufunc) basics' https://numpy.org/doc/stable/user/basics.ufuncs.html
85
+ std:label non-uniform-random-number-sampling SciPy 1.14.1 'Universal Non-Uniform Random Number Sampling in SciPy' https://docs.scipy.org/doc/scipy/tutorial/stats/sampling.html#non-uniform-random-number-sampling
86
+ std:doc tutorial/stats/sampling SciPy 1.14.1 'Universal Non-Uniform Random Number Sampling in SciPy' https://docs.scipy.org/doc/scipy/tutorial/stats/sampling.html
87
+ ```
88
+
89
+ > [!WARNING]
90
+ > There is no cache; the lookup command downloads the inventory of each mentioned package every time.
91
+
92
+ You can also use the lookup functionality via the module interface:
93
+
94
+ ```bash
95
+ $ python -m intersphinx_registry.lookup <package>[,package] [search_term]
96
+ ```
97
+
98
+ ### reverse-lookup
99
+
100
+ Find which package a documentation URL belongs to and get its Sphinx reference.
101
+
102
+ ```bash
103
+ $ intersphinx-registry reverse-lookup <url> [url...]
104
+ ```
105
+
106
+ Examples:
107
+
108
+ ```bash
109
+ $ intersphinx-registry reverse-lookup https://numpy.org/doc/stable/reference/arrays.html
110
+ $ intersphinx-registry reverse-lookup https://docs.python.org/3/ https://numpy.org/doc/stable/
111
+ ```
112
+
113
+ This is useful when you have a link to documentation and want to know the corresponding Sphinx reference (`:domain:package:target`) that you can use in your own documentation with intersphinx.
114
+
115
+ ### rev-search
116
+
117
+ Scan `.rst` files in a directory for hardcoded URLs and suggest replacements with Sphinx references.
118
+
119
+ ```bash
120
+ $ intersphinx-registry rev-search <directory-or-file>
121
+ ```
122
+
123
+ Examples:
124
+
125
+ ```bash
126
+ $ intersphinx-registry rev-search docs/
127
+ $ intersphinx-registry rev-search docs/index.rst
128
+ ```
129
+
130
+ This command helps you convert hardcoded URLs in your reStructuredText documentation into proper intersphinx references. It scans your documentation files, finds URLs that match known packages in the registry, and shows you a diff-style output of the suggested changes.
131
+
132
+ ## Why ?
133
+
134
+ Sometimes, packages docs move and it's hard to keep track of them. We _try_ to keep the
135
+ registry up to date, so you do not have to ask yourself questions and update your
136
+ intersphinx-mapping.
137
+
138
+ You also might not want to think about adding intersphinx mapping when you refer
139
+ to dependencies.
140
+
141
+ ## A package url is wrong !
142
+
143
+ Please send a PR updating only this package in the `registry.json`. We try to
144
+ link only to _stable_ package, not dev versions.
145
+
146
+ ## A package is missing !
147
+
148
+ We can't do all packages, but if you think a package is widely used and missing,
149
+ please send a PR.
@@ -0,0 +1,79 @@
1
+ """
2
+ This package provides convenient utilities and data to write a sphinx config file.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import json
8
+ import warnings
9
+ from pathlib import Path
10
+ from typing import Optional, Tuple, cast
11
+
12
+ # See issue 4, we this the best format is Major.YYMM.day,
13
+ # in case of multiple releases a day we can borrow the next day's date.
14
+ # no 0 in front of the day as it is not pep440 compliant.
15
+ version_info = (0, 2601, 5)
16
+ __version__ = ".".join(map(str, version_info))
17
+
18
+ registry_file = Path(__file__).parent / "registry.json"
19
+
20
+ # Mapping of removed aliases to their canonical package names
21
+ _ALIASES = {
22
+ "rtd": "readthedocs",
23
+ "server": "jupyter-server",
24
+ }
25
+
26
+
27
+ def _get_all_mappings() -> dict[str, tuple[str, str | None]]:
28
+ return cast(
29
+ dict[str, Tuple[str, Optional[str]]],
30
+ {k: tuple(v) for (k, v) in json.loads(registry_file.read_bytes()).items()},
31
+ )
32
+
33
+
34
+ def get_intersphinx_mapping(
35
+ *, packages: set[str] = set()
36
+ ) -> dict[str, tuple[str, str | None]]:
37
+ """
38
+ Return values of intersphinx_mapping for sphinx configuration.
39
+
40
+ For convenience, the returned dictionary is a copy so should be ok to
41
+ mutate.
42
+
43
+ Parameters
44
+ ----------
45
+ packages: Set of Str
46
+ Libraries to include.
47
+
48
+ Sphinx will download and load all the `objects.inv` for listed
49
+ packages. Getting all mappings is discourage as it will download all
50
+ the `object.inv` which can be a non-negligible amount of data.
51
+
52
+ """
53
+ if len(packages) == 0:
54
+ raise ValueError(
55
+ 'You must explicitly give a list of packages for which to download intersphinx inventories: get_intersphinx_mapping(packages=["IPython", "numpy",...]).'
56
+ )
57
+
58
+ mapping = _get_all_mappings()
59
+
60
+ # Check for aliases and replace them with canonical names
61
+ resolved_packages = set()
62
+ for pkg in packages:
63
+ if pkg in _ALIASES:
64
+ canonical = _ALIASES[pkg]
65
+ warnings.warn(
66
+ f"Package alias '{pkg}' is deprecated. Use '{canonical}' instead.",
67
+ DeprecationWarning,
68
+ stacklevel=2,
69
+ )
70
+ resolved_packages.add(canonical)
71
+ else:
72
+ resolved_packages.add(pkg)
73
+
74
+ missing = resolved_packages - set(mapping)
75
+ if missing:
76
+ raise ValueError(
77
+ f"Some libraries in 'packages' not found in registry: {repr(sorted(missing))}"
78
+ )
79
+ return {k: v for k, v in mapping.items() if k in resolved_packages}
@@ -0,0 +1,4 @@
1
+ from intersphinx_registry.cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -1,8 +1,8 @@
1
1
  """
2
2
  Experimental, print info about all (or a subset of), all the known inventories.
3
3
 
4
- As this is likely to make _many_ concurrent connections;
5
- we use aoihttp and sphobjinv which are not listed as dependencies.
4
+ As this is likely to make _many_ concurrent connections;
5
+ we use aiohttp and sphobjinv which are not listed as dependencies.
6
6
  """
7
7
 
8
8
  import asyncio
@@ -66,7 +66,7 @@ for key, base_url, data in results:
66
66
  flattened.append((key, base_url, inv.project, inv.version, inv.count))
67
67
 
68
68
  if not flattened:
69
- sys.exit("Could not reach any pacakges")
69
+ sys.exit("Could not reach any packages")
70
70
  width = [len(x) for x in flattened[0][:-1]]
71
71
 
72
72
  for item in flattened:
@@ -76,5 +76,5 @@ for item in flattened:
76
76
  for key, url, proj, version, count in flattened:
77
77
  w_key, w_url, w_proj, w_version = width
78
78
  print(
79
- f"{key:<{w_key}} {proj!r:<{w_proj+2}} {version:<{w_version}} {count:<5} {url:<{w_url}}"
79
+ f"{key:<{w_key}} {proj!r:<{w_proj + 2}} {version:<{w_version}} {count:<5} {url:<{w_url}}"
80
80
  )
@@ -0,0 +1,128 @@
1
+ import argparse
2
+ import sys
3
+
4
+ from intersphinx_registry import __version__
5
+ from intersphinx_registry.lookup import clear_cache, lookup_packages, print_info
6
+ from intersphinx_registry.reverse_lookup import reverse_lookup
7
+ from intersphinx_registry.rev_search import rev_search
8
+ from intersphinx_registry.utils import _are_dependencies_available
9
+
10
+
11
+ def lookup_command(args):
12
+ if not _are_dependencies_available():
13
+ sys.exit(1)
14
+
15
+ if not args.packages:
16
+ print("Usage: intersphinx-registry lookup <package>[,package] [search_term]\n")
17
+ print("Examples:")
18
+ print(" intersphinx-registry lookup numpy,scipy array")
19
+ print(" intersphinx-registry lookup ipython formatters.html")
20
+ sys.exit(0)
21
+
22
+ lookup_packages(args.packages, args.search_term)
23
+
24
+
25
+ def main():
26
+ parser = argparse.ArgumentParser(
27
+ prog="intersphinx-registry",
28
+ description="Default intersphinx mapping for the Python ecosystem",
29
+ epilog="For more information, see: https://github.com/Quansight-labs/intersphinx_registry",
30
+ )
31
+
32
+ parser.add_argument(
33
+ "-v",
34
+ "--version",
35
+ action="version",
36
+ version=f"intersphinx-registry {__version__}",
37
+ )
38
+
39
+ subparsers = parser.add_subparsers(
40
+ title="subcommands",
41
+ description="available subcommands",
42
+ dest="subcommand",
43
+ help="subcommand help",
44
+ )
45
+
46
+ # Lookup subcommand
47
+ lookup_parser = subparsers.add_parser(
48
+ "lookup",
49
+ help="Search and lookup intersphinx targets/webpages",
50
+ description="Search intersphinx inventories for documentation targets",
51
+ )
52
+ lookup_parser.add_argument(
53
+ "packages",
54
+ nargs="?",
55
+ default=None,
56
+ help="Comma-separated list of package names (e.g., numpy,scipy)",
57
+ )
58
+ lookup_parser.add_argument(
59
+ "search_term",
60
+ nargs="?",
61
+ default=None,
62
+ help="Optional search term to filter results",
63
+ )
64
+ lookup_parser.set_defaults(func=lookup_command)
65
+
66
+ reverse_lookup_parser = subparsers.add_parser(
67
+ "reverse-lookup",
68
+ help="Find which packages documentation URLs belong to",
69
+ description="Given URLs, find which packages they come from",
70
+ epilog="Examples:\n"
71
+ " intersphinx-registry reverse-lookup https://numpy.org/doc/stable/reference/arrays.html\n"
72
+ " intersphinx-registry reverse-lookup https://docs.python.org/3/ https://numpy.org/doc/stable/",
73
+ formatter_class=argparse.RawDescriptionHelpFormatter,
74
+ )
75
+ reverse_lookup_parser.add_argument(
76
+ "urls",
77
+ nargs="*",
78
+ help="URLs to look up (space-separated)",
79
+ )
80
+
81
+ def _reverse_lookup_wrapper(args):
82
+ if not args.urls:
83
+ reverse_lookup_parser.print_help()
84
+ sys.exit(0)
85
+ reverse_lookup(args.urls)
86
+
87
+ reverse_lookup_parser.set_defaults(func=_reverse_lookup_wrapper)
88
+
89
+ rev_search_parser = subparsers.add_parser(
90
+ "rev-search",
91
+ help="Search .rst files for URLs that can be replaced with Sphinx references",
92
+ description="Scan directory for .rst files and find URLs that can be replaced",
93
+ epilog="Examples:\n"
94
+ " intersphinx-registry rev-search docs/\n"
95
+ " intersphinx-registry rev-search .",
96
+ formatter_class=argparse.RawDescriptionHelpFormatter,
97
+ )
98
+ rev_search_parser.add_argument(
99
+ "directory",
100
+ help="Directory to search for .rst files",
101
+ )
102
+ rev_search_parser.set_defaults(func=lambda args: rev_search(args.directory))
103
+
104
+ clear_cache_parser = subparsers.add_parser(
105
+ "clear-cache",
106
+ help="Clear the intersphinx inventory cache",
107
+ description="Clear the cached intersphinx inventory files",
108
+ )
109
+ clear_cache_parser.set_defaults(func=lambda args: clear_cache())
110
+
111
+ info_parser = subparsers.add_parser(
112
+ "info",
113
+ help="Display information about the intersphinx-registry installation",
114
+ description="Show version, cache location, registry file location, and package count",
115
+ )
116
+ info_parser.set_defaults(func=lambda args: print_info())
117
+
118
+ args = parser.parse_args()
119
+
120
+ if args.subcommand is None:
121
+ parser.print_help()
122
+ sys.exit(0)
123
+
124
+ args.func(args)
125
+
126
+
127
+ if __name__ == "__main__":
128
+ main()