diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2022-10-01 13:46:29 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2022-10-03 17:17:38 +0530 |
commit | 707bc01d36ea08dc2a6b516e5f8b38c86ff4df28 (patch) | |
tree | 1d0723fce1110759f0e6f80baab50d4060e9968c | |
parent | 7b2521a0f5fee741ae307092fa59c734d93d712e (diff) |
cerbero: Fix os.path.relpath on Windows
os.path.relpath was broken because we were monkey-patching
os.path.abspath. We need to revert it to the original implementation
when invoking os.path.relpath.
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/950>
-rw-r--r-- | cerbero/hacks.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/cerbero/hacks.py b/cerbero/hacks.py index a8196a6f..cc3d501f 100644 --- a/cerbero/hacks.py +++ b/cerbero/hacks.py @@ -62,6 +62,7 @@ oldjoin = os.path.join oldexpanduser = os.path.expanduser oldabspath = os.path.abspath oldrealpath = os.path.realpath +oldrelpath = os.path.relpath def join(*args): @@ -79,6 +80,14 @@ def abspath(path): def realpath(path): return oldrealpath(path).replace('\\', '/') + +def relpath(path, start=None): + os.path.abspath = oldabspath + ret = oldrelpath(path, start).replace('\\', '/') + os.path.abspath = abspath + return ret + + if sys.platform.startswith('win'): # FIXME: replace all usage of os.path.join with pathlib.PurePath.as_posix() # instead of doing this brittle monkey-patching. @@ -86,6 +95,7 @@ if sys.platform.startswith('win'): os.path.expanduser = expanduser os.path.abspath = abspath os.path.realpath = realpath + os.path.relpath = relpath # On windows, python transforms all enviroment variables to uppercase, # but we need lowercase ones to override configure options like |