mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Split `sphinx.ext.intersphinx._cli
`
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
parent
3a1f2f377c
commit
b9a3f7e3df
@ -395,7 +395,7 @@ select = [
|
|||||||
"sphinx/environment/adapters/toctree.py" = ["B026"]
|
"sphinx/environment/adapters/toctree.py" = ["B026"]
|
||||||
|
|
||||||
# whitelist ``print`` for stdout messages
|
# whitelist ``print`` for stdout messages
|
||||||
"sphinx/ext/intersphinx/__init__.py" = ["T201"]
|
"sphinx/ext/intersphinx/_cli.py" = ["T201"]
|
||||||
|
|
||||||
# whitelist ``print`` for stdout messages
|
# whitelist ``print`` for stdout messages
|
||||||
"sphinx/testing/fixtures.py" = ["T201"]
|
"sphinx/testing/fixtures.py" = ["T201"]
|
||||||
@ -504,6 +504,7 @@ exclude = [
|
|||||||
"sphinx/ext/doctest.py",
|
"sphinx/ext/doctest.py",
|
||||||
"sphinx/ext/autosectionlabel.py",
|
"sphinx/ext/autosectionlabel.py",
|
||||||
"sphinx/ext/intersphinx/__init__.py",
|
"sphinx/ext/intersphinx/__init__.py",
|
||||||
|
"sphinx/ext/intersphinx/_cli.py",
|
||||||
"sphinx/ext/duration.py",
|
"sphinx/ext/duration.py",
|
||||||
"sphinx/ext/imgconverter.py",
|
"sphinx/ext/imgconverter.py",
|
||||||
"sphinx/ext/imgmath.py",
|
"sphinx/ext/imgmath.py",
|
||||||
|
@ -40,7 +40,6 @@ import concurrent.futures
|
|||||||
import functools
|
import functools
|
||||||
import posixpath
|
import posixpath
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
from os import path
|
from os import path
|
||||||
from typing import TYPE_CHECKING, cast
|
from typing import TYPE_CHECKING, cast
|
||||||
@ -54,6 +53,7 @@ from sphinx.addnodes import pending_xref
|
|||||||
from sphinx.builders.html import INVENTORY_FILENAME
|
from sphinx.builders.html import INVENTORY_FILENAME
|
||||||
from sphinx.deprecation import _deprecation_warning
|
from sphinx.deprecation import _deprecation_warning
|
||||||
from sphinx.errors import ExtensionError
|
from sphinx.errors import ExtensionError
|
||||||
|
from sphinx.ext.intersphinx._cli import inspect_main
|
||||||
from sphinx.ext.intersphinx._shared import LOGGER as logger
|
from sphinx.ext.intersphinx._shared import LOGGER as logger
|
||||||
from sphinx.ext.intersphinx._shared import InventoryAdapter
|
from sphinx.ext.intersphinx._shared import InventoryAdapter
|
||||||
from sphinx.locale import _, __
|
from sphinx.locale import _, __
|
||||||
@ -792,40 +792,3 @@ def setup(app: Sphinx) -> ExtensionMetadata:
|
|||||||
'env_version': 1,
|
'env_version': 1,
|
||||||
'parallel_read_safe': True,
|
'parallel_read_safe': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def inspect_main(argv: list[str], /) -> int:
|
|
||||||
"""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)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
class MockConfig:
|
|
||||||
intersphinx_timeout: int | None = None
|
|
||||||
tls_verify = False
|
|
||||||
tls_cacerts: str | dict[str, str] | None = None
|
|
||||||
user_agent: str = ''
|
|
||||||
|
|
||||||
class MockApp:
|
|
||||||
srcdir = ''
|
|
||||||
config = MockConfig()
|
|
||||||
|
|
||||||
try:
|
|
||||||
filename = argv[0]
|
|
||||||
inv_data = fetch_inventory(MockApp(), '', filename) # type: ignore[arg-type]
|
|
||||||
for key in sorted(inv_data or {}):
|
|
||||||
print(key)
|
|
||||||
inv_entries = sorted(inv_data[key].items())
|
|
||||||
for entry, (_proj, _ver, url_path, display_name) in inv_entries:
|
|
||||||
display_name = display_name * (display_name != '-')
|
|
||||||
print(f' {entry:<40} {display_name:<40}: {url_path}')
|
|
||||||
except ValueError as exc:
|
|
||||||
print(exc.args[0] % exc.args[1:], file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
except Exception as exc:
|
|
||||||
print(f'Unknown error: {exc!r}', file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
44
sphinx/ext/intersphinx/_cli.py
Normal file
44
sphinx/ext/intersphinx/_cli.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
"""This module provides contains the code for intersphinx command-line utilities."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from sphinx.ext.intersphinx import fetch_inventory
|
||||||
|
|
||||||
|
|
||||||
|
def inspect_main(argv: list[str], /) -> int:
|
||||||
|
"""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)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
class MockConfig:
|
||||||
|
intersphinx_timeout: int | None = None
|
||||||
|
tls_verify = False
|
||||||
|
tls_cacerts: str | dict[str, str] | None = None
|
||||||
|
user_agent: str = ''
|
||||||
|
|
||||||
|
class MockApp:
|
||||||
|
srcdir = ''
|
||||||
|
config = MockConfig()
|
||||||
|
|
||||||
|
try:
|
||||||
|
filename = argv[0]
|
||||||
|
inv_data = fetch_inventory(MockApp(), '', filename) # type: ignore[arg-type]
|
||||||
|
for key in sorted(inv_data or {}):
|
||||||
|
print(key)
|
||||||
|
inv_entries = sorted(inv_data[key].items())
|
||||||
|
for entry, (_proj, _ver, url_path, display_name) in inv_entries:
|
||||||
|
display_name = display_name * (display_name != '-')
|
||||||
|
print(f' {entry:<40} {display_name:<40}: {url_path}')
|
||||||
|
except ValueError as exc:
|
||||||
|
print(exc.args[0] % exc.args[1:], file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
except Exception as exc:
|
||||||
|
print(f'Unknown error: {exc!r}', file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
Loading…
Reference in New Issue
Block a user