-
-
Notifications
You must be signed in to change notification settings - Fork 762
Check git mode also in WSL #512
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
Conversation
| def check_executables(paths: List[str]) -> int: | ||
| if sys.platform == 'win32': # pragma: win32 cover | ||
| if ( | ||
| sys.platform == 'win32' or 'microsoft' in platform.uname()[3].lower() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you share an example output here and/or add a test? I don't have access to WSL to verify this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add a comment in the code with the sample output?
I'm not sure what kind of test to add for this, mock the output of platform.uname() and assert _check_git_filemode is called?
Sample output:
$ python3
Python 3.7.5 (default, Nov 7 2019, 10:50:52)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.uname()
uname_result(system='Linux', node='DESKTOP-A7438J1', release='4.4.0-19041-Microsoft', version='#1-Microsoft Fri Dec 06 14:06:00 PST 2019', machine='x86_64', processor='x86_64')
>>> platform.uname()[3].lower()
'#1-microsoft fri dec 06 14:06:00 pst 2019'
>>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asottile Is the sample output enough, and if not, is the suggested test case acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check seems much too weak imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it seem too weak?
checking if the string "microsoft" is in the uname doesn't necessarily mean this is WSL |
|
I think it's OK, Microsoft builds their own kernels. Checking uname seems to be the accepted solution, see for example here: https://www.scivision.dev/python-detect-wsl/ |
I can build my own kernel too, that doesn't mean this is ok
just because someone else makes the same mistake doesn't mean we should. the uname is an arbitrary string and not necessarily an indication this is WSL |
|
|
OK, so you're saying it's likely someone else builds their own custom kernel, sets uname to 'Microsoft', and then has the git mode check fail on them? |
|
The comment in the thread you're linking to seems to about distinguishing wsl from wsl2 btw, in both cases it's likely that file modes are not supported. Edit: The best way would be to try to properly detect if file modes are supported though, instead of checking for win32 or trying to detect wsl as I attempt in the PR. |
|
@asottile is there any way we could get this merged? I must admit I don't understand your comment about building your own kernel, is your concern false positives due to someone building their own kernel, where the substring "microsoft" is present in Another method for detecting WSL, which is proposed in the WSL bugtracker, is to check for the presence of a Windows binary on the path, e.g. the output of How about making the WSL detection opt-in, then it can be used by those who can accept false positives? |
not as-is, no
correct, looking for a string in a kernel name is not a proper detection
that seems less error-prone at the very least
I'd rather not have configuration options -- worst case you can opt-in by forking |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
There are a number of different options for detecting WSL, so many, in fact, that I have stopped well short of compiling a comprehensive list. One could use any subset of them depending on the degree of reliability desired. Personally, I would simply use the first one when Git is present, because Git already inspects the file system it's on for us for precisely the behavior in question:
If the first option only is used and Git isn't present, then the script can simply do what it already does on non-Windows platforms. Theoretically, one could check |
|
@Kurt-von-Laven should I close this and you can replace it with a PR implementing one of the other metods? FWIW, home-assistant is no longer using |
|
That sounds good to me if @asottile agrees with my implementation plan. That is a clever workaround. How did you arrange for certain tests to be skipped locally? We should probably do the same since this isn't the only check we run that struggles in some environments. |
|
Hello all, this is what microsoft uses to detect WSL in the VSCode launcher script (https://github.com/microsoft/vscode/blob/main/scripts/code.sh#L11-L13): if grep -qi Microsoft /proc/version && type powershell.exe > /dev/null 2>&1; then
IN_WSL=true
fiMaybe this could work here as well. |
|
@hamdanal, no, I don't think that will be accepted here in light of the above response from the owner to a very similar proposition:
To summarize my above suggestions, I would simply check whether |
|
@emontnemery, I have opened #730, so you may feel free to close this pull request now if you agree with my changes. |
Extend #480 to check git mode when running under WSL too