Skip to content

Further updates #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
- [Interop](interop/index.md)
- [Calling Rust from Python](interop/rust_from_python.md)
- [Calling Python from Rust](interop/python_from_rust.md)
- [Error Handling](error_handling.md)
7 changes: 7 additions & 0 deletions src/error_handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Error Handling

Most errors are considered `PyResult`s, this is re-exported as `rustpython_vm::PyResult`.

The error in a `PyResult` is a `PyBaseExceptionRef`, which is a reference to a base error (documented as `PyBaseException`).

It contains methods that return more information.
6 changes: 2 additions & 4 deletions src/getting_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ The tag should be pointed to the latest tag found at https://github.com/RustPyth

## Features
By default `threading`, `stdlib`, and `importlib` are enabled.
### `bz2`
If you'd like to use the `bz2` module, you can enable the `bz2` feature.
### `stdlib`
`stdlib` is the default feature that enables the standard library.
`stdlib` is the default feature that enables the standard library,
parts of the stdlib will still be accessible even if this is disabled.
### `sqlite`
If you'd like to use the `sqlite3` module, you can enable the `sqlite` feature.
### `ssl`
Expand All @@ -37,4 +36,3 @@ which also lets you install the pip package manager.
Note that on Windows, you may need to install OpenSSL, or you can enable the ssl-vendor feature instead,
which compiles OpenSSL for you but requires a C compiler, perl, and make.
OpenSSL version 3 is expected and tested in CI. Older versions may not work.

30 changes: 29 additions & 1 deletion src/interop/python_from_rust.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# Calling Python from Rust
TODO.

## Running code

The simplest way to do this is `VirtualMachine::run_code_string`.
This requires a scope, which can be created with `VirtualMachine::new_scope_with_builtins`
```rust
let scope = vm.new_scope_with_builtins();
vm.run_code_string(scope, "print('hello')", "<embedded>").unwrap();
```

If your code is from a path, consider using `VirtualMachine::run_script`

```rust
let scope = vm.new_scope_with_builtins();
vm.run_code_string(scope, "hello.py").unwrap();
```

### Compilation
```rust
vm.compile("print('hello')", vm::compiler::Mode::Exec, "<embedded>".to_owned())
```
once compiled, the code can be called any number of times with
```rust
let scope = vm.new_scope_with_builtins();
vm.run_code_obj(code_obj, scope)?;
```

## Calling specific code
TODO.
6 changes: 5 additions & 1 deletion src/introduction/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Introduction

RustPython is a Python interpreter written in Rust.
RustPython is a Python 3 interpreter written in Rust.
RustPython can be embedded in existing rust projects or can be run via WASM to run python in a sandboxed enviorment, or in the browser.

RustPython provides a mostly complete version of the standard library.
Major incompatabilities can be found here: https://rustpython.github.io/pages/whats-left