From 9464798068d43f90acc1238d97ccff2af4deb105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Thu, 27 May 2021 16:04:12 -0700 Subject: [PATCH] doc: external_content: fix for Unix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Path.rename() uses os.rename() internally. Per the Python docs: The operation may fail on some Unix flavors if src and dst are on different filesystems. Since 'src_adjusted' is in a temporary directory, on my flavor of Unix, that's in /tmp, which is indeed on a different filesystem than 'dst', a destination in the doc build directory on my root filesystem. This is causing the following error when I build the docs: Handler for event 'builder-inited' threw an exception (exception: [Errno 18] Invalid cross-device link: '/tmp/tmpfscfo20o/index.rst' -> '/home/mbolivar/zp/zephyr/doc/_build/src/reference/drivers/index.rst') Fix this by using shutil.move() instead of Path.rename(). The shutil function handles cross-filesystem moves correctly. It did not take a path-like object for both its src and dst arguments until Python 3.9, though, so we need to convert to strings for portability on earlier but still supported versions. Signed-off-by: Martí Bolívar --- doc/_extensions/zephyr/external_content.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/_extensions/zephyr/external_content.py b/doc/_extensions/zephyr/external_content.py index e5e99c31f7a..8f4acfd3d70 100644 --- a/doc/_extensions/zephyr/external_content.py +++ b/doc/_extensions/zephyr/external_content.py @@ -154,7 +154,7 @@ def sync_contents(app: Sphinx) -> None: if not filecmp.cmp(src_adjusted, dst): dst.unlink() - src_adjusted.rename(dst) + shutil.move(os.fspath(src_adjusted), os.fspath(dst)) # remove any previously copied file not present in the origin folder, # excepting those marked to be kept.