Skip to content
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

Add GraalPy support #5141

Merged
merged 2 commits into from
Jul 19, 2024
Merged

Add GraalPy support #5141

merged 2 commits into from
Jul 19, 2024

Conversation

timfel
Copy link
Contributor

@timfel timfel commented Jul 17, 2024

Summary

Currently, uv refuses to install anything on GraalPy. This is currently blocking GraalPy testing with cibuildwheel, since manylinux includes both uv and graalpy (but doesn't test with uv), whereas cibuildwheel defaults to uv. See e.g. https://github.com/pypa/cibuildwheel/actions/runs/9956369360/job/27506182952?pr=1538 where it gives

      + python -m build /project/sample_proj --wheel --outdir=/tmp/cibuildwheel/built_wheel --installer=uv
  * Creating isolated environment: venv+uv...
  * Using external uv from /usr/local/bin/uv
  * Installing packages in isolated environment:
    - setuptools >= 40.8.0
  > /usr/local/bin/uv pip install "setuptools >= 40.8.0"
  < error: Unknown implementation: `graalpy`

Test Plan

I simply based the GraalPy support on PyPy and added some small tests. I'm open to discussing how to test this. GraalPy is available for manylinux images and with setup-python, so we should be able to add tests against it to the CI. I locally confirmed by installing uv into a GraalPy venv and then trying things like uv pip install Pillow and testing those extensions.

@zanieb zanieb added the enhancement New feature or request label Jul 17, 2024
@zanieb zanieb self-assigned this Jul 17, 2024
@zanieb
Copy link
Member

zanieb commented Jul 17, 2024

Thanks for contributing! Welcome to the project :)

Could you add a CI integration test in the style of the PyPy one?

@timfel timfel force-pushed the tim/graalpy branch 2 times, most recently from edd6e5f to ff3dd22 Compare July 18, 2024 07:57
@timfel
Copy link
Contributor Author

timfel commented Jul 18, 2024

Could you add a CI integration test in the style of the PyPy one?

Added. There's a bug with GraalPy 24.0 on Linux around parsing the home property in pyvenv.cfg that we hadn't noticed so far because the venv and virtualenv modules seem to be doing something different. I fixed this in GraalPy master already and the fix is due out in the first week of September. Until then I added a workaround to the CI job for GraalPy on Linux.

runs-on: windows-latest

steps:
- uses: timfel/setup-python@fc9bcb4a04f5b1ea7d678c2ca7ea1c479a2468d7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR to setup-python is open: actions/setup-python#880

- name: Graalpy info
run: |
which graalpy
echo "GRAAL_PYTHONHOME=$(graalpy -c 'print(__graalpython__.home)')" >> $GITHUB_ENV
Copy link
Contributor Author

@timfel timfel Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workaround for 24.0 bug (fixed in 24.1, due out in September)

@zanieb
Copy link
Member

zanieb commented Jul 18, 2024

Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me once it's passing CI.

@zanieb zanieb merged commit 24a0268 into astral-sh:main Jul 19, 2024
54 checks passed
@timfel timfel deleted the tim/graalpy branch July 19, 2024 03:31
@mkniewallner mkniewallner mentioned this pull request Jul 19, 2024
@mayeut
Copy link
Contributor

mayeut commented Jul 20, 2024

@timfel, this does not seem to work:

