mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Merge pull request #3132 from youknowone/sys
vm::sysmodule -> vm::stdlib::sys
This commit is contained in:
8 files changed
+29
-25
No files matched your search
+3
-3
@@ -45,7 +45,7 @@ extern crate log;
|
||||
|
||||
use clap::{App, AppSettings, Arg, ArgMatches};
|
||||
use rustpython_vm::{
|
||||
builtins::PyInt, compile, exceptions::print_exception, match_class, scope::Scope, sysmodule,
|
||||
builtins::PyInt, compile, exceptions::print_exception, match_class, scope::Scope, stdlib::sys,
|
||||
InitParameter, Interpreter, ItemProtocol, PyResult, PySettings, TypeProtocol, VirtualMachine,
|
||||
};
|
||||
|
||||
@@ -158,10 +158,10 @@ where
|
||||
}
|
||||
|
||||
fn flush_std(vm: &VirtualMachine) {
|
||||
if let Ok(stdout) = sysmodule::get_stdout(vm) {
|
||||
if let Ok(stdout) = sys::get_stdout(vm) {
|
||||
let _ = vm.call_method(&stdout, "flush", ());
|
||||
}
|
||||
if let Ok(stderr) = sysmodule::get_stderr(vm) {
|
||||
if let Ok(stderr) = sys::get_stderr(vm) {
|
||||
let _ = vm.call_method(&stderr, "flush", ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ mod decl {
|
||||
readline::{Readline, ReadlineResult},
|
||||
scope::Scope,
|
||||
slots::PyComparisonOp,
|
||||
sysmodule,
|
||||
stdlib::sys,
|
||||
utils::Either,
|
||||
IdProtocol, ItemProtocol, PyArithmaticValue, PyClassImpl, PyObjectRef, PyRef, PyResult,
|
||||
PyValue, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
@@ -358,9 +358,9 @@ mod decl {
|
||||
|
||||
#[pyfunction]
|
||||
fn input(prompt: OptionalArg<PyStrRef>, vm: &VirtualMachine) -> PyResult {
|
||||
let stdin = sysmodule::get_stdin(vm)?;
|
||||
let stdout = sysmodule::get_stdout(vm)?;
|
||||
let stderr = sysmodule::get_stderr(vm)?;
|
||||
let stdin = sys::get_stdin(vm)?;
|
||||
let stdout = sys::get_stdout(vm)?;
|
||||
let stderr = sys::get_stderr(vm)?;
|
||||
|
||||
let _ = vm.call_method(&stderr, "flush", ());
|
||||
|
||||
@@ -645,7 +645,7 @@ mod decl {
|
||||
pub fn print(objects: PosArgs, options: PrintOptions, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let file = match options.file {
|
||||
Some(f) => f,
|
||||
None => sysmodule::get_stdout(vm)?,
|
||||
None => sys::get_stdout(vm)?,
|
||||
};
|
||||
let write = |obj: PyStrRef| vm.call_method(&file, "write", (obj,));
|
||||
|
||||
|
||||
+11
-10
@@ -6,22 +6,23 @@ use crate::{
|
||||
},
|
||||
function::{ArgIterable, FuncArgs},
|
||||
py_io::{self, Write},
|
||||
sysmodule, IdProtocol, IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult,
|
||||
PyValue, StaticType, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
stdlib::sys,
|
||||
IdProtocol, IntoPyObject, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue,
|
||||
StaticType, TryFromObject, TypeProtocol, VirtualMachine,
|
||||
};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufRead, BufReader};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
io::{self, BufRead, BufReader},
|
||||
};
|
||||
|
||||
pub trait IntoPyException {
|
||||
fn into_pyexception(self, vm: &VirtualMachine) -> PyBaseExceptionRef;
|
||||
}
|
||||
|
||||
impl fmt::Debug for PyBaseException {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
impl std::fmt::Debug for PyBaseException {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
// TODO: implement more detailed, non-recursive Debug formatter
|
||||
f.write_str("PyBaseException")
|
||||
}
|
||||
@@ -47,7 +48,7 @@ pub fn chain<T>(e1: PyResult<()>, e2: PyResult<T>) -> PyResult<T> {
|
||||
/// Print exception chain by calling sys.excepthook
|
||||
pub fn print_exception(vm: &VirtualMachine, exc: PyBaseExceptionRef) {
|
||||
let write_fallback = |exc, errstr| {
|
||||
if let Ok(stderr) = sysmodule::get_stderr(vm) {
|
||||
if let Ok(stderr) = sys::get_stderr(vm) {
|
||||
let mut stderr = py_io::PyWriter(stderr, vm);
|
||||
// if this fails stderr might be closed -- ignore it
|
||||
let _ = writeln!(stderr, "{}", errstr);
|
||||
@@ -84,7 +85,7 @@ fn print_source_line<W: Write>(
|
||||
) -> Result<(), W::Error> {
|
||||
// TODO: use io.open() method instead, when available, according to https://github.com/python/cpython/blob/main/Python/traceback.c#L393
|
||||
// TODO: support different encodings
|
||||
let file = match File::open(filename) {
|
||||
let file = match std::fs::File::open(filename) {
|
||||
Ok(file) => file,
|
||||
Err(_) => return Ok(()),
|
||||
};
|
||||
|
||||
@@ -72,7 +72,6 @@ mod signal;
|
||||
mod sliceable;
|
||||
pub mod slots;
|
||||
pub mod stdlib;
|
||||
pub mod sysmodule;
|
||||
pub mod types;
|
||||
pub mod utils;
|
||||
mod version;
|
||||
|
||||
@@ -81,6 +81,7 @@ mod select;
|
||||
pub(crate) mod signal;
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "ssl"))]
|
||||
mod ssl;
|
||||
pub mod sys;
|
||||
#[cfg(all(unix, not(target_os = "redox")))]
|
||||
mod termios;
|
||||
#[cfg(windows)]
|
||||
@@ -146,7 +147,7 @@ pub fn get_module_inits() -> StdlibMap {
|
||||
"unicodedata" => unicodedata::make_module,
|
||||
"_warnings" => warnings::make_module,
|
||||
"zlib" => zlib::make_module,
|
||||
crate::sysmodule::sysconfigdata_name() => sysconfigdata::make_module,
|
||||
sys::sysconfigdata_name() => sysconfigdata::make_module,
|
||||
}
|
||||
// parser related modules:
|
||||
#[cfg(feature = "rustpython-ast")]
|
||||
|
||||
@@ -361,7 +361,7 @@ pub fn get_stderr(vm: &VirtualMachine) -> PyResult {
|
||||
/// # Usage
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// writeln!(sysmodule::PyStderr(vm), "foo bar baz :)");
|
||||
/// writeln!(sys::PyStderr(vm), "foo bar baz :)");
|
||||
/// ```
|
||||
///
|
||||
/// Unlike writing to a `std::io::Write` with the `write[ln]!()` macro, there's no error condition here;
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::sysmodule::MULTIARCH;
|
||||
use super::sys::MULTIARCH;
|
||||
use crate::{IntoPyObject, ItemProtocol, PyObjectRef, VirtualMachine};
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
|
||||
+6
-3
@@ -26,7 +26,7 @@ use crate::{
|
||||
scope::Scope,
|
||||
signal::NSIG,
|
||||
slots::PyComparisonOp,
|
||||
stdlib, sysmodule,
|
||||
stdlib,
|
||||
utils::Either,
|
||||
IdProtocol, IntoPyObject, ItemProtocol, PyArithmaticValue, PyContext, PyLease, PyMethod,
|
||||
PyObject, PyObjectRef, PyRef, PyRefExact, PyResult, PyValue, TryFromObject, TryIntoRef,
|
||||
@@ -326,7 +326,7 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
builtins::make_module(self, self.builtins.clone());
|
||||
sysmodule::make_module(self, self.sys_module.clone(), self.builtins.clone());
|
||||
stdlib::sys::make_module(self, self.sys_module.clone(), self.builtins.clone());
|
||||
|
||||
let mut inner_init = || -> PyResult<()> {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -475,7 +475,10 @@ impl VirtualMachine {
|
||||
if let Err(e) = self.invoke(&func, args) {
|
||||
last_exc = Some(e.clone());
|
||||
if !e.isinstance(&self.ctx.exceptions.system_exit) {
|
||||
writeln!(sysmodule::PyStderr(self), "Error in atexit._run_exitfuncs:");
|
||||
writeln!(
|
||||
stdlib::sys::PyStderr(self),
|
||||
"Error in atexit._run_exitfuncs:"
|
||||
);
|
||||
exceptions::print_exception(self, e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user