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

Commitd5ed266

Browse files
committed
Use bytes in bash.exe check; retest no-distro case
This removes text=True from the subprocess.run call, changing strliterals to bytes where appropriate and (less importantly) using"%r" instead of "%s" in log messages so it's clear that printingthe repr of a bytes object is, at least for now, intentional.The reason for this is that the encoding of error messages producedby running the WSL bash.exe, when it attempts but fails to use aWSL system, varies based on what error occurred. When no systemsare installed, the output can be decoded as UTF-8. When an errorfrom "deeper down" is reported, at least for Bash/Service errors,the output is encoded in UTF-16LE, and attempting to decode it asUTF-8 interleaves lots of null characters in the best case. With abytes object, loss of information is avoided, and it is clear oninspection that the output requires decoding.The most common case of such an error is *probably*: Insufficient system resources exist to complete the requested service. Error code: Bash/Service/CreateInstance/CreateVm/HCS/0x800705aaHowever, that is tricky to produce intentionally on some systems.To produce a test error, "wsl --shutdown" can be run repeatedlywhile a _WinBashStatus.check() call is in progress. This produces: The virtual machine or container was forcefully exited. Error code: Bash/Service/0x80370107Assuming the output always includes the text "Error code:", it maybe feasible to reliably detect which cases it is. This couldespecially improve the log message. But for now that is not done.In adddition to changing from text to binary mode, this commit alsotemporarily removes the setup-wsl step from the CI workflow again,to verify on CI that the text-to-binary change doesn't break theWslNoDistro case. Manual testing shows the other cases still work.
1 parent7ff3cee commitd5ed266

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

‎.github/workflows/pythonpackage.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ jobs:
3535
python-version:${{ matrix.python-version }}
3636
allow-prereleases:${{ matrix.experimental }}
3737

38-
-name:Set up WSL (Windows)
39-
if:startsWith(matrix.os, 'windows')
40-
uses:Vampire/setup-wsl@v2.0.2
41-
with:
42-
distribution:Debian
43-
4438
-name:Prepare this repo for tests
4539
run:|
4640
./init-tests-after-clone.sh

‎test/test_index.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ def check(cls):
9494
ifos.name!="nt":
9595
returncls.Inapplicable()
9696

97-
no_distro_message="Windows Subsystem for Linux has no installed distributions."
97+
# Use bytes because messages for different WSL errors use different encodings.
98+
no_distro_message=b"Windows Subsystem for Linux has no installed distributions."
9899

99100
deferror_running_bash(error):
100-
log.error("Error running bash.exe to check WSL status: %s",error)
101+
log.error("Error running bash.exe to check WSL status: %r",error)
101102
returncls.ErrorWhileChecking(error)
102103

103104
try:
@@ -106,7 +107,7 @@ def error_running_bash(error):
106107
# information on ways to check for WSL, see https://superuser.com/a/1749811.
107108
script='test -e /proc/sys/fs/binfmt_misc/WSLInterop; echo "$?"'
108109
command= ["bash.exe","-c",script]
109-
proc=subprocess.run(command,capture_output=True,check=True,text=True)
110+
proc=subprocess.run(command,capture_output=True,check=True)
110111
exceptFileNotFoundError:
111112
returncls.Absent()
112113
exceptOSErroraserror:
@@ -117,11 +118,11 @@ def error_running_bash(error):
117118
returnerror_running_bash(error)
118119

119120
status=proc.stdout.rstrip()
120-
ifstatus=="0":
121+
ifstatus==b"0":
121122
returncls.Wsl()
122-
ifstatus=="1":
123+
ifstatus==b"1":
123124
returncls.Native()
124-
log.error("Strange output checking WSL status: %s",proc.stdout)
125+
log.error("Strange output checking WSL status: %r",proc.stdout)
125126
returncls.ErrorWhileChecking(proc)
126127

127128

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp