forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.rs
More file actions
49 lines (42 loc) · 1.7 KB
/
platform.rs
File metadata and controls
49 lines (42 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::function::PyFuncArgs;
use crate::pyobject::{PyObjectRef, PyResult};
use crate::version;
use crate::vm::VirtualMachine;
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
let ctx = &vm.ctx;
py_module!(vm, "platform", {
"python_branch" => ctx.new_rustfunc(platform_python_branch),
"python_build" => ctx.new_rustfunc(platform_python_build),
"python_compiler" => ctx.new_rustfunc(platform_python_compiler),
"python_implementation" => ctx.new_rustfunc(platform_python_implementation),
"python_revision" => ctx.new_rustfunc(platform_python_revision),
"python_version" => ctx.new_rustfunc(platform_python_version),
})
}
fn platform_python_implementation(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args);
Ok(vm.new_str("RustPython".to_string()))
}
fn platform_python_version(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args);
Ok(vm.new_str(version::get_version_number()))
}
fn platform_python_compiler(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args);
Ok(vm.new_str(version::get_compiler()))
}
fn platform_python_build(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args);
let (git_hash, git_timestamp) = version::get_build_info();
Ok(vm
.ctx
.new_tuple(vec![vm.new_str(git_hash), vm.new_str(git_timestamp)]))
}
fn platform_python_branch(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args);
Ok(vm.new_str(version::get_git_branch()))
}
fn platform_python_revision(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args);
Ok(vm.new_str(version::get_git_revision()))
}