Fix #7324: Emit a warning if multiple files for same document found

This commit is contained in:
Takeshi KOMIYA 2020-03-18 22:45:50 +09:00
parent 6f60864d03
commit 2360473012
2 changed files with 10 additions and 1 deletions

View File

@ -114,6 +114,8 @@ Features added
* Added ``SphinxDirective.get_source_info()``
and ``SphinxRole.get_source_info()``.
* #7324: sphinx-build: Emit a warning if multiple files having different file
extensions for same document found
Bugs fixed
----------

View File

@ -9,6 +9,7 @@
"""
import os
from glob import glob
from sphinx.locale import __
from sphinx.util import get_matching_files
@ -55,7 +56,13 @@ class Project:
for filename in get_matching_files(self.srcdir, excludes): # type: ignore
docname = self.path2doc(filename)
if docname:
if os.access(os.path.join(self.srcdir, filename), os.R_OK):
if docname in self.docnames:
pattern = os.path.join(self.srcdir, docname) + '.*'
files = [relpath(f, self.srcdir) for f in glob(pattern)]
logger.warning(__('multiple files found for the document "%s": %r\n'
'Use %r for the build.'),
docname, files, self.doc2path(docname), once=True)
elif os.access(os.path.join(self.srcdir, filename), os.R_OK):
self.docnames.add(docname)
else:
logger.warning(__("document not readable. Ignored."), location=docname)