Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd779a75

Browse files
committed
Don't assume WSL-related bash.exe error is English
Instead of searching for an English sentence from the errormessage, this searches for the specific aka.ms short URL itcontains in all languages, which points to a page about downloadingdistributions for WSL from the Microsoft Store (Windows Store).The URL is controlled and hosted by Microsoft and intended as apermalink. Thus this approach should be more reliable even forEnglish, as the specific wording of the message might be rephrasedover time, so this may have a lower risk of false negatives.Because it only makes sense to give a link for obtaining adistribution in an error message when no distribution is installedalready, the risk of false positives should also be fairly low.The URL is included in the output telling the user they have nodistributions installed even on systems like Windows Server wherethe Microsoft Store is not itself available, and even in situationswhere WSL has successfully downloaded and unpacked a distributionbut could not run it the first time because it is using WSL 2 butthe necessary virtualization is unavailable. Because these areincluded among the situations where the hook tests should be markedxfail, it is suitable for the purpose at hand.Furthermore, while this only works if we correctly guess if theencoding is UTF-16LE or not, it should be *fairly* robust againstincorrect decoding of the message where a single-byte encoding istreated as UTF-8, or UTF-8 is treated as a single-byte encoding, orone single-byte encoding is treated as another (i.e., wrong ANSIcode page). But some related encoding subtleties remain to beresolved.Although reliability is likely improved even for English, tofaciliate debugging the WslNoDistro case now carries analogous`process` and `message` arguments to the `CheckError` case.On some Windows systems, wsl.exe exists in System32 but bash.exedoes not. This is not inherently a problem for run_commit_hook asit currently stands, which is just trying to use whatever bash.exeis available. (It is not clear that WSL should be preferred.) Thisis currently so, on some systems, where WSL is not really set up;wsl.exe can be used to do so. This is a situation where no WSLdistributions are present, but because the bash.exe WSL wrapper isalso absent, it is not a problem.However, I had wrongly claimed in the _WinBashStatus.checkdocstring that bash.exe is in System32 whenever WSL is present. Sothis also revises the docstring to say only that this is usually so(plus some further revision for clarity).
1 parent496acaa commitd779a75

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

‎test/test_index.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
importos
99
importos.pathasosp
1010
frompathlibimportPath
11+
importre
1112
fromstatimportS_ISLNK,ST_MODE
1213
importsubprocess
1314
importtempfile
@@ -58,7 +59,7 @@ class _WinBashStatus:
5859
Wsl=constructor()
5960
"""Running ``bash.exe`` calls ``bash`` in a WSL distribution."""
6061

61-
WslNoDistro=constructor()
62+
WslNoDistro=constructor("process","message")
6263
"""Running ``bash.exe` tries to run bash on a WSL distribution, but none exists."""
6364

6465
CheckError=constructor("process","message")
@@ -80,20 +81,18 @@ def check(cls):
8081
8182
:func:`index.fun.run_commit_hook` uses :class:`subprocess.Popen`, including when
8283
it runs ``bash.exe`` on Windows. It doesn't pass ``shell=True`` (and shouldn't).
83-
On Windows, `Popen` calls ``CreateProcessW``, whichsearches several locations
84-
prior tousing the ``PATH`` environment variable. It is expected tosearch the
85-
``System32``directory, even if another directory containing the executable
86-
precedes it in``PATH``. (Other differences are less relevant here.) When WSL is
87-
installed, evenwith no distributions, ``bash.exe`` exists in ``System32``, and
88-
`Popen`finds it even if another ``bash.exe`` precedes it in ``PATH``, as on CI.
89-
If WSLis absent, ``System32`` may still have ``bash.exe``, as Windows users and
84+
On Windows, `Popen` calls ``CreateProcessW``, whichchecks some locations before
85+
using the ``PATH`` environment variable. It is expected totry the ``System32``
86+
directory, even if another directory containing the executable precedes it in
87+
``PATH``. (Other differences are less relevant here.) When WSL is present, even
88+
with no distributions, ``bash.exe``usuallyexists in ``System32``, and `Popen`
89+
finds it even if another ``bash.exe`` precedes it in ``PATH``, as on CI. If WSL
90+
is absent, ``System32`` may still have ``bash.exe``, as Windows users and
9091
administrators occasionally put executables there in lieu of extending ``PATH``.
9192
"""
9293
ifos.name!="nt":
9394
returncls.Inapplicable()
9495

95-
no_distro_message="Windows Subsystem for Linux has no installed distributions."
96-
9796
try:
9897
# Output rather than forwarding the test command's exit status so that if a
9998
# failure occurs before we even get to this point, we will detect it. For
@@ -106,11 +105,12 @@ def check(cls):
106105
exceptOSErroraserror:
107106
returncls.WinError(error)
108107

108+
# FIXME: When not UTF-16LE: try local ANSI code page, then fall back to UTF-8.
109109
encoding="utf-16le"ifb"\r\0\n\0"inprocess.stdoutelse"utf-8"
110110
text=process.stdout.decode(encoding).rstrip()# stdout includes WSL errors.
111111

112-
ifprocess.returncode==1andtext.startswith(no_distro_message):
113-
returncls.WslNoDistro()
112+
ifprocess.returncode==1andre.search(r"\bhttps://aka.ms/wslstore\b",text):
113+
returncls.WslNoDistro(process,text)
114114
ifprocess.returncode!=0:
115115
log.error("Error running bash.exe to check WSL status: %s",text)
116116
returncls.CheckError(process,text)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp