### Silly Setup for Doctest
Source: https://github.com/oracle/graalpython/blob/master/graalpython/lib-python/3/test/test_doctest/test_doctest2.txt
Demonstrates a simple setup for doctests using a specific module and attribute. Ensure the module and attribute are accessible.
```python
>>> import test.test_doctest.test_doctest
>>> test.test_doctest.test_doctest.sillySetup
True
```
--------------------------------
### Install LZMASUPPORT Target
Source: https://github.com/oracle/graalpython/blob/master/graalpython/python-liblzma/CMakeLists.txt
Installs the LZMASUPPORT target to the 'bin' directory within the installation prefix. This makes the compiled LZMASUPPORT executable available after installation.
```cmake
install(TARGETS ${TARGET_LZMASUPPORT} DESTINATION bin)
```
--------------------------------
### Setting Installation Prefix
Source: https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python.cext/CMakeLists.txt
Configures the installation directory for the build artifacts to be within the project's binary directory.
```cmake
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
```
--------------------------------
### Test HPy Environment Setup
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/CONTRIBUTING.md
Run this command to build HPy and a proof-of-concept extension, then validate the setup with pytest. This is a good initial test for your environment.
```bash
proof-of-concept/test_pof.sh wheel universal
```
--------------------------------
### Pyflate Benchmark Setup
Source: https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python.benchmarks/python/micro/pyperformance/README.md
Sets up the Pyflate benchmark, defining run, warmup, iterations, summary, and dependencies.
```python
def run():
bench_pyflake(1, filename)
def warmupIterations():
return 0
def iterations():
return 10
def summary():
return {
"name": "OutlierRemovalAverageSummary",
"lower-threshold": 0.0,
"upper-threshold": 1.0,
}
def dependencies():
return ["data/interpreter.tar.bz2"]
```
--------------------------------
### Install GraalPython Target
Source: https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python.cext/CMakeLists.txt
Installs the built GraalPython library target to the 'bin' directory.
```cmake
install(TARGETS ${TARGET_LIBPYTHON} DESTINATION bin)
```
--------------------------------
### Build Linux/amd64 Wheels with Act
Source: https://github.com/oracle/graalpython/blob/master/scripts/wheelbuilder/README.md
Use the 'act' tool to build wheels for Linux/amd64. This command clones the repository, sets GraalPy version and Python version, installs 'act', configures input for the build, starts a Podman service, sets the Docker host, and then runs the build workflow.
```shell
git clone https://github.com/oracle/graalpython
cd graalpython
VERSION=25.1.0
PYTHON_VERSION=3.12
BINDIR=. curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/nektos/act/master/install.sh | bash
echo "graalpy_url=https://github.com/oracle/graalpython/releases/download/graal-$VERSION/graalpy$PYTHON_VERSION-$VERSION-linux-amd64.tar.gz" > .input
podman system service -t 0 unix:///tmp/podman.sock &
export DOCKER_HOST=unix:///tmp/podman.sock
./act --env http_proxy=$http_proxy --env https_proxy=$https_proxy -W .github/workflows/build-linux-amd64-wheels.yml --artifact-server-path=$(pwd)/artifacts
```
--------------------------------
### Install Python Packages with Pip
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Standalone-Getting-Started.md
Once a virtual environment is active, use pip to install packages. Supports individual packages or installation from a requirements file.
```bash
# Install a package
pip install requests
# Install with requirements file
pip install -r requirements.txt
```
--------------------------------
### GUI Test Class Setup
Source: https://github.com/oracle/graalpython/blob/master/graalpython/lib-python/3/idlelib/idle_test/README.txt
Implement setUpClass in a test class to acquire GUI resources. Ensure these resources are cleaned up in tearDownClass.
```python
@classmethod
def setUpClass(cls):
requires('gui')
cls.root = tk.Tk()
cls.text = tk.Text(root)
```
--------------------------------
### HPy Extension Setup Script
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/quickstart.rst
The setup.py script used to build the HPy extension. It specifies the HPy ABI.
```python
from setuptools import setup
setup(
name='quickstart',
ext_modules=[
{
'name': 'quickstart',
'sources': ['quickstart.c'],
'language': 'c',
},
],
include_package_data=True,
setup_requires=['hpy'],
)
```
--------------------------------
### Install GraalPy with pyenv
Source: https://github.com/oracle/graalpython/blob/master/docs/site/01-python-developers.md
Use pyenv to install the latest GraalPy release or development build. Set the shell to use the installed version.
```bash
pyenv install graalpy-{{ site.language_version }}
pyenv shell graalpy-{{ site.language_version }}
```
```bash
# On Windows (pyenv-win), provide platform-specific names
pyenv install graalpy-{{ site.language_version }}-windows-amd64
pyenv shell graalpy-{{ site.language_version }}-windows-amd64
```
```bash
# Latest development build of GraalPy
pyenv install graalpy-dev
pyenv shell graalpy-dev
```
--------------------------------
### Install and Run Python Applications with GraalPy
Source: https://github.com/oracle/graalpython/blob/master/docs/site/index.md
This snippet shows how to install GraalPy using pyenv, set it as the current shell, and run Python code. It also includes a performance benchmark.
```bash
$ pyenv install graalpy-{{ site.language_version }}
$ pyenv shell graalpy-{{ site.language_version }}
$ python3 -c "import sys; print(sys.implementation.name)"
graalpy
$ python3 -m timeit "'-'.join(str(n) for n in range(100))"
500000 loops, best of 5: 757 nsec per loop
```
--------------------------------
### Install HPy from Development Repository
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/quickstart.rst
Install HPy directly from its development repository using pip.
```console
python3 -m pip install git+https://github.com/hpyproject/hpy.git#egg=hpy
```
--------------------------------
### Install native build tools (Debian-based)
Source: https://github.com/oracle/graalpython/blob/master/docs/contributor/CONTRIBUTING.md
Install essential native build tools and libraries required for building GraalPy on Debian-based systems.
```shell
sudo apt install build-essential libc++-12-dev zlib1g-dev cmake
```
--------------------------------
### Create venv and Install HPy in Editable Mode
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/README-gdb.md
Steps to create a virtual environment using a debug CPython build and install HPy in editable mode for development.
```bash
cd /path/to/hpy
/opt/python-debug/bin/python3 -m venv venv/hpy-debug
. venv/hpy-debug/bin/activate
python setup.py develop
```
--------------------------------
### Install GraalPy with pyenv on Windows
Source: https://github.com/oracle/graalpython/blob/master/README.md
Install the GraalPy Windows distribution using pyenv. This command specifies the version and platform.
```bash
pyenv install graalpy-25.0.2-windows-amd64
```
--------------------------------
### CPU Tracer Output Example
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Tooling.md
Example output from the CPU tracer, showing a histogram of element executions, including total, interpreted, and compiled counts.
```bash
--------------------------------------------------------------------------------------------------------------------
Tracing Histogram. Counted a total of 1135 element executions.
Total Count: Number of times the element was executed and percentage of total executions.
Interpreted Count: Number of times the element was interpreted and percentage of total executions of this element.
Compiled Count: Number of times the compiled element was executed and percentage of total executions of this element.
--------------------------------------------------------------------------------------------------------------------
Name | Total Count | Interpreted Count | Compiled Count | Location
--------------------------------------------------------------------------------------------------------------------
get_newfunc_typeid | 110 9.7% | 110 100.0% | 0 0.0% | capi.c~596:0
PyTruffle_PopulateType | 110 9.7% | 110 100.0% | 0 0.0% | capi.c~721:0
PyTruffle_AllocMemory | 86 7.6% | 86 100.0% | 0 0.0% | obmalloc.c~77:0
PyTruffle_AllocateType | 66 5.8% | 66 100.0% | 0 0.0% | capi.c~874:0
PyMem_RawMalloc | 66 5.8% | 66 100.0% | 0 0.0% | obmalloc.c~170:0
initialize_type_structure | 50 4.4% | 50 100.0% | 0 0.0% | capi.c~181:0
_Py_TYPE | 45 4.0% | 45 100.0% | 0 0.0% | object_shared.c~55:0
PyType_GetFlags | 41 3.6% | 41 100.0% | 0 0.0% | typeobject_shared.c~44:0
get_tp_name | 37 3.3% | 37 100.0% | 0 0.0% | capi.c~507:0
...
--------------------------------------------------------------------------------------------------------------------
```
--------------------------------
### Memory Tracer Output Example
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Tooling.md
Example output from the Memory tracer, showing a location histogram with allocation counts, including self and total counts.
```bash
----------------------------------------------------------------------------
Location Histogram with Allocation Counts. Recorded a total of 565 allocations.
Total Count: Number of allocations during the execution of this element.
Self Count: Number of allocations in this element alone (excluding sub calls).
----------------------------------------------------------------------------
Name | Self Count | Total Count | Location
----------------------------------------------------------------------------
PyTruffle_PopulateType | 440 77.9% | 440 77.9% | capi.c~721:0
PyType_Ready | 61 10.8% | 68 12.0% | typeobject.c~463:0
_PyObject_MakeTpCall | 20 3.5% | 24 4.2% | object.c~155:0
PyUnicode_FromString | 11 1.9% | 11 1.9% | capi.c~2161:0
PyErr_NewException | 11 1.9% | 11 1.9% | capi.c~1537:0
_PyUnicode_AsASCIIString | 6 1.1% | 6 1.1% | capi.c~2281:0
PyDict_New | 4 0.7% | 4 0.7% | capi.c~1505:0
PyTuple_New | 4 0.7% | 4 0.7% | capi.c~2097:0
PyUnicode_FromStringAndSize | 3 0.5% | 3 0.5% | unicodeobject.c~171:0
...
----------------------------------------------------------------------------
```
--------------------------------
### Install Test Requirements and Dump Sources
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/api.rst
Install necessary test requirements and dump the generated test sources from the HPy repository.
```console
> cd hpy
> python3 -m pip install pytest filelock
> python3 -m pytest --dump-dir=test_sources test/
```
--------------------------------
### GraalPy Maven Plugin Configuration Example
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Embedding-Build-Tools.md
Configure the GraalPy Maven Plugin in your pom.xml. This example shows how to specify Python packages and choose a deployment approach (Virtual Filesystem or External Directory).
```xml
org.graalvm.python
graalpy-maven-plugin
termcolor==2.2
GRAALPY-VFS/${project.groupId}/${project.artifactId}
${basedir}/python-resources
```
--------------------------------
### Create a List using CPython API
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/porting-guide.rst
Example of creating a list with a fixed size using the CPython PyList_New and PyList_SET_ITEM functions.
```c
PyObject *list = PyList_New(5);
if (list == NULL)
return NULL; /* error */
PyList_SET_ITEM(list, 0, item0);
PyList_SET_ITEM(list, 1, item0);
...
PyList_SET_ITEM(list, 4, item0);
/* now 'list' is ready to use */
```
--------------------------------
### Run a Specific Benchmark
Source: https://github.com/oracle/graalpython/blob/master/docs/contributor/CONTRIBUTING.md
Execute a single benchmark, for example, 'nbody3' from the 'meso' suite.
```bash
mx benchmark meso:nbody3
```
--------------------------------
### Build HPy extension with setup.py
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/api.rst
Example setup.py script for building an HPy extension module. Demonstrates building for CPython ABI and HPy Universal ABI using the --hpy-abi=universal option.
```python
from setuptools import setup, Extension
module = Extension("simple", sources=["simple.c"])
setup(
name="simple",
ext_modules=[
module,
],
)
```
--------------------------------
### Using py-dump for PyObject* Inspection
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/README-gdb.md
Example of using the custom 'py-dump' GDB command to get detailed information about a PyObject*.
```gdb
(gdb) set $x = PyLong_FromLong(42)
(gdb) py-dump $x
object address : 0x555555903ca0
object refcount : 11
object type : 0x5555558d5560
object type name: int
object repr : 42
(gdb) py-dump PyExc_ValueError
object address : 0x5555558ce880
object refcount : 14
object type : 0x5555558dd8e0
object type name: type
object repr :
```
--------------------------------
### Legacy Module Initialization (CPython API)
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/porting-guide.rst
Demonstrates the traditional single-phase module initialization pattern using the CPython API.
```c
// BEGIN
// This is a placeholder for the actual legacy CPython module initialization code.
// The original source uses .. literalinclude:: to point to a file.
// END
```
--------------------------------
### Installing JavaScript Language via GraalPy Script
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Interoperability.md
Execute this bash command from your GraalPy installation directory to install the JavaScript language.
```bash
libexec/graalpy-polyglot-get js
```
--------------------------------
### Build HPy Extension
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/quickstart.rst
Build the HPy extension using the setup.py script with the universal HPy ABI.
```console
python3 setup.py --hpy-abi=universal develop
```
--------------------------------
### Go Benchmark Configuration
Source: https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python.benchmarks/python/micro/pyperformance/README.md
Sets up the Go benchmark for execution, defining the `run` function and parameters for warmup, iterations, and summary. It includes conditional warmup adjustments for PyPy's JIT.
```python
def run():
versus_cpu()
def warmupIterations():
return 0
def iterations():
return 10
def summary():
return {
"name": "OutlierRemovalAverageSummary",
"lower-threshold": 0.0,
"upper-threshold": 1.0,
}
```
--------------------------------
### Install HPy
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/microbench/README.md
Installs HPy in development mode within your virtual environment.
```bash
cd /path/to/hpy
python setup.py develop
```
--------------------------------
### Initialize IDE Settings
Source: https://github.com/oracle/graalpython/blob/master/docs/contributor/GETTING_STARTED.md
Optional command to initialize IDE-specific settings after setting up your environment.
```bash
mx ideinit
```
--------------------------------
### Install HPy using pip
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/quickstart.rst
Install the latest stable release of HPy using pip.
```console
python3 -m pip install hpy
```
--------------------------------
### Regex DNA Benchmark Setup
Source: https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python.benchmarks/python/micro/pyperformance/README.md
Initializes the regex DNA benchmark, setting up argument parsing and defining the run, warmup, iterations, and summary functions.
```python
def run():
cmd = argparse.ArgumentParser(prog="python")
args = cmd.parse_args()
bench_regex_dna(1, seq, expected_res)
def warmupIterations():
return 0
def iterations():
return 10
def summary():
return {
"name": "OutlierRemovalAverageSummary",
"lower-threshold": 0.0,
"upper-threshold": 1.0,
}
```
--------------------------------
### Install Coverage Package
Source: https://github.com/oracle/graalpython/blob/master/graalpython/lib-python/3/idlelib/idle_test/README.txt
Install the coverage package using pip, required for test coverage analysis.
```bash
python3 -m pip install coverage
```
--------------------------------
### Initialize Java Application with Gradle
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Embedding-Getting-Started.md
Use this command to create a new Java application project structure managed by Gradle. It sets up the project name, package, and avoids splitting the project into multiple modules.
```bash
gradle init --type java-application \
--project-name interop \
--package interop \
--no-split-project
```
--------------------------------
### Prepare Revisions for Benchmarking Standalones
Source: https://github.com/oracle/graalpython/blob/master/AGENTS.md
Commands to set up the correct project revisions for building benchmarking standalones. This involves importing specific suites and checking out downstream projects.
```bash
mx --env native-ee sforceimports && mx --env native-ee checkout-downstream compiler graal-enterprise
```
--------------------------------
### Spectral Norm Benchmark Setup
Source: https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python.benchmarks/python/micro/pyperformance/README.md
Sets up the spectral_norm benchmark, defining run, warmup, and iteration counts, along with summary statistics. It imports the pyperf library.
```python
import pyperf
def run():
bench_spectral_norm(1)
def warmupIterations():
return 0
def iterations():
return 10
def summary():
return {
"name": "OutlierRemovalAverageSummary",
"lower-threshold": 0.0,
"upper-threshold": 1.0,
}
```
--------------------------------
### HPy Meth Keywords Example
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/leysin-2020-design-decisions.md
Example of defining a function with HPy_METH_KEYWORDS, showing how to silence potential warnings by casting to HPyMeth.
```C
{"add_ints_kw", (HPyMeth) add_ints_kw, HPy_METH_KEYWORDS, ""}
```
--------------------------------
### Initialize Compatibility Database
Source: https://github.com/oracle/graalpython/blob/master/docs/site/03-python-developers-compatibility.md
Sets up global constants and variables for the compatibility checking script, including default versions and display options.
```javascript
DB.ANY_VERSION = "any";
DB.INSTALLS_BUT_FAILS_TESTS = "The package installs, but the test suite was not set up for GraalPy.";
DB.FAILS_TO_INSTALL = "We have been unable to build, install, or run tests for this package.";
DB.UNSUPPORTED = "The package is unsupported.";
DB.PERCENT_PASSING = (pct) => `${pct}% of the tests are passing on GraalPy.`;
const PATCH_AVAILABLE = "GraalPy will automatically apply a patch when installing this package to improve compatibility.";
const LOWER_PRIORITY = "This version works, but there is no reason to prefer it over more recent versions.";
const BUILD_SCRIPT_AVAILABLE = (url) => `If you have trouble building this package, there is a script.`;
const default_version = 'v250';
const show_percentages = true;
const dbs = {};
var module_query = '';
```
--------------------------------
### Unpack Sequence Benchmark Setup
Source: https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python.benchmarks/python/micro/pyperformance/README.md
Sets up the unpack_sequence benchmark using argparse for command-line arguments. It defines the run function, warmup and iteration counts, and summary statistics.
```python
import argparse
def run():
parser = argparse.ArgumentParser(prog="python")
parser.add_argument("benchmark", nargs="?",
options = parser.parse_args()
func(8192)
def warmupIterations():
return 0
def iterations():
return 10
def summary():
return {
"name": "OutlierRemovalAverageSummary",
"lower-threshold": 0.0,
"upper-threshold": 1.0,
}
```
--------------------------------
### Install GraalPy with pyenv on Linux/macOS
Source: https://github.com/oracle/graalpython/blob/master/README.md
Quickly install and set the GraalPy version for your current shell session on Linux or macOS using pyenv.
```bash
pyenv install graalpy-25.0.2 && pyenv shell graalpy-25.0.2
```
--------------------------------
### List Available Python Benchmark Suites
Source: https://github.com/oracle/graalpython/blob/master/docs/contributor/CONTRIBUTING.md
Use this command to see all available Python benchmark suites and VM configurations.
```bash
mx benchmark --list
```
--------------------------------
### Update Pyenv and Install GraalPy on Linux
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Standalone-Getting-Started.md
Use Pyenv to update to the latest GraalPy versions and install a specific version. This is the recommended method for Linux.
```bash
pyenv update
pyenv install graalpy-25.0.3
pyenv shell graalpy-25.0.3
```
--------------------------------
### Build Project
Source: https://github.com/oracle/graalpython/blob/master/AGENTS.md
Command to build the GraalPython project.
```bash
mx python-jvm
```
--------------------------------
### Setting up Java Environment and Exposing Object to Python
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Interoperability.md
This snippet demonstrates how to create a Java object and make it available to a Python context within GraalPy.
```java
import org.example.MyJavaClass;
import org.graalvm.python.embedding.GraalPyResources;
class Main {
public static void main(String[] args) {
MyJavaClass myJavaObject = new MyJavaClass(42, 17);
try (var context = GraalPyResources.createContext()) {
// myJavaObject will be globally available in example.py as my_java_object
context.getBindings("python").putMember("my_java_object", myJavaObject);
context.eval(Source.newBuilder("python", "example.py"));
}
}
}
```
--------------------------------
### Multi-phase Module Initialization (HPy API)
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/porting-guide.rst
Shows the equivalent module initialization using HPy's multi-phase initialization, which is required for HPy modules.
```c
// BEGIN
// This is a placeholder for the actual HPy multi-phase module initialization code.
// The original source uses .. literalinclude:: to point to a file.
// END
```
--------------------------------
### Install and Use GraalPy with Pyenv on macOS
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Standalone-Getting-Started.md
Install GraalPy using Pyenv and set it as the active version for the current shell session. This is the recommended approach for macOS.
```bash
pyenv install graalpy-25.0.3
pyenv shell graalpy-25.0.3
```
--------------------------------
### Create GraalPy Context with Default VFS
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Embedding-Build-Tools.md
Creates a GraalPy context with the default Virtual Filesystem configuration. Use this for a quick setup where default VFS behavior is sufficient.
```java
Context context = GraalPyResources.createContext();
```
--------------------------------
### Install GraalPy with uv
Source: https://github.com/oracle/graalpython/blob/master/docs/site/01-python-developers.md
Install GraalPy using the uv package manager, which automatically selects the correct version. You can also create virtual environments with GraalPy.
```bash
# Install GraalPy with uv (uv selects GraalPy by Python language version)
uv python install graalpy-3.12
# Create a virtual environment with GraalPy
uv venv --python graalpy-3.12
```
--------------------------------
### C API Example for GraalPython
Source: https://github.com/oracle/graalpython/blob/master/graalpython/hpy/docs/porting-example/steps/step_00_c_api.rst
This C code snippet shows how to initialize the GraalPython interpreter, create a Python string, and execute it. It requires the GraalPython C API headers.
```c
#include
int main(int argc, char **argv) {
Py_Initialize();
PyObject *pName, *pModule, *pFunc, *pArgs, *pValue;
pName = PyUnicode_FromString("hello");
if (!pName) {
fprintf(stderr, "Failed to create Python string\n");
return 1;
}
/* Example of calling a function from a module */
pModule = PyImport_Import(pName);
if (!pModule) {
fprintf(stderr, "Failed to load module\n");
Py_DECREF(pName);
return 1;
}
pFunc = PyObject_GetAttrString(pModule, "hello");
if (!pFunc || !PyCallable_Check(pFunc)) {
if (PyErr_Occurred()) PyErr_Print();
fprintf(stderr, "Cannot find function \"hello\"\n");
Py_XDECREF(pFunc);
Py_DECREF(pModule);
Py_DECREF(pName);
return 1;
}
pArgs = PyTuple_New(1);
pValue = PyLong_FromLong(10);
if (!pValue) {
Py_DECREF(pArgs);
fprintf(stderr, "Cannot convert argument\n");
return 1;
}
PyTuple_SetItem(pArgs, 0, pValue); /* pValue stolen here */
pValue = PyObject_CallObject(pFunc, pArgs);
Py_DECREF(pArgs);
if (pValue != NULL) {
printf("Result of call: %ld\n", PyLong_AsLong(pValue));
Py_DECREF(pValue);
} else {
PyErr_Print();
fprintf(stderr, "Call failed\n");
return 1;
}
Py_DECREF(pFunc);
Py_DECREF(pModule);
Py_DECREF(pName);
Py_Finalize();
return 0;
}
```
--------------------------------
### GraalPy Coverage Output Example
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Tooling.md
This is an example of the output generated when the Coverage.py tool is enabled with GraalPy. It displays a histogram showing the percentage of code covered for various elements.
```bash
------------------------------------------------------------------------------------------------------------------------------------------------
Code coverage histogram.
Shows what percent of each element was covered during execution
------------------------------------------------------------------------------------------------------------------------------------------------
Path | Statements | Lines | Roots
------------------------------------------------------------------------------------------------------------------------------------------------
/lib/python3.10/site-packages/_distutils_hack/__init__.py | 0.00% | 0.00% | 0.00%
/lib/python3.10/site-packages/bs4/__init__.py | 56.10% | 56.14% | 55.26%
/lib/python3.10/site-packages/bs4/builder/__init__.py | 79.12% | 78.84% | 50.00%
/lib/python3.10/site-packages/bs4/builder/_html5lib.py | 2.41% | 2.46% | 2.38%
/lib/python3.10/site-packages/bs4/builder/_htmlparser.py | 69.08% | 68.67% | 83.33%
/lib/python3.10/site-packages/bs4/builder/_lxml.py | 3.72% | 3.78% | 4.00%
/lib/python3.10/site-packages/bs4/css.py | 32.73% | 31.48% | 15.38%
/lib/python3.10/site-packages/bs4/dammit.py | 65.46% | 65.29% | 24.14%
/lib/python3.10/site-packages/bs4/element.py | 44.15% | 43.13% | 31.08%
/lib/python3.10/site-packages/bs4/formatter.py | 73.49% | 74.36% | 66.67%
/lib/python3.10/site-packages/certifi/__init__.py | 100.00% | 100.00% | 100.00%
/lib/python3.10/site-packages/certifi/core.py | 33.33% | 33.33% | 25.00%
/lib/python3.10/site-packages/charset_normalizer/__init__.py | 100.00% | 100.00% | 100.00%
/lib/python3.10/site-packages/charset_normalizer/api.py | 11.87% | 11.94% | 16.67%
/lib/python3.10/site-packages/charset_normalizer/assets/__init__.py | 100.00% | 100.00% | 100.00%
/lib/python3.10/site-packages/charset_normalizer/cd.py | 12.81% | 13.54% | 4.35%
/lib/python3.10/site-packages/charset_normalizer/constant.py | 100.00% | 100.00% | 100.00%
/lib/python3.10/site-packages/charset_normalizer/legacy.py | 25.00% | 25.00% | 50.00%
/lib/python3.10/site-packages/charset_normalizer/md.py | 22.05% | 20.37% | 17.24%
/lib/python3.10/site-packages/charset_normalizer/models.py | 38.46% | 38.50% | 9.30%
/lib/python3.10/site-packages/charset_normalizer/utils.py | 26.79% | 26.89% | 3.33%
/lib/python3.10/site-packages/charset_normalizer/version.py | 100.00% | 100.00% | 100.00%
/lib/python3.10/site-packages/idna/__init__.py | 100.00% | 100.00% | 100.00%
/lib/python3.10/collections/abc.py | 100.00% | 100.00% | 100.00%
/lib/python3.10/contextlib.py | 40.80% | 37.99% | 31.71%
/lib/python3.10/copy.py | 36.36% | 36.41% | 21.43%
/lib/python3.10/copyreg.py | 3.20% | 3.20% | 7.69%
/lib/python3.10/csv.py | 25.17% | 23.91% | 25.00%
/lib/python3.10/datetime.py | 30.32% | 30.01% | 14.74%
/lib/python3.10/email/__init__.py | 42.86% | 42.86% | 20.00%
/lib/python3.10/email/_encoded_words.py | 35.11% | 34.44% | 14.29%
/lib/python3.10/email/_parseaddr.py | 12.64% | 12.15% | 10.71%
/lib/python3.10/email/_policybase.py | 55.22% | 54.69% | 39.29%
```
--------------------------------
### CPU Sampler Output Example
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Tooling.md
This is an example of the output generated by the CPU sampler. It details time spent in different functions, distinguishing between self time and total time on the stack.
```bash
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Sampling Histogram. Recorded 564 samples with period 10ms. Missed 235 samples.
Self Time: Time spent on the top of the stack.
Total Time: Time spent somewhere on the stack.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Thread[main,5,main]
Name || Total Time || Self Time || Location
--------------------------------------------------------------------------------------------------------------------------------------------------------------
parse_starttag || 1090ms 19.3% || 570ms 10.1% || /lib/python3.10/html/parser.py~300-347:11658-13539
match || 190ms 3.4% || 190ms 3.4% || /lib/python3.10/site-packages/soupsieve/css_parser.py~320-323:9862-10026
_replace_cdata_list_attribute_values || 190ms 3.4% || 190ms 3.4% || /lib/python3.10/site-packages/bs4/builder/__init__.py~295-331:11245-13031
goahead || 1430ms 25.4% || 150ms 2.7% || /lib/python3.10/html/parser.py~133-250:4711-9678
check_for_whole_start_tag || 130ms 2.3% || 130ms 2.3% || /lib/python3.10/html/parser.py~351-382:13647-14758
|| 800ms 14.2% || 130ms 2.3% || /lib/python3.10/site-packages/soupsieve/css_parser.py~1-1296:0-47061
...
--------------------------------------------------------------------------------------------------------------------------------------------------------------
```
--------------------------------
### Create GraalPy Context Builder with Custom VFS
Source: https://github.com/oracle/graalpython/blob/master/docs/user/Embedding-Build-Tools.md
Returns a context builder pre-configured with a custom Virtual Filesystem. Use this when you need to define a specific VFS setup.
```java
Context context = GraalPyResources.contextBuilder(customVfs).build();
```
--------------------------------
### Fetch JDK for Standalone Builds
Source: https://github.com/oracle/graalpython/blob/master/AGENTS.md
Command to fetch a specific JDK version required for building standalones. Ensure JAVA_HOME is set according to the output.
```bash
mx -p ../graal/vm fetch-jdk -jdk-id labsjdk-ce-latest
```