From 7e526e81af1aae0ad0c4466e0cef5aed29be0b7c Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Fri, 6 Sep 2024 17:10:22 +1000 Subject: [PATCH] Handle the case where source drive and cwd drive differ (#17125) Summary of the issue: `markdownTranslate.prettyPathString` was using `os.path.relpath` without preventing or catching errors raised by that method. This was causing unit tests to fail for users whose development takes place on a separate drive to their Windows user account folder, as `ntpath.relpath` raises `ValueError` when the drives differ. Description of user facing changes None. Description of developer facing changes Unit tests now run properly when the NVDA repo and developer's user directory are on different drives. This may also fix translation for users with such set-ups, though I'm not sure if this was broken for them. Description of development approach Added a check to see if the drives of the given path and the CWD differ, and if so, return the given path unchanged. Otherwise, calculate and return the relative path. Testing strategy: Ran unittests to ensure they now pass. --- user_docs/markdownTranslate.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/user_docs/markdownTranslate.py b/user_docs/markdownTranslate.py index c70353a0e60..81239d736de 100644 --- a/user_docs/markdownTranslate.py +++ b/user_docs/markdownTranslate.py @@ -32,7 +32,10 @@ def prettyPathString(path: str) -> str: - return os.path.relpath(path, os.getcwd()) + cwd = os.getcwd() + if os.path.normcase(os.path.splitdrive(path)[0]) != os.path.normcase(os.path.splitdrive(cwd)[0]): + return path + return os.path.relpath(path, cwd) @contextlib.contextmanager