[root@78fc86164bc0 /]# uv -V
uv 0.2.27
[root@78fc86164bc0 /]# uv venv --python /opt/python/graalpy310-graalpy240_310_native/bin/python /tmp/uv-test-graalpy3.10
Using Python 3.10.13 interpreter at: opt/python/graalpy310-graalpy240_310_native/bin/python
Creating virtualenv at: tmp/uv-test-graalpy3.10
[root@78fc86164bc0 /]# /tmp/uv-test-graalpy3.10/bin/python -V
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[python::PythonContext] WARNING: could not determine Graal.Python's standard library path. You need to pass --python.StdLibHome if you want to use the standard library.
[python::PythonContext] WARNING: could not determine Graal.Python's core path - you may need to pass --python.CoreHome.
[python::PythonContext] WARNING: could not determine Graal.Python's C API library path. You need to pass --python.CAPI if you want to use the C extension modules.
[python::PythonContext] WARNING: could not determine Graal.Python's C API library path. You need to pass --python.CAPI if you want to use the C extension modules.
ERROR: java.lang.UnsupportedOperationException: Could not load posix support library from path '/lib/graalpy24.0/libposix.so'. Troubleshooting: 
Check permissions of the file.
Missing runtime Maven dependency 'org.graalvm.truffle:truffle-nfi-libffi' (should be a dependency of `org.graalvm.polyglot:python{-community}`)?
org.graalvm.polyglot.PolyglotException: java.lang.UnsupportedOperationException: Could not load posix support library from path '/lib/graalpy24.0/libposix.so'. Troubleshooting: 
Check permissions of the file.
Missing runtime Maven dependency 'org.graalvm.truffle:truffle-nfi-libffi' (should be a dependency of `org.graalvm.polyglot:python{-community}`)?
	at com.oracle.graal.python.runtime.NFIPosixSupport$InvokeNativeFunction.loadLibrary(NFIPosixSupport.java:394)
	at com.oracle.graal.python.runtime.NFIPosixSupport$InvokeNativeFunction.call(NFIPosixSupport.java:330)
	at com.oracle.graal.python.runtime.NFIPosixSupport$InvokeNativeFunction.callLong(NFIPosixSupport.java:345)
	at com.oracle.graal.python.runtime.NFIPosixSupport.lseek(NFIPosixSupport.java:653)
	at com.oracle.graal.python.runtime.NFIPosixSupportGen$PosixSupportLibraryExports$Uncached.lseek(NFIPosixSupportGen.java:6569)
	at com.oracle.graal.python.runtime.ImageBuildtimePosixSupport.lseek(ImageBuildtimePosixSupport.java:261)
	at com.oracle.graal.python.runtime.ImageBuildtimePosixSupportGen$PosixSupportLibraryExports$Uncached.lseek(ImageBuildtimePosixSupportGen.java:2575)
	at com.oracle.graal.python.runtime.PosixSupportLibraryGen$UncachedDispatch.lseek(PosixSupportLibraryGen.java:7580)
	at com.oracle.graal.python.builtins.modules.io.FileIOBuiltins$SeekNode.internalSeek(FileIOBuiltins.java:812)
	at com.oracle.graal.python.builtins.modules.io.FileIOBuiltins$TellNode.internalTell(FileIOBuiltins.java:837)
	at com.oracle.graal.python.builtins.modules.io.AbstractBufferedIOBuiltins$BufferedInitNode.internalInit(AbstractBufferedIOBuiltins.java:120)
	at com.oracle.graal.python.builtins.modules.io.BufferedReaderBuiltins$BufferedReaderInit.internalInit(BufferedReaderBuiltins.java:103)
	at com.oracle.graal.python.builtins.modules.SysModuleBuiltins.initStd(SysModuleBuiltins.java:726)
	at com.oracle.graal.python.builtins.modules.SysModuleBuiltins.postInitialize(SysModuleBuiltins.java:710)
	at com.oracle.graal.python.builtins.Python3Core.postInitialize(Python3Core.java:980)
	at com.oracle.graal.python.runtime.PythonContext.patch(PythonContext.java:1485)
	at com.oracle.graal.python.PythonLanguage.patchContext(PythonLanguage.java:420)
	at com.oracle.graal.python.PythonLanguage.patchContext(PythonLanguage.java:142)
	at org.graalvm.truffle/com.oracle.truffle.api.LanguageAccessor$LanguageImpl.patchEnvContext(LanguageAccessor.java:431)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotLanguageContext.patch(PolyglotLanguageContext.java:893)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.patch(PolyglotContextImpl.java:3490)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.loadPreinitializedContext(PolyglotEngineImpl.java:1929)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.createContext(PolyglotEngineImpl.java:1809)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineDispatch.createContext(PolyglotEngineDispatch.java:152)
	at org.graalvm.polyglot/org.graalvm.polyglot.Context$Builder.build(Context.java:1937)
	at com.oracle.graal.python.shell.GraalPythonMain.launch(GraalPythonMain.java:739)
	at com.oracle.graal.python.enterprise.shell.GraalPythonEnterpriseMain.launch(GraalPythonEnterpriseMain.java:53)
	at org.graalvm.launcher.AbstractLanguageLauncher.launch(AbstractLanguageLauncher.java:296)
	at org.graalvm.launcher.AbstractLanguageLauncher.launch(AbstractLanguageLauncher.java:121)
	at org.graalvm.launcher.AbstractLanguageLauncher.runLauncher(AbstractLanguageLauncher.java:168)
	Suppressed: Attached Guest Language Frames (0)
Internal GraalVM error, please report at https://github.com/oracle/graal/issues/.
[root@78fc86164bc0 /]# /opt/python/graalpy310-graalpy240_310_native/bin/python -m venv /tmp/venv-test-graalpy3.10
[root@78fc86164bc0 /]# /tmp/venv-test-graalpy3.10/bin/python -V
GraalPy 3.10.13 (Oracle GraalVM Native 24.0.2)
[root@78fc86164bc0 /]# cat /tmp/uv-test-graalpy3.10/pyvenv.cfg 
home = /opt/_internal/graalpy310-graalpy240_310_native/bin
implementation = GraalVM
uv = 0.2.27
version_info = 3.10.13
include-system-site-packages = false
[root@78fc86164bc0 /]# cat /tmp/venv-test-graalpy3.10/pyvenv.cfg 
home = /opt/_internal/graalpy310-graalpy240_310_native
include-system-site-packages = false
version = 3.10.13

Removing /bin in pyvenv.cfg works but seems like a workaround specific to GraalPy ?

@timfel
Copy link
Contributor Author

timfel commented Jul 20, 2024

@timfel, this does not seem to work:

Yeah, there's a workaround in the CI config I commented on above in this PR, the fix is in GraalPy master and will be in the next release in September. Until then we have to work around with either your suggestion or setting GRAAL_PYTHONHOME like I do in the CI here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants