Skip to content

Commit 272d1f9

Browse files
committed
apply textual suggestions to standalone module documentation
1 parent f2aad82 commit 272d1f9

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

docs/user/PythonStandaloneBinaries.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,54 @@ permalink: /reference-manual/python/standalone-binaries/
66
---
77
# Standalone Applications with Python
88

9-
It can be desirable to distribute Python applications or libraries as standalone binaries or JAR files without any external dependencies.
10-
The Truffle framework that GraalPy is built on and the Sulong LLVM runtime that GraalPy can leverage for managed execution of Python's native extensions allow us to completely virtualize all filesystem accesses of Python programs, including those to the standard library and installed packages.
9+
With GraalVM Python implementation (GraalPy), you can distribute Python applications or libraries as standalone binaries or JAR files without any external dependencies.
10+
The [Truffle framework](https://github.com/oracle/graal/tree/master/truffle) that GraalPy is built on, and the [Sulong LLVM runtime](https://github.com/oracle/graal/tree/master/sulong) that GraalPy leverages for managed execution of Python's native extensions enables users to completely virtualize all filesystem accesses of Python programs, including those to the standard library and installed packages.
1111

1212
GraalPy comes with a module that can create standalone binaries or Java project skeletons.
13-
The binaries simply bundle everything into one native image.
13+
The binaries bundle everything into one native executable.
1414
The Java skeletons are set up with Maven to build and run self-contained JAR files.
15-
They can also be used to generate a standalone binaries from those JARs later, so the Java skeletons offer more flexibility and control over the steps.
15+
They can also be used to generate a standalone binary from those JARs later, so Java skeletons offer more flexibility and control over the steps.
16+
17+
### Prerequisite
18+
19+
Set `JAVA_HOME` to use a GraalVM distribution.
1620

1721
## Creating GraalPy Binaries
1822

19-
Suppose we have a simple Python script `my_script.py` that does some useful work when run directly.
20-
If we wanted to distribute it as a standalone native image, we run the following command:
23+
Suppose there is a simple Python script, `my_script.py`, that does some useful work when run directly.
24+
To distribute it as a standalone native binary, run the following command:
2125

2226
```
23-
$ graalpy -m standalone binary --module my_script.py --output my_binary
27+
graalpy -m standalone binary --module my_script.py --output my_binary
2428
```
2529

26-
This will generate a standalone `my_binary` file which includes the Python code, the GraalPy runtime, and the Python standard library in a single, self-contained executable.
30+
It generates a standalone `my_binary` file which includes the Python code, the GraalPy runtime, and the Python standard library in a single, self-contained executable.
2731
Use `graalpy -m standalone binary --help` for further options.
2832

29-
## Embedding GraalPy in Java Applications
33+
## Embedding GraalPy in a Java Application
3034

31-
Suppose now we wanted to distribute our `my_script.py` script as a JAR that can run on any GraalVM that includes GraalPy.
32-
To prepare such a Java project, the `standalone` GraalPy tool has another command:
35+
You can distribute the Python script as a JAR file that runs on GraalVM and includes GraalPy.
36+
To achieve this, run the `java` subcommand of GraalPy's `standalone` module:
3337

3438
```
35-
$ graalpy -m standalone java --output-directory MyJavaApplication --module my_script
39+
graalpy -m standalone java --output-directory MyJavaApplication --module my_script.py
3640
```
3741

38-
The target folder `MyJavaApplication` includes a `pom.xml` that makes it easy to generate a JAR or a GraalVM native image with Maven.
42+
It creates a Java project _MyJavaApplication_. It includes a `pom.xml` that makes it easy to generate a JAR or a GraalVM native executable with Maven.
3943
You can open this Maven project with any Java IDE and edit the main class that was created to modify the Python embedding.
40-
To build, you can use either `mvn -Pjar package` to create a JAR, or `mvn -Pnative package` to create a GraalVM native image.
41-
For both, make sure to set your `JAVA_HOME` to use a GraalVM distribution.
44+
To build the application, either `mvn -Pjar package` to create a JAR file, or `mvn -Pnative package` to create a GraalVM native executable.
4245

4346
Take a look at the generated `pom.xml`.
4447
There are some options to tweak the performance and footprint trade-off.
45-
Review also our general documentation on Python native images to find out how to remove other unwanted components and further reduce the binary size.
48+
Review the [Python Native Images documentation](PythonNativeImages.md) to find out how to remove other unwanted components and further reduce the binary size.
4649

4750
The generated project should be viewed as a starting point.
4851
It includes the entire Python standard library, so the Python code can invoke all of the standard library code.
4952
The resources can be manually pruned to reduce the included Python libraries to the necessary amount, reducing both the size of the package and the time to start up.
50-
The Java code demonstrates some useful default options for the Python context, but other settings may be desirable to further control what the Python code is allowed to do.
53+
This Java example demonstrates some useful default options for the Python context, but other settings may be desirable to further control what the Python code is allowed to do.
5154

52-
## Security considerations
55+
## Security Considerations
5356

54-
Creating a native image or a JAR that includes the Python code could be seen as a mild form of obfuscation, but it does not protect your source code.
57+
Creating a native executable or a JAR that includes the Python code could be seen as a mild form of obfuscation, but it does not protect your source code.
5558
While the Python sources are not stored verbatim into the image (only the GraalPy bytecode is), that bytecode is easy to convert back into Python sources.
56-
If stronger protection for the included Python source code is required, this needs to be handled by a means of e.g. encryption of the resources before building the native image, and adding approproate decryption into the generated virtual file system.
59+
If stronger protection for the included Python source code is required, consider, for example, encryption of the resources before building the native executable, and adding appropriate decryption into the generated virtual file system.

graalpython/lib-graalpython/modules/standalone/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@
128128
<buildArg>-H:-CopyLanguageResources</buildArg>
129129
<buildArg>--initialize-at-build-time=Py2BinLauncher$JarFileSystem</buildArg>
130130
</buildArgs>
131-
<!-- Remove the properties below to include the Python JIT compier -->
131+
<!-- Remove the properties below to include the Python JIT compiler -->
132132
<jvmArgs>
133133
<arg>-Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime</arg>
134134
<arg>-Dpolyglot.engine.WarnInterpreterOnly=false</arg>
135135
</jvmArgs>
136136
<!-- Flip the property below for verbose or quiet image build -->
137137
<verbose>true</verbose>
138-
<!-- Flip the property below to include debug symbols for the image -->
138+
<!-- Flip the property below to include debug symbols in the native executable -->
139139
<debug>false</debug>
140140
</configuration>
141141
</plugin>

0 commit comments

Comments
 (0)