Skip to content

Commit 00663c4

Browse files
committed
import updated docs from graalpy website
1 parent c38d190 commit 00663c4

18 files changed

+1457
-1158
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ GraalPy has first-class support for embedding in Java and can turn Python applic
1212
**Low-overhead integration with Java and other languages.**
1313

1414
* Use [Python in Java](docs/user/Interoperability.md) applications on GraalVM JDK, Oracle JDK, or OpenJDK
15-
* Use JVM tools like [Maven](docs/user/PythonStandaloneBinaries.md#embedding-graalpy-in-a-java-application), JFR, or [GraalVM Native Image](docs/user/PythonNativeimages.md)
16-
* Manage Python libraries' system access thanks to GraalPy's [Java-based emulation of Python OS APIs](docs/user/OsInterface.md#java-backend)
15+
* Use JVM tools like [Maven](docs/user/README.md), JFR, or [GraalVM Native Image](docs/user/Native-Images-with-Python.md)
16+
* Manage Python libraries' system access thanks to GraalPy's [Java-based emulation of Python OS APIs](docs/user/Embedding-Permissions.md)
1717

1818
**Compatible with the Python ecosystem**
1919

@@ -76,7 +76,7 @@ You can use `pip` to install packages as usual.
7676
Packages with C code usually do not provide binaries for GraalPy, so they will be automatically compiled during installation.
7777
This means that build tools have to be available and installation will take longer.
7878
We provide [Github actions](scripts/wheelbuilder) to help you build binary packages with the correct dependencies.
79-
Thanks to our integration with GraalVM Native Image, we can deploy Python applications as [standalone binary](docs/user/PythonStandaloneBinaries.md), all dependencies included.
79+
Thanks to our integration with GraalVM Native Image, we can deploy Python applications as [standalone binary](docs/user/Python-Standalone-Applications.md), all dependencies included.
8080

8181
* Linux
8282

@@ -143,7 +143,7 @@ The _setup-python_ action supports GraalPy:
143143

144144
Most existing Jython code that uses Java integration will be based on a stable Jython release—however, these are only available in Python 2.x versions.
145145
To migrate your code from Python 2 to Python 3, follow [the official guide from the Python community](https://docs.python.org/3/howto/pyporting.html).
146-
GraalPy also provides a [special mode](docs/user/Jython.md) to facilitate migration.
146+
GraalPy also provides a [special mode](docs/user/Python-on-JVM.md) to facilitate migration.
147147
To run Jython scripts, you need to use a GraalPy distribution running on the JVM so you can access Java classes from Python scripts.
148148

149149
* Linux

docs/user/Embedding-Permissions.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
layout: docs-experimental
3+
toc_group: python
4+
link_title: Embedding Permissions
5+
permalink: /reference-manual/python/Embedding-Permissions/
6+
redirect_from:
7+
- /reference-manual/python/OSInterface/
8+
---
9+
10+
# Permissions for Python Embeddings
11+
12+
## Access Control and Security Limits for Python Scripts
13+
14+
Embedding GraalPy into Java works with the [GraalVM Polyglot Sandbox](https://www.graalvm.org/latest/reference-manual/embed-languages/#controlling-access-to-host-functions).
15+
16+
## Python's POSIX Interface
17+
18+
The way the operating system interface is exposed to Python scripts is GraalPy-specific.
19+
By default all access is routed through Java interfaces, but some packages rely on details of POSIX APIs and require direct native access.
20+
21+
Graal languages (those implemented on the [Truffle framework](https://www.graalvm.org/latest/graalvm-as-a-platform/language-implementation-framework/)) usually implement system-related functions using the [Truffle abstraction layer](https://github.com/oracle/graal/blob/master/truffle/docs/README.md), which is OS independent and provides extension points for the users when embedding GraalPy or other Graal languages into Java applications.
22+
See, for example, the [Truffle FileSystem service-provider](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html).
23+
24+
The standard Python library also provides an OS abstraction, but exposes lower level interfaces. For example, the `os` module directly exposes some POSIX functions.
25+
On non-POSIX platforms, this interface is emulated to a degree.
26+
27+
GraalPy provides two alternative implementations (each referred to as a "backend") of system-related functionality offered by built-in Python modules such as `os`.
28+
The `PosixModuleBackend` option determines which backend is used: valid values are `native` and `java`.
29+
30+
### Native Backend
31+
32+
This backend directly calls the POSIX API in mostly the same way as CPython (the reference Python implementation).
33+
34+
This approach is the most compatible with CPython and provides bare access to the underlying OS interface without an intermediate emulation layer.
35+
36+
By default, this implementation bypasses the Truffle abstraction layer, and therefore it is not sandboxed and does not support custom implementations of [Truffle FileSystem service-provider](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html), and other Polyglot API providers related to system interfaces.
37+
38+
The native backend is chosen by default when GraalPy is started via the `graalpy` or any other Python related launcher.
39+
The exceptions are Python related launchers with `-managed` suffix available only in Oracle GraalVM (for example, `graalpy-managed`), which by default use the `java` POSIX backend.
40+
41+
#### Limitations of the Native Backend
42+
43+
Known limitations are:
44+
45+
* `os.fork` is not supported
46+
* `_posixsubprocess.fork_exec` does not support the `preexec_fn` parameter
47+
48+
### Java Backend
49+
50+
This backend uses the [Truffle abstraction layer](https://github.com/oracle/graal/blob/master/truffle/docs/README.md) and therefore supports custom Polyglot API providers related to system interfaces and sandboxing.
51+
Because this abstraction is POSIX agnostic, it does not expose all the necessary functionality. Some functionality is emulated, and some functionality is unsupported.
52+
53+
The Java backend is the default when GraalPy is run via the `Context` API, that is, [embedded in Java applications](https://github.com/oracle/graal/blob/master/docs/reference-manual/embedding/embed-languages.md), or when it is launched using Python-related launchers with the `-managed` suffix (available only in Oracle GraalVM).
54+
55+
#### Limitations of the Java Backend
56+
57+
GraalPy can log information about known incompatibility of functions executed at runtime, which includes the OS interface-related functions.
58+
To turn on this logging, use the command-line option `--log.python.compatibility.level=FINE` (or other desired logging level).
59+
60+
Known limitations of the of the Java backend are:
61+
62+
* Its state is disconnected from the actual OS state, which applies especially to:
63+
* *file descriptors*: Python-level file descriptors are not usable in native code.
64+
* *current working directory*: is initialized to the current working
65+
directory at the startup, but is then maintained separately. So, for example, `chdir` in Python
66+
does not change the actual current working directory of the process.
67+
* *umask*: has the same limitation as that of the current working directory, but it is always initialized
68+
to `0022` regardless of the actual system value at startup.
69+
* Resolution of file access/modification times depends on the JDK.
70+
The best the Java backend can guarantee is seconds resolution.
71+
* `os.access` and any other functionality based on `faccessat` POSIX function does not support:
72+
* effective IDs.
73+
* `follow_symlinks=False` unless the mode is only `F_OK`.
74+
75+
## Python Native Extensions
76+
77+
Python native extensions run by default as native binaries, with full access to the underlying system.

docs/user/FAQ.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)