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

Environment resolution uses UNC paths with Python 3.10, 3.7 was using mounted network drives. #1438

Open
KelSolaar opened this issue Feb 2, 2023 · 19 comments · May be fixed by #1856
Open
Labels
bug os:windows Windows-specific shell Shell related issues

Comments

@KelSolaar
Copy link
Contributor

Hello,

As we are trying to update our Rez version from 2.91, I noted that the resolution now uses UNC paths:

Rez v2.112.0

C:\Users\tmansencal>rez-env dcraw

You are now in a rez-configured environment.

resolved by tmansencal@***, on Fri Feb 03 08:48:25 2023, using Rez v2.112.0

requested packages:
dcraw
~platform==windows           (implicit)
~arch==AMD64                 (implicit)
~os==windows-10.0.***.SP0  (implicit)

resolved packages:
arch-AMD64        c:\***\packages\***\arch\AMD64
dcraw-9.27        \\***\***\packages\thirdparty\dcraw\9.27\platform-windows\arch-AMD64
platform-windows  c:\***\packages\***\platform\windows

Rez v2.2.91.0

C:\Users\tmansencal>rez-env dcraw

You are now in a rez-configured environment.

resolved by tmansencal@***, on Fri Feb 03 08:53:09 2023, using Rez v2.91.0

requested packages:
dcraw
~platform==windows           (implicit)
~arch==AMD64                 (implicit)
~os==windows-10.0.***.SP0  (implicit)

resolved packages:
arch-AMD64        c:\***\packages\***\arch\AMD64
dcraw-9.27        s:\packages\thirdparty\dcraw\9.27\platform-windows\arch-AMD64
platform-windows  c:\***\packages\***\platform\windows

Environment

  • OS: Window 10
  • Rez version (eg "2.100.0"): v2.112.0
  • Rez python version (output of "rez-python --version"): Python 3.10.9

I do think that this is strictly caused by the Python difference but would be keen to know if anyone has seen that already before I start digging.

To Reproduce

  1. Build Rez with Python 3.7, resolve environment from mounted drive.
  2. Build Rez with Python 3.10, resolve environment from mounted drive.
  3. Compare the resolved package paths.

Expected behavior
The mounted drive package path should be used as UNC paths wreck havoc in many CMD scripts.

Actual behavior
The UNC package path is used instead.

@KelSolaar KelSolaar added the bug label Feb 2, 2023
@JeanChristopheMorinPerso JeanChristopheMorinPerso added the os:windows Windows-specific label Feb 2, 2023
@flord
Copy link

flord commented Feb 6, 2023

I would argue this should be a config. Mapped drive letters can wreck havoc in other setups, like the one we have here. We only use powershell where UNC works fine.

@KelSolaar
Copy link
Contributor Author

It is already wrecking havoc! :) The default behaviour on something as critical as the way paths are handled should not change without huge warnings.

@instinct-vfx
Copy link
Contributor

I would expect that the config is used as-is and not transformed. Can you share your config (or any environment overrides) respectively?

@KelSolaar
Copy link
Contributor Author

KelSolaar commented Feb 6, 2023

@instinct-vfx: There is nothing extra-ordinary here, only the packages_path variable that sets various Windows paths, all of them being drive letter-based.

@instinct-vfx
Copy link
Contributor

I just did parallel installs of 2.91.0 and 2.112.0 and i can not reproduce this. Are you sure there are not other differences (one installation being python2.7 and one being python3.x maybe?)

@KelSolaar
Copy link
Contributor Author

Hey @instinct-vfx,

As I was saying in the description, I think it is related to the Python version and not Rez itself, or indirectly at least. Did you try with Python 3.7 vs 3.10?

Cheers,

Thomas

@instinct-vfx
Copy link
Contributor

Sorry, i must have skipped that on first read :( I did try with 3.9 in my case. We will need to find out which specific change at what version broke this and see what's the best way to make it behave backwards compatible. These are really tricky to detect. Next time we can detect it by adding tests, but it's unlikely to change again anytime soon i guess :/

@yanshil
Copy link
Contributor

yanshil commented Feb 17, 2023

image
Hey guys, let me give you an insight.

This is an issue caused by different behavior of how UNC path resolved by os.path.realpath. It occurs at py-3.7 <-> py-3.8

Note: The rez version on the screenshot is not the actual one. We applied some local changes but didn't version if with another tag.

@yanshil
Copy link
Contributor

yanshil commented Feb 17, 2023

@KelSolaar
Copy link
Contributor Author

Great finding @yanshil!

@KelSolaar
Copy link
Contributor Author

Confirming the behaviour on our end:

C:\Users\tmansencal>rez-env python-2.7 -- python -c "import os;print(os.path.realpath('S:\\****'))"
S:\****

C:\Users\tmansencal>rez-env python-3.6 -- python -c "import os;print(os.path.realpath('S:\\****'))"
S:\****

C:\Users\tmansencal>rez-env python-3.7 -- python -c "import os;print(os.path.realpath('S:\\****'))"
S:\****

C:\Users\tmansencal>rez-env python-3.9 -- python -c "import os;print(os.path.realpath('S:\\****'))"
\\****\****\****

C:\Users\tmansencal>rez-env python-3.10 -- python -c "import os;print(os.path.realpath('S:\\****'))"
\\****\****\****

@KelSolaar
Copy link
Contributor Author

For completeness: image

@JeanChristopheMorinPerso
Copy link
Member

JeanChristopheMorinPerso commented Feb 22, 2023

Thanks @yanshil for jumping in! I'm not a Windows expert and I also don't have the bandwidth right now to look into this specific issue. What do you think would be the next step on this? WOUld there be a relatively easy fix to this? @instinct-vfx any opinion?

@KelSolaar
Copy link
Contributor Author

KelSolaar commented Feb 22, 2023

I think we should first figure out what was the intent for using os.path.realpath. Does it make sense to resolve symlinks in this context or would os.path.abspath suffice here? Maybe @nerdvegas can comment?

@JeanChristopheMorinPerso
Copy link
Member

Here is where the canonical_path function is called. Each call site has a comment explaining why it's called.

# Must make canonical otherwise a symlinked path will cause it not
# to match the repo location, which is always canonical.
#
location = os.path.join(bundle_path, repo_path)
location = canonical_path(location, platform_)

# ensure that differing case doesn't get interpreted as different repos
# on case-insensitive platforms (eg windows)
location = canonical_path(location, platform_)

# It appears that sometimes, the handle location can differ to the
# repo location even though they are the same path (different
# mounts). We account for that here.
#
# https://github.com/AcademySoftwareFoundation/rez/pull/957
#
if location != self.location:
location = canonical_path(location, platform_)

@KelSolaar
Copy link
Contributor Author

KelSolaar commented Feb 26, 2023

It seems like the intent was to resolve symlinks for Linux. The behavioural change of os.path.realpath affects Windows only.

I would be inclined to have a specific case for Windows that resolves the path in a backward compatible way with a Config option to be able to have the new symlink and UNC path resolution for people that wants it.

Using os.path.abspath should hopefully provides the expected behaviour:

C:\Users\tmansencal>rez-env python -- python
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec  6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.realpath(".")
'C:\\Users\\tmansencal'
>>> os.path.abspath(".")
'C:\\Users\\tmansencal'

@KelSolaar
Copy link
Contributor Author

Spent a bit of time on this one and we are going to go with a sitecustomize.py file:

image

This addresses our needs and fixes the regression. I'm still keen get an upstream fix/solution for the problem that said!

@KelSolaar KelSolaar mentioned this issue Mar 6, 2023
6 tasks
@JeanChristopheMorinPerso JeanChristopheMorinPerso added the shell Shell related issues label Mar 11, 2023
@JeanChristopheMorinPerso
Copy link
Member

JeanChristopheMorinPerso commented Mar 16, 2023

From the TSC meeting: Let's try to replace all os.path.realpath with rez.utils.filesystem. canonical_path.

Seems introduced by #775.

Will need some thinking and testing.

@yanshil
Copy link
Contributor

yanshil commented Mar 29, 2023

Ahhh, actually I did came across with an issue related iwth UNC path, and I started a PR at that time but I didn't keep working on it.

I would suggest testing should also include this path mismatch issue.
#1329

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug os:windows Windows-specific shell Shell related issues
Projects
None yet
5 participants