Skip to content

Commit

Permalink
Handle the case where source drive and cwd drive differ (#17125)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SaschaCowley committed Sep 6, 2024
1 parent 21fbfa7 commit 7e526e8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion user_docs/markdownTranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e526e8

Please sign in to comment.