| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
Contributions are more than welcome, and in many cases we are happy to guide contributors through PRs or on Discord.
We label issues that would be good for a first time contributor as good first issue. Also checkout the issue tracker for all open issues.
You can enhance CPython compatibility by increasing our unittest coverage, you can see This pinned issue to see which libs and tests need be updated to our current supported python version.
Another approach is to checkout the source code: builtin functions and object methods are often the simplest and easiest way to contribute.
You can also simply run python -I scripts/whats_left.py to assist in finding any unimplemented method.
We require all use of AI in contributions to follow our AI Policy.
If your contribution does not follow the policy, it will be closed.
RustPython attracts developers with interest and experience in Rust, Python, or WebAssembly. Whether you are familiar with Rust, Python, or WebAssembly, the goal of this Development Guide is to give you the basics to get set up for developing RustPython and contributing to this project.
The contents of the Development Guide include:
RustPython requires the following:
The Rust code style used is the default rustfmt codestyle. Please format your code accordingly, or run cargo fmt to autoformat it. We also use clippy to lint Rust code, which you can check yourself with cargo clippy.
Custom Python code (i.e. code not copied from CPython's standard library) should follow the PEP 8 style. We also use ruff to check Python code style.
In addition to language specific tools, cspell, a code spell checker, is used in order to ensure correct spellings for code.
To test RustPython's functionality, a collection of Python snippets is located in the extra_tests/snippets directory and can be run using pytest:
$ cd extra_tests
$ pytest -vRust unit tests can be run with cargo:
$ cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --exclude rustpython-capirustpython-capi needs to be tested from inside its own directory, since it has a separate cargo config that only applies there:
$ cd crates/capi
$ cargo testPython unit tests can be run by compiling RustPython and running the test module:
$ cargo run --release -- -m testThere are a few test options that are especially useful:
For example, to run all tests in parallel:
$ cargo run --release -- -m test -j 4To run only test_cmath (located at Lib/test/test_cmath) verbosely:
$ cargo run --release -- -m test test_cmath -vYou can test RustPython on Linux from macOS using Apple's container CLI.
Setup (one-time):
# Install container CLI
$ brew install container
# Disable Rosetta requirement for arm64-only builds
$ defaults write com.apple.container.defaults build.rosetta -bool false
# Build the development image
$ container build --arch arm64 -t rustpython-dev -f .devcontainer/Dockerfile .Running tests:
# Start a persistent container in background (8GB memory, 4 CPUs for compilation)
$ container run -d --name rustpython-test -m 8G -c 4 \
--mount type=bind,source=$(pwd),target=/workspace \
-w /workspace rustpython-dev sleep infinity
# Run tests inside the container
$ container exec rustpython-test sh -c "cargo run --release -- -m test test_ensurepip"
# Run any command
$ container exec rustpython-test sh -c "cargo test --workspace"
# Stop and remove the container when done
$ container rm -f rustpython-testTo profile RustPython, build it in release mode with the flame-it feature. This will generate a file flamescope.json, which can be viewed at https://speedscope.app.
$ cargo run --release --features flame-it script.py
$ cat flamescope.json
{<json>}You can specify another file name other than the default by using the --output-file option to specify a file name (or stdout if you specify -). The --output-format option determines the format of the output file. The speedscope json format (default), text, or raw html can be passed. There exists a raw html viewer which is currently broken, and we welcome a PR to fix it.
Understanding a new codebase takes time. Here's a brief view of the repository's structure:
The RustPython workspace includes the rustpython top-level crate. The Cargo.toml file in the root of the repo provide configuration of the crate and the implementation is found in the src directory (specifically, src/lib.rs).
The top-level rustpython binary depends on several lower-level crates including:
Together, these crates provide the functions of a programming language and enable a line of code to go through a series of steps:
RustPython uses the Ruff project's parser and AST implementation:
The rustpython-compiler crate's purpose is to transform the AST (Abstract Syntax Tree) to bytecode. The implementation of the compiler is found in the crates/compiler/src directory. The compiler implements Python's symbol table, ast->bytecode compiler, and bytecode optimizer in Rust.
Implementation of bytecode structure in Rust is found in the crates/compiler-core/src directory. crates/compiler-core/src/bytecode.rs contains the representation of instructions and operations in Rust. Further information about Python's bytecode instructions can be found in the Python documentation.
The rustpython-vm crate has the important job of running the virtual machine that executes Python's instructions. The crates/vm/src directory contains code to implement the read and evaluation loop that fetches and dispatches instructions. This directory also contains the implementation of the Python Standard Library modules in Rust (crates/vm/src/stdlib). In Python everything can be represented as an object. The crates/vm/src/builtins directory holds the Rust code used to represent different Python objects and their methods. The core implementation of what a Python object is can be found in crates/vm/src/object/core.rs.
There are some code generations involved in building RustPython:
Have you tried these steps and have a question, please chat with us on Discord.
| Back | FazBrowse Home | New Git URL |