From 1190a8e1368270e05110139e3cd6fab1f160f866 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 9 Jan 2022 03:23:01 +0900 Subject: [PATCH] Fix #10057: Failed to scan documents on the root directory get_matching_files() incorrectly drops the first character of each path on scanning documents. It will help users to exclude paths via exclude_patterns setting. Note: Users need to configure `exclude_patterns` to put their document on the root directory. This does not help to avoid recursive symlinks (ex. /proc, /sys) --- CHANGES | 2 ++ sphinx/util/__init__.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 6ce3e51f3d0..256bb4d6ec1 100644 --- a/CHANGES +++ b/CHANGES @@ -67,6 +67,8 @@ Bugs fixed at info-field-list * #9390: texinfo: Do not emit labels inside footnotes * #9979: Error level messages were displayed as warning messages +* #10057: Failed to scan documents if the project is placed onto the root + directory Testing -------- diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 8a3b52fbfca..c773ea05422 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -72,10 +72,9 @@ def get_matching_files(dirname: str, """ # dirname is a normalized absolute path. dirname = path.normpath(path.abspath(dirname)) - dirlen = len(dirname) + 1 # exclude final os.path.sep for root, dirs, files in os.walk(dirname, followlinks=True): - relativeroot = root[dirlen:] + relativeroot = path.relpath(root, dirname) qdirs = enumerate(path_stabilize(path.join(relativeroot, dn)) for dn in dirs) # type: Iterable[Tuple[int, str]]