Skip to content

Commit 152c165

Browse files
committed
Add sys.platform
1 parent 0a683f2 commit 152c165

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

tests/snippets/sysmod.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
print(sys.argv)
44
assert sys.argv[0].endswith('.py')
5+
6+
assert sys.platform == "linux" or sys.platform == "darwin" or sys.platform == "win32" or sys.platform == "unknown"

vm/src/sysmodule.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef, builtins: PyObjectR
6262
};
6363
let path = ctx.new_list(path_list);
6464

65+
let platform = if cfg!(target_os = "linux") {
66+
"linux".to_string()
67+
} else if cfg!(target_os = "macos") {
68+
"darwin".to_string()
69+
} else if cfg!(target_os = "windows") {
70+
"win32".to_string()
71+
} else if cfg!(target_os = "android") {
72+
// Linux as well. see https://bugs.python.org/issue32637
73+
"linux".to_string()
74+
} else {
75+
"unknown".to_string()
76+
};
77+
6578
let sys_doc = "This module provides access to some objects used or maintained by the
6679
interpreter and to functions that interact strongly with the interpreter.
6780
@@ -145,6 +158,7 @@ settrace() -- set the global debug tracing function
145158
"_getframe" => ctx.new_rustfunc(getframe),
146159
"modules" => modules.clone(),
147160
"warnoptions" => ctx.new_list(vec![]),
161+
"platform" => ctx.new_str(platform),
148162
});
149163

150164
modules.set_item("sys", module.clone(), vm).unwrap();

0 commit comments

Comments
 (0)