Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.dict/python-more.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dllhandle
docstring
docstrings
dunder
dunders
endianness
endpos
eventmask
Expand Down
2 changes: 2 additions & 0 deletions .cspell.dict/rust-more.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ trai
ulonglong
unic
unistd
ungil
unraw
unsendable
unsync
wasip1
wasip2
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,97 @@

- name: cargo doc
run: cargo doc --locked

pyo3:
# Skip the build when rust sources did not change.
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
needs:
- determine_changes
env:
RUST_BACKTRACE: full
RUN_PYO3: ${{ needs.determine_changes.outputs.rust_code == 'true' || github.ref == 'refs/heads/main' }}
name: Run pyo3 tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 60
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-2025]
fail-fast: false
steps:
- name: Skip pyo3 tests when sources did not change
if: env.RUN_PYO3 != 'true'
run: echo "No rust source changes; required check is green without rebuilding."

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
if: env.RUN_PYO3 == 'true'
with:
persist-credentials: false

- uses: dtolnay/rust-toolchain@stable
if: env.RUN_PYO3 == 'true'

- name: Use a short Cargo home on Windows
if: env.RUN_PYO3 == 'true' && runner.os == 'Windows'
shell: pwsh
run: |
"CARGO_HOME=$env:RUNNER_TEMP\c" >> $env:GITHUB_ENV
git config --global core.longpaths true

- name: Restore cache
if: env.RUN_PYO3 == 'true'
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
${{ runner.temp }}/c/registry/index/
${{ runner.temp }}/c/registry/cache/
${{ runner.temp }}/c/git/db/
target/
key: ${{ runner.os }}-${{ hashFiles('**/Cargo.toml') }}-
restore-keys: |
${{ runner.os }}-stable--${{ hashFiles('**/Cargo.toml') }}-
${{ runner.os }}-stable--
# Windows runners randomly crashes, https://github.com/actions/cache/issues/1754
continue-on-error: true

- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
if: env.RUN_PYO3 == 'true'
id: python
with:
python-version: "3.14"

- name: Install macOS dependencies
if: env.RUN_PYO3 == 'true'
uses: ./.github/actions/install-macos-deps

- name: build rustpython
if: env.RUN_PYO3 == 'true'
run: cargo build --locked --release --verbose --features=threading,pyo3 ${{ env.CARGO_ARGS }}
env:
PYO3_PYTHON: ${{ steps.python.outputs.python-path }}

# Shared libpython is not on the default Linux loader path. Windows
# finds python3xx.dll via PATH; the macOS framework install name is absolute.
- name: Locate libpython
id: libpython
if: env.RUN_PYO3 == 'true' && runner.os == 'Linux'
shell: bash
env:
PYO3_PYTHON: ${{ steps.python.outputs.python-path }}
run: |
libdir="$("$PYO3_PYTHON" -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")"
echo "libdir=${libdir}" >> "$GITHUB_OUTPUT"

- name: Run pyo3 tests
if: env.RUN_PYO3 == 'true'
shell: bash
env:
LIBDIR: ${{ steps.libpython.outputs.libdir }}
run: |
if [ -n "$LIBDIR" ]; then
export LD_LIBRARY_PATH="${LIBDIR}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
fi
target/release/rustpython crates/module_pyo3/tests/test_module_pyo3.py
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license.workspace = true
[features]
capi = ["dep:rustpython-capi", "threading"]
default = ["threading", "stdlib", "stdio", "importlib", "ssl-rustls-aws-lc", "host_env", "mimalloc", "doc", "ucd_3_2_0"]
doc = ["rustpython-vm/doc", "rustpython-stdlib?/doc"]
doc = ["rustpython-vm/doc", "rustpython-stdlib?/doc", "rustpython-module_pyo3?/doc"]
mimalloc = ["dep:mimalloc"]
host_env = ["rustpython-vm/host_env", "rustpython-stdlib?/host_env"]
importlib = ["rustpython-vm/importlib"]
Expand All @@ -23,7 +23,11 @@ flame-it = ["rustpython-vm/flame-it", "rustpython-stdlib/flame-it", "flame", "fl
freeze-stdlib = ["stdlib", "rustpython-vm/freeze-stdlib", "rustpython-pylib?/freeze-stdlib"]
jit = ["rustpython-vm/jit"]
opcode-histogram = ["rustpython-vm/opcode-histogram"]
threading = ["rustpython-vm/threading", "rustpython-stdlib/threading"]
threading = [
"rustpython-vm/threading",
"rustpython-stdlib/threading",
"rustpython-module_pyo3?/threading",
]
sqlite = ["rustpython-stdlib/sqlite"]
ssl = ["host_env", "rustpython-stdlib?/ssl"]
ssl-rustls = ["ssl", "rustpython-stdlib/ssl-rustls"]
Expand All @@ -33,6 +37,7 @@ ssl-openssl = ["ssl", "rustpython-stdlib/ssl-openssl"]
ssl-openssl-vendor = ["ssl-openssl", "rustpython-stdlib/ssl-openssl-vendor"]
tkinter = ["rustpython-stdlib/tkinter"]
ucd_3_2_0 = ["rustpython-stdlib?/ucd_3_2_0"]
pyo3 = ["dep:rustpython-module_pyo3"]

[build-dependencies]
winresource = "0.1"
Expand All @@ -42,6 +47,7 @@ rustpython-capi = { workspace = true, optional = true }
rustpython-pylib = { workspace = true, optional = true }
rustpython-stdlib = { workspace = true, optional = true, default-features = false, features = ["compiler"] }
rustpython-vm = { workspace = true, features = ["compiler", "gc"] }
rustpython-module_pyo3 = { workspace = true, optional = true }

log = { workspace = true }
flame = { workspace = true, optional = true }
Expand Down Expand Up @@ -200,6 +206,7 @@ rustpython-sre_engine = { path = "crates/sre_engine", version = "0.6.1" }
rustpython-unicode = { path = "crates/unicode", default-features = false, version = "0.6.1" }
rustpython-wtf8 = { path = "crates/wtf8", version = "0.6.1" }
rustpython-doc = { path = "crates/doc", version = "0.6.1" }
rustpython-module_pyo3 = { path = "crates/module_pyo3", version = "0.6.1", default-features = false }

# Use the RustPython Ruff fork for RustPython public `_ast` metadata.
ruff_python_parser = { package = "rustpython-ruff_python_parser", git = "https://github.com/RustPython/ruff.git", rev = "9290a8849542134d83f77e9360e7f0b93897fd93" }
Expand Down
25 changes: 25 additions & 0 deletions crates/module_pyo3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "rustpython-module_pyo3"
description = "RustPython pyo3 module - bridge to CPython via PyO3"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license.workspace = true

[features]
default = ["doc"]
doc = ["rustpython-vm/doc"]
threading = ["rustpython-vm/threading"]

[dependencies]
rustpython-vm = { workspace = true }
rustpython-derive = { workspace = true }
pyo3 = { workspace = true, features = ["auto-initialize"] }
malachite-bigint = { workspace = true }
num-complex = { workspace = true }
num-traits = { workspace = true }

[lints]
workspace = true
Loading
Loading