From b976588ff6cc178022d75b13f6b4a648719a827a Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sun, 11 May 2025 09:03:27 +0900 Subject: [PATCH 1/4] fix test_python_legacy_windows_stdio --- Lib/test/test_cmd_line.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 1b40e0d05fe3bc..fe0eeb66fcca41 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -972,10 +972,20 @@ def test_python_legacy_windows_fs_encoding(self): @unittest.skipUnless(support.MS_WINDOWS, 'Test only applicable on Windows') def test_python_legacy_windows_stdio(self): - code = "import sys; print(sys.stdin.encoding, sys.stdout.encoding)" - expected = 'cp' - rc, out, err = assert_python_ok('-c', code, PYTHONLEGACYWINDOWSSTDIO='1') - self.assertIn(expected.encode(), out) + def get_stderr_class(legacy_windows_stdio): + code = 'import sys; print(type(sys.stderr.buffer.raw))' + env = {'PYTHONLEGACYWINDOWSSTDIO': str(int(legacy_windows_stdio))} + # use stderr=None as legacy_windows_stdio doesn't affect pipes + p = spawn_python('-c', code, env=env, stderr=None, + creationflags=subprocess.CREATE_NEW_CONSOLE) + out = kill_python(p).strip().decode('ascii', 'ignore') + return out.removeprefix("") + + out = get_stderr_class(legacy_windows_stdio=True) + self.assertEqual('_io.FileIO', out) + + out = get_stderr_class(legacy_windows_stdio=False) + self.assertEqual('_io._WindowsConsoleIO', out) @unittest.skipIf("-fsanitize" in sysconfig.get_config_vars().get('PY_CFLAGS', ()), "PYTHONMALLOCSTATS doesn't work with ASAN") From 876feef1bf46ada0c75e0841993ec7d21a943214 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sun, 11 May 2025 09:31:27 +0900 Subject: [PATCH 2/4] add workflow_dispatch --- .github/workflows/reusable-windows.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/reusable-windows.yml b/.github/workflows/reusable-windows.yml index 37c802095b0f2f..ca62b2e8dca7de 100644 --- a/.github/workflows/reusable-windows.yml +++ b/.github/workflows/reusable-windows.yml @@ -1,6 +1,21 @@ name: Reusable Windows on: + workflow_dispatch: + inputs: + arch: + description: CPU architecture + required: true + type: choice + options: + - x86 + - x64 + - arm64 + free-threading: + description: Whether to compile CPython in free-threading mode + required: false + type: boolean + default: false workflow_call: inputs: arch: From d4aa6d7326611e5d62e3642acd02e9519e90dcd7 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sun, 11 May 2025 09:40:32 +0900 Subject: [PATCH 3/4] kick reusable-windows --- .github/workflows/reusable-windows.yml | 15 -------------- .github/workflows/windows.yml | 28 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/reusable-windows.yml b/.github/workflows/reusable-windows.yml index ca62b2e8dca7de..37c802095b0f2f 100644 --- a/.github/workflows/reusable-windows.yml +++ b/.github/workflows/reusable-windows.yml @@ -1,21 +1,6 @@ name: Reusable Windows on: - workflow_dispatch: - inputs: - arch: - description: CPU architecture - required: true - type: choice - options: - - x86 - - x64 - - arm64 - free-threading: - description: Whether to compile CPython in free-threading mode - required: false - type: boolean - default: false workflow_call: inputs: arch: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000000000..235b5b86a437be --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,28 @@ +name: Manual Windows + +on: + workflow_dispatch: + inputs: + arch: + description: CPU architecture + required: true + type: choice + options: + - x86 + - x64 + - arm64 + free-threading: + description: Whether to compile CPython in free-threading mode + required: false + type: boolean + default: false + +env: + FORCE_COLOR: 1 + +jobs: + build-windows: + uses: ./.github/workflows/reusable-windows.yml + with: + arch: ${{ inputs.arch }} + free-threading: ${{ inputs.free-threading }} From 5e156d655e91d22b7f9abd5f7cbc55f10f379be6 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sun, 11 May 2025 10:42:56 +0900 Subject: [PATCH 4/4] skip test when stderr is not WindowsConsoleIO --- Lib/test/test_cmd_line.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index fe0eeb66fcca41..92c050cb5d2c2a 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -970,14 +970,14 @@ def test_python_legacy_windows_fs_encoding(self): rc, out, err = assert_python_ok('-c', code, PYTHONLEGACYWINDOWSFSENCODING='1') self.assertIn(expected.encode(), out) - @unittest.skipUnless(support.MS_WINDOWS, 'Test only applicable on Windows') + @unittest.skipUnless(type(sys.stderr.buffer.raw).__name__ == "_WindowsConsoleIO", + "Test only applicable on Windows with console IO") def test_python_legacy_windows_stdio(self): def get_stderr_class(legacy_windows_stdio): code = 'import sys; print(type(sys.stderr.buffer.raw))' env = {'PYTHONLEGACYWINDOWSSTDIO': str(int(legacy_windows_stdio))} # use stderr=None as legacy_windows_stdio doesn't affect pipes - p = spawn_python('-c', code, env=env, stderr=None, - creationflags=subprocess.CREATE_NEW_CONSOLE) + p = spawn_python('-c', code, env=env, stderr=None) out = kill_python(p).strip().decode('ascii', 'ignore') return out.removeprefix("")