by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Alan Justino da Silva
    @alanjds
    thanks
    Good... night?
    Karel L. Kubat
    @KaiserKarel
    It's good to see that all VM attributes are public; so I can just implement a custom builder and do the inits myself
    Without certain modules; python cannot make system calls right?
    Or does the language have some builtin ways to make them as well?
    Karel L. Kubat
    @KaiserKarel
    Also, what does py_compile_bytecode accept exactly/how does it work? :)
    Karel L. Kubat
    @KaiserKarel
    Oh and out of the builtins; open, input and print obviously make syscalls
    Sean Chen
    @seanchen1991
    Hi, I just wanted to ask and make sure that currently when you run pytest -v against the source code that there will be some expected failures. I'm seeing SampleTestCase.test_cpython_function_args, SampleTestCase.test_cpython_fstrings, and SampleTestCase.test_cpython_dict_union failing.
    Noah
    @coolreader18
    It might be because your system Python version is a bit behind, but it shouldn't be anything to worry about; the Python version when it's tested on CI is always consistent
    Sean Chen
    @seanchen1991
    Oh ok, I'm on 3.7.2, not 3.7.4.
    Jeong YunWon
    @youknowone
    The ci probably run 3.8.x
    Karel L. Kubat
    @KaiserKarel
    I'm trying to call vm.set_attr, but I'm getting a trait not implemented error on smallbox
    My code is basically taken from vm.initialize
    let mut vm = python::VirtualMachine::new(setting);
            // ensure that only files to which we have the capabilities can be opened, by removing
            // the standard open wrapper, and substituting our own.
            {
                let open_wrapper = crate::stdlib::io::io_open_with_capabilities(self.cap.clone().fs);
                vm.set_attr(&vm.builtins, "open", open_wrapper)?;
            }
    
            Ok(Vm{vm, cap: self.cap.clone()})
    where my open_wrapper is a PyNative functions
    Any clues what's going on? I'm creating open_wrapper using IntoPyNativeFunc::into_func(open_fn)
    I'm on master btw
    Noah
    @coolreader18
    Huh, strange
    That looks like a span issue in rustc, because there's nothing in vm.set_attr that requires that trait bound
    @KaiserKarel my bet is that it's something to do with the open function not being a valid IntoPyFunc
    What specifically is the type of open_wrapper? You can do something like let open_wrapper: () = ... to get an error message with the full type
    Karel L. Kubat
    @KaiserKarel
    pub fn io_open_with_capabilities(capabilities: Privilege<HashSet<Capability>>) -> PyNativeFunc {
        let open_fn =  |file: PyObjectRef, mode: OptionalArg<PyStringRef>, opts: OpenArgs, vm: &VirtualMachine| {
            match &capabilities {
                Privilege::None => return Err(vm.new_value_error("Filesystem capabilities are not enabled.".to_owned())),
                Privilege::Total => {
                    let mode = mode.as_ref().into_option().map(|s| s.as_str());
                    return python::stdlib::io::io_open(file, mode, opts, vm)
                },
                Privilege::Limited(caps) => {
                    todo!("check if the file should be opened based on the capabilities.");
                    let mode = mode.as_ref().into_option().map(|s| s.as_str());
                    python::stdlib::io::io_open(file, mode, opts, vm)
                }
            }
        };
    
        IntoPyNativeFunc::into_func(open_fn)
    }
    This produces the open_wrapper
    and the type is
    error[E0308]: mismatched types
      --> src/vm.rs:89:36
       |
    89 |             let open_wrapper: () = crate::stdlib::io::io_open_with_capabilities(self.cap.clone().fs);
       |                               --   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `smallbox::smallbox::SmallBox`
       |                               |
       |                               expected due to this
       |
       = note: expected unit type `()`
                     found struct `smallbox::smallbox::SmallBox<(dyn for<'r> std::ops::Fn(&'r rustpython_vm::vm::VirtualMachine, rustpython_vm::function::PyFuncArgs) -> std::result::Result<std::sync::Arc<rustpython_vm::pyobject::PyObject<(dyn rustpython_vm::pyobject::PyObjectPayload + 'static)>>, rustpython_vm::pyobject::PyRef<rustpython_vm::exceptions::PyBaseException>> + std::marker::Send + std::marker::Sync + 'static), smallbox::space::S1>`
    
    error: could not compile `psammophis`.
    Karel L. Kubat
    @KaiserKarel
    io_open_with_capabilities does compile; so open_wrapper should be a valid PyNativeFunc
    Maybe something is going wrong with lifetimes since I am using a closure?
    Noah
    @coolreader18
    You need to convert it to a Python function from a rust closure, try passing vm.ctx.new_function(open_wrapper) as the third argument to set_attr
    Alan Justino da Silva
    @alanjds
    Question: How do I call the equivalent of super() during a #[pyproperty]?
    Noah
    @coolreader18
    You could in theory construct a PySuper object with zelf and Self::class(vm), and then get an attribute of it, but I'm not sure what the rust API of PySuper is looking like right now
    Karel L. Kubat
    @KaiserKarel
    That did the trick @coolreader18! Thanks for the help.
    Karel L. Kubat
    @KaiserKarel
    I feel like I keep asking stupid questions; but I am getting a couldn't init zipimport panic, originating from a ModuleNotFoundError: No module named 'io' in the initialize method of vm. I've copied the root level Lib from rustpython; and set the env variable RUSTPYTHONPATH=/path/to/lib
    James Webber
    @jamestwebber
    hello! on the topic of possibly-stupid questions: I'm not sure what's wrong but cargo run demo.py is failing for me with compilation errors
    fresh install of rust 1.40.0 and python 3.8 in a new conda env on Ubuntu 20.04
    most popular error is error[E0658]: custom attributes cannot be applied to modules
    Jeong YunWon
    @youknowone
    @jamestwebber Try to update rust to most recent version
    rustup update will work when you used rustup
    James Webber
    @jamestwebber
    ahh i used conda to install rust, didn't realize it was out of date
    James Webber
    @jamestwebber
    it works :tada:
    James Webber
    @jamestwebber
    is there a way to run a specific cpython test?
    cargo run Lib/test/test_whatever.py will run a whole file which takes a while
    James Webber
    @jamestwebber
    okay now i'm struggling debugging a test that should fail with python exception but is panicking with "no more blocks to pop"
    tried copying test_pickle.py and friends into the project
    James Webber
    @jamestwebber
    ^ dug a little deeper, it seems like a particular type of bad input caused this, b'V...'. there are a bunch of other errors in the tests but they at least run once i commented out those specific cases
    Noah
    @coolreader18
    @jamestwebber you can do something like cargo run --release -- -m test.test_whatever -k test_name
    @KaiserKarel I'm not sure why zipimport isn't working, but I think that should just be a warning, not a panic?
    James Webber
    @jamestwebber
    ah close, it was cargo run -- -m unittest test.test_pickle.PyPickleTests.test_callapi
    or least that worked
    i'm more used to pytest
    Jeong YunWon
    @youknowone
    -k option is searching as same as pytest
    James Webber
    @jamestwebber
    it didn't seem to work when i tried, not sure why