Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: realpath on windows changed behavior in python 3.8 to expand mapped drive letters to their UNC path names #1856

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/rez/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ def _parse_env_var(self, value):
"alias_back": OptionalStr,
"package_preprocess_function": OptionalStrOrFunction,
"package_preprocess_mode": PreprocessMode_,
"windows_unc_path": Bool,
"error_on_missing_variant_requires": Bool,
"context_tracking_host": OptionalStr,
"variant_shortlinks_dirname": OptionalStr,
Expand Down
6 changes: 3 additions & 3 deletions src/rez/resolved_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from rez.utils.formatting import columnise, PackageRequest, ENV_VAR_REGEX, \
header_comment, minor_header_comment
from rez.utils.data_utils import deep_del
from rez.utils.filesystem import TempDirs, is_subdirectory, canonical_path
from rez.utils.filesystem import TempDirs, is_subdirectory, canonical_path, real_path
from rez.utils.memcached import pool_memcached_connections
from rez.utils.logging_ import print_error, print_warning
from rez.utils.which import which
Expand Down Expand Up @@ -1816,8 +1816,8 @@ def _adjust_variant_for_bundling(cls, handle, out):

if is_subdirectory(repo_path, bundle_path):
vars_["location"] = os.path.relpath(
os.path.realpath(repo_path),
os.path.realpath(bundle_path)
real_path(repo_path),
real_path(bundle_path)
)

# serializing in, make repo absolute
Expand Down
5 changes: 5 additions & 0 deletions src/rez/rezconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,11 @@
# - "override": Package's preprocess function completely overrides the global preprocess.
package_preprocess_mode = "override"

# Define if we want to windows drive letters to be resolved to UNC paths in the context
# resolution. Before Python 3.8 drive letters were not resolved to drive
# letters. To keep the pre Python 3.8 behavior this should be set to False.
windows_unc_path = False

###############################################################################
# Context Tracking
###############################################################################
Expand Down
3 changes: 2 additions & 1 deletion src/rez/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import platform

from rez import __version__
from rez.utils.filesystem import real_path
from rez.utils.platform_ import platform_
from rez.exceptions import RezSystemError
from rez.utils.data_utils import cached_property
Expand Down Expand Up @@ -237,7 +238,7 @@ def rez_bin_path(self):

validation_file = os.path.join(binpath, ".rez_production_install")
if os.path.exists(validation_file):
return os.path.realpath(binpath)
return real_path(binpath)

return None

Expand Down
18 changes: 15 additions & 3 deletions src/rez/utils/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ def make_tmp_name(name):

def is_subdirectory(path_a, path_b):
"""Returns True if `path_a` is a subdirectory of `path_b`."""
path_a = os.path.realpath(path_a)
path_b = os.path.realpath(path_b)
path_a = real_path(path_a)
path_b = real_path(path_b)
try:
relative = os.path.relpath(path_a, path_b)
except ValueError:
Expand Down Expand Up @@ -519,7 +519,7 @@ def canonical_path(path, platform=None):
if platform is None:
platform = platform_

path = os.path.normpath(os.path.realpath(path))
path = os.path.normpath(real_path(path))

if not platform.has_case_sensitive_filesystem:
return path.lower()
Expand Down Expand Up @@ -744,3 +744,15 @@ def rename(src, dst):
raise OSError("Rename {} to {} failed.".format(src, dst))
else:
raise err


def real_path(path):
"""Determine the real path resolving symbolic links and relative paths.

Backwards compatibility with python-3.7 behavior of os.path.realpath on windows."""

from rez.config import config # Avoid circular imports

if is_windows and not config.windows_unc_path:
return os.path.abspath(path)
return os.path.realpath(path)
Loading