mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7927 from jnothman/name-case-clash
Add autosummary_filename_map config to avoid clashes
This commit is contained in:
commit
da174138af
@ -195,6 +195,15 @@ also use these config values:
|
||||
|
||||
.. versionadded:: 2.1
|
||||
|
||||
.. confval:: autosummary_filename_map
|
||||
|
||||
A dict mapping object names to filenames. This is necessary to avoid
|
||||
filename conflicts where multiple objects have names that are
|
||||
indistinguishable when case is ignored, on file systems where filenames
|
||||
are case-insensitive.
|
||||
|
||||
.. versionadded:: 3.2
|
||||
|
||||
|
||||
Customizing templates
|
||||
---------------------
|
||||
|
@ -252,7 +252,9 @@ class Autosummary(SphinxDirective):
|
||||
tree_prefix = self.options['toctree'].strip()
|
||||
docnames = []
|
||||
excluded = Matcher(self.config.exclude_patterns)
|
||||
filename_map = self.config.autosummary_filename_map
|
||||
for name, sig, summary, real_name in items:
|
||||
real_name = filename_map.get(real_name, real_name)
|
||||
docname = posixpath.join(tree_prefix, real_name)
|
||||
docname = posixpath.normpath(posixpath.join(dirname, docname))
|
||||
if docname not in self.env.found_docs:
|
||||
@ -785,6 +787,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
||||
app.add_role('autolink', AutoLink())
|
||||
app.connect('builder-inited', process_generate_options)
|
||||
app.add_config_value('autosummary_context', {}, True)
|
||||
app.add_config_value('autosummary_filename_map', {}, 'html')
|
||||
app.add_config_value('autosummary_generate', [], True, [bool])
|
||||
app.add_config_value('autosummary_generate_overwrite', True, False)
|
||||
app.add_config_value('autosummary_mock_imports',
|
||||
|
@ -74,6 +74,7 @@ class DummyApplication:
|
||||
self.warningiserror = False
|
||||
|
||||
self.config.add('autosummary_context', {}, True, None)
|
||||
self.config.add('autosummary_filename_map', {}, True, None)
|
||||
self.config.init_values()
|
||||
|
||||
def emit_firstresult(self, *args: Any) -> None:
|
||||
@ -393,6 +394,11 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None,
|
||||
# keep track of new files
|
||||
new_files = []
|
||||
|
||||
if app:
|
||||
filename_map = app.config.autosummary_filename_map
|
||||
else:
|
||||
filename_map = {}
|
||||
|
||||
# write
|
||||
for entry in sorted(set(items), key=str):
|
||||
if entry.path is None:
|
||||
@ -418,7 +424,7 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None,
|
||||
imported_members, app, entry.recursive, context,
|
||||
modname, qualname)
|
||||
|
||||
filename = os.path.join(path, name + suffix)
|
||||
filename = os.path.join(path, filename_map.get(name, name) + suffix)
|
||||
if os.path.isfile(filename):
|
||||
with open(filename, encoding=encoding) as f:
|
||||
old_content = f.read()
|
||||
|
@ -0,0 +1,21 @@
|
||||
from os import path # NOQA
|
||||
from typing import Union
|
||||
|
||||
|
||||
class Foo:
|
||||
class Bar:
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def bar(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def baz(self):
|
||||
pass
|
||||
|
||||
|
||||
def bar(x: Union[int, str], y: int = 1) -> None:
|
||||
pass
|
11
tests/roots/test-ext-autosummary-filename-map/conf.py
Normal file
11
tests/roots/test-ext-autosummary-filename-map/conf.py
Normal file
@ -0,0 +1,11 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
extensions = ['sphinx.ext.autosummary']
|
||||
autosummary_generate = True
|
||||
autosummary_filename_map = {
|
||||
"autosummary_dummy_module": "module_mangled",
|
||||
"autosummary_dummy_module.bar": "bar"
|
||||
}
|
9
tests/roots/test-ext-autosummary-filename-map/index.rst
Normal file
9
tests/roots/test-ext-autosummary-filename-map/index.rst
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
.. autosummary::
|
||||
:toctree: generated
|
||||
:caption: An autosummary
|
||||
|
||||
autosummary_dummy_module
|
||||
autosummary_dummy_module.Foo
|
||||
autosummary_dummy_module.Foo.bar
|
||||
autosummary_dummy_module.bar
|
@ -394,6 +394,20 @@ def test_autosummary_recursive(app, status, warning):
|
||||
assert 'package.package.module' in content
|
||||
|
||||
|
||||
@pytest.mark.sphinx('dummy', testroot='ext-autosummary-filename-map')
|
||||
def test_autosummary_filename_map(app, status, warning):
|
||||
app.build()
|
||||
|
||||
assert (app.srcdir / 'generated' / 'module_mangled.rst').exists()
|
||||
assert not (app.srcdir / 'generated' / 'autosummary_dummy_module.rst').exists()
|
||||
assert (app.srcdir / 'generated' / 'bar.rst').exists()
|
||||
assert not (app.srcdir / 'generated' / 'autosummary_dummy_module.bar.rst').exists()
|
||||
assert (app.srcdir / 'generated' / 'autosummary_dummy_module.Foo.rst').exists()
|
||||
|
||||
html_warnings = app._warning.getvalue()
|
||||
assert html_warnings == ''
|
||||
|
||||
|
||||
@pytest.mark.sphinx('latex', **default_kw)
|
||||
def test_autosummary_latex_table_colspec(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
Loading…
Reference in New Issue
Block a user