Skip to content

Commit 6f40d58

Browse files
jhonabreulclaude
andcommitted
CI: install x64 .NET host and fix PYTHONHOME for uv venv
Two failures after moving Python provisioning to uv: - macOS: "Could not find 'dotnet' host for the 'X64' architecture". macos-15 is Apple Silicon, so setup-dotnet installed an arm64 host while the tests run --runtime any-x64. Pass the architecture input (only available on setup-dotnet@main) so the x64 host is installed. - All others: "ModuleNotFoundError: No module named 'encodings'". PYTHONHOME was set to sys.prefix, which under a uv venv points at the venv dir (no stdlib). When .NET hosts the interpreter it could not find the stdlib. Point PYTHONHOME at sys.base_prefix and add the venv site-packages via PYTHONPATH, and scope both to the .NET-hosts-Python steps only -- the venv python running pytest must keep its own sys.prefix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4e17fca commit 6f40d58

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

.github/workflows/main.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ jobs:
2828
- name: Checkout code
2929
uses: actions/checkout@v4
3030

31+
# macos-15 (and the arm64 path generally) is Apple Silicon, but this
32+
# matrix builds/tests x64. The architecture input installs the matching
33+
# .NET host; it currently only exists on setup-dotnet@main.
3134
- name: Setup .NET
32-
uses: actions/setup-dotnet@v4
35+
uses: actions/setup-dotnet@main
3336
with:
3437
dotnet-version: '10.0.x'
38+
architecture: ${{ matrix.platform }}
3539

3640
# Use astral-sh/setup-uv (python-build-standalone) instead of
3741
# actions/setup-python. The setup-python x64 macOS builds dynamically
@@ -55,19 +59,32 @@ jobs:
5559
run: |
5660
uv pip install -v .
5761
58-
- name: Set Python DLL path and PYTHONHOME (non Windows)
62+
# Python is provisioned in a uv virtual environment, whose sys.prefix has
63+
# no stdlib (only site-packages). When .NET hosts the interpreter we must
64+
# point PYTHONHOME at the *base* install (sys.base_prefix) so it can find
65+
# the stdlib (e.g. `encodings`), and add the venv's site-packages via
66+
# PYTHONPATH so embedded code can still import clr/numpy. PYTHONNET_PYDLL
67+
# tells Python.Runtime which libpython to load. PYTHONHOME is intentionally
68+
# NOT set globally: the venv `python` running pytest must keep its own
69+
# sys.prefix to resolve its installed packages.
70+
- name: Set Python DLL path, home and site-packages (non Windows)
5971
if: ${{ matrix.os != 'windows' }}
6072
run: |
61-
echo PYTHONNET_PYDLL=$(python -m pythonnet.find_libpython) >> $GITHUB_ENV
62-
echo PYTHONHOME=$(python -c 'import sys; print(sys.prefix)') >> $GITHUB_ENV
73+
echo "PYTHONNET_PYDLL=$(python -m pythonnet.find_libpython)" >> $GITHUB_ENV
74+
echo "PY_HOME=$(python -c 'import sys; print(sys.base_prefix)')" >> $GITHUB_ENV
75+
echo "PY_SITE=$(python -c 'import sysconfig; print(sysconfig.get_path(\"purelib\"))')" >> $GITHUB_ENV
6376
64-
- name: Set Python DLL path and PYTHONHOME (Windows)
77+
- name: Set Python DLL path, home and site-packages (Windows)
6578
if: ${{ matrix.os == 'windows' }}
6679
run: |
6780
Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append -InputObject "PYTHONNET_PYDLL=$(python -m pythonnet.find_libpython)"
68-
Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append -InputObject "PYTHONHOME=$(python -c 'import sys; print(sys.prefix)')"
81+
Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append -InputObject "PY_HOME=$(python -c 'import sys; print(sys.base_prefix)')"
82+
Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append -InputObject "PY_SITE=$(python -c 'import sysconfig; print(sysconfig.get_path(\"purelib\"))')"
6983
7084
- name: Embedding tests
85+
env:
86+
PYTHONHOME: ${{ env.PY_HOME }}
87+
PYTHONPATH: ${{ env.PY_SITE }}
7188
run: dotnet test --runtime any-${{ matrix.platform }} --logger "console;verbosity=detailed" src/embed_tests/
7289

7390
# The runtime now targets net10.0 only, so the Mono and .NET Framework
@@ -78,4 +95,7 @@ jobs:
7895
run: pytest --runtime netcore tests
7996

8097
- name: Python tests run from .NET
98+
env:
99+
PYTHONHOME: ${{ env.PY_HOME }}
100+
PYTHONPATH: ${{ env.PY_SITE }}
81101
run: dotnet test --runtime any-${{ matrix.platform }} src/python_tests_runner/

0 commit comments

Comments
 (0)