Skip to content

Commit dd8e9a6

Browse files
committed
Use pylib as a dependency of the rustpython binary in order to get a Lib path
1 parent d7bc121 commit dd8e9a6

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2018"
66
description = "A python interpreter written in rust."
77
repository = "https://github.com/RustPython/RustPython"
88
license = "MIT"
9+
include = ["LICENSE", "Cargo.toml", "src/**/*.rs"]
910

1011
[workspace]
1112
members = [".", "derive", "vm", "wasm/lib", "parser", "compiler", "bytecode", "vm/pylib-crate", "common"]
@@ -15,7 +16,7 @@ name = "bench"
1516
path = "./benchmarks/bench.rs"
1617

1718
[features]
18-
default = ["threading"]
19+
default = ["threading", "pylib"]
1920
flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
2021
freeze-stdlib = ["rustpython-vm/freeze-stdlib"]
2122
threading = ["rustpython-vm/threading"]
@@ -29,6 +30,7 @@ clap = "2.33"
2930
rustpython-compiler = { path = "compiler", version = "0.1.1" }
3031
rustpython-parser = { path = "parser", version = "0.1.1" }
3132
rustpython-vm = { path = "vm", version = "0.1.1", default-features = false, features = ["compile-parse"] }
33+
pylib = { package = "rustpython-pylib", path = "vm/pylib-crate", version = "0.1.0", default-features = false, optional = true }
3234
dirs = { package = "dirs-next", version = "1.0" }
3335
num-traits = "0.2.8"
3436
cfg-if = "0.1"

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ fn create_settings(matches: &ArgMatches) -> PySettings {
198198
// add the current directory to sys.path
199199
settings.path_list.push("".to_owned());
200200

201+
// BUILDTIME_RUSTPYTHONPATH should be set when distributing
201202
if let Some(paths) = option_env!("BUILDTIME_RUSTPYTHONPATH") {
202203
settings.path_list.extend(
203204
std::env::split_paths(paths).map(|path| path.into_os_string().into_string().unwrap()),
204205
)
205-
} else if option_env!("RUSTPYTHONPATH").is_none() {
206-
settings
207-
.path_list
208-
.push(concat!(env!("CARGO_MANIFEST_DIR"), "/Lib").to_owned());
206+
} else {
207+
#[cfg(all(feature = "pylib", not(feature = "freeze-stdlib")))]
208+
settings.path_list.push(pylib::LIB_PATH.to_owned());
209209
}
210210

211211
if !ignore_environment {

vm/pylib-crate/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ version = "0.1.0"
44
authors = ["RustPython Team"]
55
edition = "2018"
66

7+
[features]
8+
default = ["compiled-bytecode"]
9+
compiled-bytecode = ["rustpython-derive", "rustpython-bytecode"]
10+
711
[dependencies]
8-
rustpython-derive = { version = "0.1.2", path = "../../derive" }
9-
rustpython-bytecode = { version = "0.1.2", path = "../../bytecode" }
10-
maplit = "1.0"
12+
rustpython-derive = { version = "0.1.2", path = "../../derive", optional = true }
13+
rustpython-bytecode = { version = "0.1.2", path = "../../bytecode", optional = true }

vm/pylib-crate/src/lib.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,14 @@
44
55
extern crate self as rustpython_pylib;
66

7-
use rustpython_bytecode::bytecode::{self, FrozenModule};
8-
use std::collections::HashMap;
9-
10-
use rustpython_derive::py_compile_bytecode as _py_compile_bytecode;
11-
#[macro_export]
12-
macro_rules! py_compile_bytecode {
13-
($($arg:tt)*) => {{
14-
#[macro_use]
15-
mod __m {
16-
$crate::_py_compile_bytecode!($($arg)*);
17-
}
18-
__proc_macro_call!()
19-
}};
20-
}
21-
22-
mod __exports {
23-
pub use maplit::hashmap;
24-
}
7+
pub const LIB_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/Lib");
258

9+
#[cfg(feature = "compiled-bytecode")]
10+
use {
11+
rustpython_bytecode::bytecode::{self, FrozenModule},
12+
std::collections::HashMap,
13+
};
14+
#[cfg(feature = "compiled-bytecode")]
2615
pub fn frozen_stdlib() -> HashMap<String, FrozenModule> {
27-
py_compile_bytecode!(dir = "Lib", crate_name = "rustpython_pylib")
16+
rustpython_derive::py_compile_bytecode!(dir = "Lib", crate_name = "rustpython_pylib")
2817
}

0 commit comments

Comments
 (0)