Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Noah
    @coolreader18
    oh wait i do use the system ssl lib, let me try with vendoring it into the binary
    ah I'm able to reproduce it now!
    although I'm not sure what we could do to fix it, it seems like it might be an issue in openssl-sys' tarball of openssl
    Noah
    @coolreader18
    Try setting OPENSSL_NO_VENDOR=1 while building, that should fix the issue temporarily (assuming you have openssl installed on your system)
    Zomatree
    @Zomatree
    yeah that seems to have fixed it
    Zomatree
    @Zomatree
      File "/home/zomatree/rustpytest/discord/http.py", line 134, in ws_connect
        return await self.__session.ws_connect(url, **kwargs)
    TypeError: 'coroutine_wrapper' object is not an iterator
    a new error
    Noah
    @coolreader18
    @Zomatree just pushed a fix
    Zomatree
    @Zomatree
    zlib.Decompress.decompress should be able to take both bytes and bytearray but it errors on bytearray
    >>>>> zlib.decompressobj().decompress(bytearray())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: Expected type 'bytes', not 'bytearray'
    Noah
    @coolreader18
    fixed :+1:
    this is a real smoke test of the small inconsistencies we have across the codebase :smile:
    Zomatree
    @Zomatree
    https://mystb.in/AcademyLensesButler.rust well its kinda working, however...
    Noah
    @coolreader18
    Hm, that's weird, I thought the json implementation handled unicode
    Noah
    @coolreader18
    @Zomatree Would you be able to find the specific string that had that unicode in it? I'd like to make sure my fix works
    ah nvm, I got it
    Zomatree
    @Zomatree

    rustpython doesnt add member descriptors for attributes defined inside __slots__.

    >>>>> class A:
    .....   __slots__ = ("b",)
    .....
    >>>>> dict(A.__dict__)
    {'__dict__': <getset_descriptor object at 0x55ba83927880>, '__doc__': None, '__new__': <bound method of <class '__main__.A'>>, '__module__': '__main__', '__qualname__': 'A', '__slots__': ('b',)}
    >>>>> A.b
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: type object 'A' has no attribute 'b'
    >>> class A:
    ...     __slots__ = ("b",)
    
    >>> A.__dict__
    mappingproxy({'__module__': '__main__', '__slots__': ('b',), 'b': <member 'b' of 'A' objects>, '__doc__': None})
    
    >>> A.b
    <member 'b' of 'A' objects>

    (also slight nitpick, mappingproxy has a differant repr)

    Noah
    @coolreader18
    yeah, we don't really support __slots__ at the moment
    Jeong YunWon
    @youknowone
    time for slot_descriptor
    Noah
    @coolreader18
    yeah, wooo 🙃
    I think CPython makes the object repr dependent on the __slots__, I assume we would just have a SlottedObjectpayload type with a vec field instead?
    Jeong YunWon
    @youknowone
    that make sense. but i don’t know how cpython handle it
    that sounds like to bea perfect solution if multiple inheritance is not possible with slot parent and other payload-attached types
    Zomatree
    @Zomatree
    do you have an example of using the _json module, i cant seem to get it to work
    Zomatree
    @Zomatree
    nvm got it
    Jonathan
    @jboi:jboi.nl
    [m]
    "lobby" implies there are more rooms, are there more rooms?
    Jeong YunWon
    @youknowone
    no, it is lobby and plaza at the same time. we don’t have that much traffic to separate channels yet
    Jonathan
    @jboi:jboi.nl
    [m]
    ah ok
    Prefix Required Jones
    @mojosd_twitter
    A discord server would be nice.
    Prefix Required Jones
    @mojosd_twitter
    Having threads would make reading these exchanges easier I think. Also, the Dev Guide mentions that there are contributors here willing to mentor those of us who are new to the project, and in my case new to OSS. If you one of those people willing to help and mentor someone new to RustPython, please let me know. I'm hoping to get some help with how to work with this project. Thank you.
    10 replies
    Pluriscient
    @Pluriscient

    A discord server would be nice.

    Zulip is also an alternative: https://zulip.com/

    0xc
    @tcarrio:matrix.org
    [m]
    What does the performance of RustPython look like so far?
    Klas Segeljakt
    @segeljakt

    Noob question, with python3-REPL I can import numpy as np, but with rustpython-REPL I get:

    >>>>> import numpy as np
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'numpy'

    is there a way to make it work?

    Noah
    @coolreader18
    No, we don't support numpy yet
    Klas Segeljakt
    @segeljakt
    hmm, how does it work, do all libraries need to be implemented in Rust for it to work?
    fbpyr
    @fbpyr:tchncs.de
    [m]
    @segeljakt: I would assume quite a few of the pure python libs should work directly, but probably not the ones having compiled C/asm/.. parts in it - like numpy.
    Noah
    @coolreader18
    I think the current plan is to implement the hpy abi, and then eventually numpy might support that as well: https://github.com/hpyproject/HPy https://github.com/hpyproject/numpy-hpy
    Klas Segeljakt
    @segeljakt
    👍
    jrmarcum
    @jrmarcum
    image.png
    Just checking to see if anyone saw this. The dirs crate is evidently not managed anymore and is listed as not secure for use. As it stands no one can install rust python with this crate like that.
    Jesse Hoobergs
    @jhoobergs
    Hi Guys! I am trying to embed RustPython in one of my programs. I based myself on https://github.com/RustPython/RustPython/blob/master/examples/hello_embed.rs en that works fine, but now I need to be able to 'interact' with the python code. With interact I mean that I would like to get the value of a variable after the execution, is this possible?
    I actually want to run the python code and set a certain string as stdin and read another one at the stdout, but I could not find an example for that? So now I add some code to the executed python snipped that sets stdin and stdout to a StringIO object and it is the value of this stdout StringIO variable that I would like to read.
    But if it is also possible to set the stdin from rust before executing the python code and reading the stdout afterwards, that would be even better.
    Noah
    @coolreader18
    I would recommend having a Python function that runs stuff, rather than appending to the user's Python code. So like:
    const CODE: &str = "
    import io, sys
    def run(code):
        stdout = io.StringIO()
        sys.stdout = stdout
        try:
            exec(code, {}, {}) # maybe you'll want to do something with the locals+globals
        finally:
            sys.stdout = sys.__stdout__
        return stdout.getvalue()
    ";
    Noah
    @coolreader18
    And then run it and get the run function from the globals scope. Then, when you have code to run, call vm.compile() with the code string and pass the code object to the run() function you got.
    Jesse Hoobergs
    @jhoobergs
    Thanks Noah. Could you elaborate a bit more on how I should compile the run function and how I can get access to it in the global scope? Should I compile in Eval or Exec mode etc?
    Jesse Hoobergs
    @jhoobergs
    I got some inspiration from the mini_repl example and came up with the following solution:
    use rustpython_vm as vm;
    
    // See: https://github.com/RustPython/RustPython/blob/d6c8247886ff504f77e8995b08d9a15c22dfa8a0/examples/mini_repl.rs
    macro_rules! add_python_function {
        ( $scope:ident, $vm:ident, $src:literal $(,)? ) => {{
            // compile the code to bytecode
            let code = vm::py_compile!(source = $src);
            // convert the rustpython_bytecode::CodeObject to a PyCodeRef
            let code = $vm.new_code_object(code);
    
            // run the python code in the scope to store the function
            $vm.run_code_obj(code, $scope.clone())
        }};
    }
    
    fn main() {
        let res = execute(r#"print(sum(map(int,input().split(" "))))"#, "1 2 3 4 5");
        println!("{}", res.expect("Failed executing"));
    }
    
    fn execute(code: &str, input: &str) -> Result<String, ()> {
        vm::Interpreter::default().enter(|vm| {
            let scope = vm.new_scope_with_builtins();
    
            add_python_function!(
                scope,
                vm,
                r#"
    import _io, sys
    def run(code, input):
        stdout = _io.StringIO()
        sys.stdin = _io.StringIO(input)
        sys.stdout = stdout
        try:
            exec(code, {}, {}) # maybe you'll want to do something with the locals+globals
        finally:
            sys.stdout = sys.__stdout__
            sys.stdin = sys.__stdin__
        return stdout.getvalue()            
    "#
            );
    
            let run_input = format!("run('{}', '{}')", code, input); // TODO: escape quotes?
    
            match vm
                .compile(&run_input, vm::compile::Mode::Eval, "<embedded>".to_owned())
                .map_err(|err| vm.new_syntax_error(&err))
                .and_then(|code_obj| vm.run_code_obj(code_obj, scope.clone()))
            {
                Ok(output) => {
                    if !vm.is_none(&output) {
                        match vm.to_str(&output) {
                            Ok(s) => Ok(s.as_ref().to_owned()),
                            Err(e) => Err(()), // TODO
                        }
                    } else {
                        Err(()) // TODO
                    }
                }
                Err(e) => {
                    vm::exceptions::print_exception(vm, e);
                    Err(()) // TODO
                }
            }
        })
    }
    The only thing that I should do differently, is compiling the given code to bytecode instead of pasting the given code in the run_input variable. I don't know how I can make it execute the run function with the bytecode as it's argument.
    Technisha
    @devstar:matrix.org
    [m]
    Heya!
    I'm compiling RustPython from source to try it out so -w-
    But uh, is this okay?