@@ -18,36 +18,49 @@ A Python-3 (CPython >= 3.11.0) Interpreter written in Rust :snake: :scream:
18
18
19
19
## Usage
20
20
21
- #### Check out our [ online demo] ( https://rustpython.github.io/demo/ ) running on WebAssembly.
21
+ ** Check out our [ online demo] ( https://rustpython.github.io/demo/ ) running on WebAssembly.**
22
22
23
- RustPython requires Rust latest stable version (e.g 1.65.0 at November 10th 2022).
24
- To check Rust version: ` rustc --version ` If you wish to update,
25
- ` rustup update stable ` .
23
+ RustPython requires Rust latest stable version (e.g 1.67.1 at February 7th 2023). If you don't
24
+ currently have Rust installed on your system you can do so by following the instructions at [ rustup.rs] ( https://rustup.rs/ ) .
26
25
27
- To build RustPython locally, do the following:
26
+ To check the version of Rust you're currently running, use ` rustc --version ` . If you wish to update,
27
+ ` rustup update stable ` will update your Rust installation to the most recent stable release.
28
28
29
- $ git clone https://github.com/RustPython/RustPython
30
- $ cd RustPython
31
- # --release is needed (at least on windows) to prevent stack overflow
32
- $ cargo run --release demo.py
33
- Hello, RustPython!
29
+ To build RustPython locally, first, clone the source code:
30
+
31
+ ``` bash
32
+ git clone https://github.com/RustPython/RustPython
33
+ ```
34
+
35
+ Then you can change into the RustPython directory and run the demo (Note: ` --release ` is
36
+ needed to prevent stack overflow on Windows):
37
+
38
+ ``` bash
39
+ $ cd RustPython
40
+ $ cargo run --release demo_closures.py
41
+ Hello, RustPython!
42
+ ```
34
43
35
44
Or use the interactive shell:
36
45
37
- $ cargo run --release
38
- Welcome to rustpython
39
- >>>>> 2+2
40
- 4
41
-
46
+ ``` bash
47
+ $ cargo run --release
48
+ Welcome to rustpython
49
+ >>>>> 2+2
50
+ 4
51
+ ```
52
+
42
53
NOTE: For windows users, please set ` RUSTPYTHONPATH ` environment variable as ` Lib ` path in project directory.
43
54
(e.g. When RustPython directory is ` C:\RustPython ` , set ` RUSTPYTHONPATH ` as ` C:\RustPython\Lib ` )
44
55
45
56
You can also install and run RustPython with the following:
46
57
47
- $ cargo install --git https://github.com/RustPython/RustPython
48
- $ rustpython
49
- Welcome to the magnificent Rust Python interpreter
50
- >>>>>
58
+ ``` bash
59
+ $ cargo install --git https://github.com/RustPython/RustPython
60
+ $ rustpython
61
+ Welcome to the magnificent Rust Python interpreter
62
+ >>>>>
63
+ ```
51
64
52
65
(The ` rustpython-* ` crates are currently yanked from crates.io due to being out
53
66
of date and not building on newer rust versions; we hope to release a new
@@ -61,31 +74,37 @@ which compiles OpenSSL for you but requires a C compiler, perl, and `make`.
61
74
Once you've installed rustpython with SSL support, you can install pip by
62
75
running:
63
76
64
- $ rustpython --install-pip
77
+ ``` bash
78
+ rustpython --install-pip
79
+ ```
65
80
66
81
You can also install RustPython through the ` conda ` package manager, though
67
82
this isn't officially supported and may be out of date:
68
83
69
- $ conda install rustpython -c conda-forge
70
- $ rustpython
71
-
84
+ ``` bash
85
+ conda install rustpython -c conda-forge
86
+ rustpython
87
+ ```
72
88
73
89
### WASI
74
90
75
91
You can compile RustPython to a standalone WebAssembly WASI module so it can run anywhere.
76
92
77
93
Build
78
- ``` shell
79
- $ cargo build --target wasm32-wasi --no-default-features --features freeze-stdlib,stdlib --release
94
+
95
+ ``` bash
96
+ cargo build --target wasm32-wasi --no-default-features --features freeze-stdlib,stdlib --release
80
97
```
81
98
82
99
Run by wasmer
83
- ``` shell
84
- $ wasmer run --dir . target/wasm32-wasi/release/rustpython.wasm extra_tests/snippets/stdlib_random.py
100
+
101
+ ``` bash
102
+ wasmer run --dir . target/wasm32-wasi/release/rustpython.wasm extra_tests/snippets/stdlib_random.py
85
103
```
86
104
87
105
Run by wapm
88
- ``` shell
106
+
107
+ ``` bash
89
108
$ wapm install rustpython
90
109
$ wapm run rustpython
91
110
>>>>> 2+2
@@ -96,25 +115,27 @@ $ wapm run rustpython
96
115
97
116
You can build the WebAssembly WASI file with:
98
117
99
- ```
118
+ ``` bash
100
119
cargo build --release --target wasm32-wasi --features=" freeze-stdlib"
101
120
```
102
121
103
122
> Note: we use the ` freeze-stdlib ` to include the standard library inside the binary. You also have to run once ` rustup target add wasm32-wasi ` .
104
123
105
124
### JIT (Just in time) compiler
106
125
107
- RustPython has a ** very** experimental JIT compiler that compile python functions into native code.
126
+ RustPython has a ** very** experimental JIT compiler that compile python functions into native code.
108
127
109
128
#### Building
110
129
111
130
By default the JIT compiler isn't enabled, it's enabled with the ` jit ` cargo feature.
112
131
113
- $ cargo run --features jit
114
-
132
+ ``` bash
133
+ cargo run --features jit
134
+ ```
135
+
115
136
This requires autoconf, automake, libtool, and clang to be installed.
116
137
117
- #### Using
138
+ #### Using
118
139
119
140
To compile a function, call ` __jit__() ` on it.
120
141
@@ -176,11 +197,12 @@ latest release, or the [user guide](https://rustpython.github.io/docs/).
176
197
You can also generate documentation locally by running:
177
198
178
199
``` shell
179
- $ cargo doc # Including documentation for all dependencies
180
- $ cargo doc --no-deps --all # Excluding all dependencies
200
+ cargo doc # Including documentation for all dependencies
201
+ cargo doc --no-deps --all # Excluding all dependencies
181
202
```
182
203
183
- Documentation HTML files can then be found in the ` target/doc ` directory.
204
+ Documentation HTML files can then be found in the ` target/doc ` directory or you can append ` --open ` to the previous commands to
205
+ have the documentation open automatically on your default browser.
184
206
185
207
## Contributing
186
208
@@ -208,6 +230,7 @@ method.
208
230
[ See this doc] ( wasm/README.md )
209
231
210
232
## Community
233
+
211
234
![ Discord Banner] ( https://discordapp.com/api/guilds/1043121930691149845/widget.png?style=banner2 )
212
235
213
236
Chat with us on [ Discord] [ discord ] .
0 commit comments