Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 16 15:21
    David-OConnor commented #220
  • Oct 15 05:41
    programmerjake commented #220
  • Oct 14 13:21
    dependabot-preview[bot] labeled #223
  • Oct 14 13:21
    dependabot-preview[bot] opened #223
  • Oct 14 13:21

    dependabot-preview[bot] on cargo

    Bump failure from 0.1.5 to 0.1.… (compare)

  • Oct 14 13:20
    dependabot-preview[bot] labeled #222
  • Oct 14 13:20
    dependabot-preview[bot] opened #222
  • Oct 14 13:20

    dependabot-preview[bot] on cargo

    Bump structopt from 0.3.2 to 0.… (compare)

  • Oct 14 13:20

    dependabot-preview[bot] on cargo

    (compare)

  • Oct 14 13:20
    dependabot-preview[bot] closed #217
  • Oct 14 13:20
    dependabot-preview[bot] commented #217
  • Oct 14 13:20
    dependabot-preview[bot] labeled #221
  • Oct 14 13:20
    dependabot-preview[bot] opened #221
  • Oct 14 13:20

    dependabot-preview[bot] on cargo

    Bump reqwest from 0.9.20 to 0.9… (compare)

  • Oct 14 11:50
    David-OConnor edited #220
  • Oct 14 11:49
    David-OConnor opened #220
  • Oct 11 03:50
    programmerjake edited #219
  • Oct 11 03:49
    programmerjake opened #219
  • Oct 07 15:41
    dependabot-preview[bot] synchronize #217
  • Oct 07 15:41

    dependabot-preview[bot] on cargo

    Bump reqwest from 0.9.20 to 0.9… (compare)

konstin
@konstin
@kngwyu I've removed you from the list of collaborators; You should still have the same access but just that you know
Yuji Kanagawa
@kngwyu
:heavy_check_mark:
Yuji Kanagawa
@kngwyu
@pramodbutte Sorry I have no time this week, please wait for a few days... :sweat:
pramodbutte
@pramodbutte
ok thanks! I have been fighting with the borrow checker for straight 36 hours!! this is my first battle and i hope i will figure this out eventually. :wink: any help is appreciated. thanks i will keep hacking hoping there is a possibility of solution in the end :smile: :thumbsup:
Yuji Kanagawa
@kngwyu
@pramodbutte
I think the use of as_array_mut is the key point.
For now I added an example function rust-numpy/rust-numpy#108
Paul Ganssle
@pganssle
Here's my talk from PyLondinium on Rust and Python: https://www.youtube.com/watch?v=IqQDl_2BsNs
pramodbutte
@pramodbutte
@kngwyu thanks trying it now!
William Patton
@pattonw
I threw together a quick cookiecutter (https://github.com/pattonw/cookiecutter-rust-pypackage) for a mixed layout package using pyo3 and pyo3-pack. Its still very much a work in progress but if anyone wants to give me some pointers on tools that are nice to have set up for a mixed layout project let me know
Yoandy Rodriguez Martinez
@yorodm
hello, is there some tutorial about how to do I/O from the Rust side using PyO3?
RKennedy9064
@RKennedy9064

I have a quick question about #[pyclass] if anyone is available. Is there any reason why I would't be able to return a struct that is annotated with #[pyclass]? I currently have these two struct I'm working with.

#[pyclass]
#[derive(Debug)]
pub struct Reader {
    pub inner: CsvReader<File>,
}

#[pyclass]
#[derive(Debug)]
pub struct Position {
    inner: CsvPosition,
}

#[staticmethod]
    fn from_path(path: &str) -> PyResult<Reader> {
        let inner = CsvReader::from_path(path).map_err(|err| ApplicationError::from(err))?;

        Ok(Reader { inner })
    }

fn position(&self) -> PyResult<Position> {
        let inner = self.inner.position().clone();
        Ok(Position { inner })
    }

I'm able to build and use my from_path function to Return a reader, but when I try to return a Position I get this error.

error[E0277]: the trait bound `csv::reader::Position: pyo3::conversion::FromPyObject<'_>` is not satisfied
  --> src\csv\reader.rs:22:1
   |
22 | #[pymethods]
   | ^^^^^^^^^^^^ the trait `pyo3::conversion::FromPyObject<'_>` is not implemented for `csv::reader::Position`

Why does returning a Reader work, but not a Position even though both have #[pyclass]?

Omer Katz
@thedrow
Because PyO3 doesn't know how to convert csv::reader::Position to a PyObject.
Omer Katz
@thedrow
You probably want to use Py<Position> as the type
RKennedy9064
@RKennedy9064
@thedrow How does it know to convert reader? Is there anything different between them? They're both annotated with #[pyclass].
Ethan Smith
@ethanhs
@kngwyu Hi! I've been using rust-numpy and loving it! Using it to speed up some quantum computing work. I was hoping to pass a pyclass across multiprocessing boundaries and I'm excited to use the new features in pyo3 master related to pickling, but as far as I can tell, there are compatibility issues between the pyo3 master and rust-numpy master. I was curious if you were planning on releasing newer versions of pyo3/rust-numpy in the next week or so? No worries at all if not, and thank you so much for your work on these projects!
Geordon Worley
@vadixidav
hey, I am trying to import and run something from a python module:
fn python_hello(name: &str) -> PyResult<String> {
    let gil = Python::acquire_gil();
    let py = gil.python();
    let locals = [
        ("greet", py.import("modules")?.get("greet")?.to_object(py)),
        ("name", name.to_object(py)),
    ]
    .into_py_dict(py);
    let code = "greet.greeting(name)";
    let hello_world: String = py.eval(code, None, Some(&locals))?.extract()?;
    Ok(hello_world)
}
but it just gives back PyErr { type: Py(0x7f90b5a4c7c0, PhantomData) }
I am just starting to use PyO3
does anyone know if I am fundamentally misunderstanding something here?
Geordon Worley
@vadixidav
I am also trying some other things
like this
fn python_hello(name: &str) -> PyResult<String> {
    let gil = Python::acquire_gil();
    let py = gil.python();
    // Import greet module into global scope.
    py.run("import modules.greet", None, None)?;

    // Get greeting
    let locals = [("name", name)].into_py_dict(py);
    let hello_world: String = py
        .eval("greet.greeting(name)", None, Some(&locals))?
        .extract()?;
    Ok(hello_world)
}
Geordon Worley
@vadixidav
seems I cant even evaluate a simple string
fn python_hello(name: &str) -> PyResult<String> {
    let gil = Python::acquire_gil();
    let py = gil.python();
    let hello_world: String = py.eval("'test'", None, None)?.extract()?;
    Ok(hello_world)
}
Geordon Worley
@vadixidav
actually, it seems I can evaluate a string, but importing the module causes it to fail
if anyone knows how to import a module with pyo3 I would appreciate it
Geordon Worley
@vadixidav
got it to work by modifying sys.path and inserting the cwd
Geordon Worley
@vadixidav
I keep seeing this PyErr { type: Py(0x7fb6aeca1a00, PhantomData) }
is this something I can extract more information from?
Yuji Kanagawa
@kngwyu
@ethanhs
Sorry for my delayed response, but I'll do it this weekend. Thank you.
Ethan Smith
@ethanhs
@kngwyu that would be fantastic!
Yuji Kanagawa
@kngwyu
And sorry in advance for my less attendance in this project till 9/21 since my part-time job
Ethan Smith
@ethanhs
Thank you so much! And no worries at all, I'm sure you are plenty busy
Diego Luca Candido
@joxer
Hi, can I from Rust eval interpreter a python snippet instead of just an expression?
the eval method just eval the line of code
I'm a moron, there's run() -_-
but another question, can I have a context the script i'm executing? My idea is to execute it multiple times and have a generic context structure
William Patton
@pattonw
Do any of the maturin releases support pip installing with mixed layout projects? pip install . comes up with the error pip._vendor.pep517.wrappers.BackendUnavailable which i solved last time by setting requires = ["pyo3-pack==0.7.0-beta.7"], but I'm getting the same error for maturin 0.7.1, 0.7.1-beta.1 and 0.7.1-beta.2
Samuel Batissou Tiburcio
@SamBlaise
Hi can I specify multiple constructors for an python class written in Rust ?
Omer Katz
@thedrow
It turns out PyO3 is not supported on Alpine because of the ctor crate
Florian Finkernagel
@TyberiusPrime
Hello channel, I have a #[pyclass...]), and now I want to have a method that case another object of the same class as a parameter. Is there an easy way to derive the FromPyObject for my class?
@SamBlaise I use classmethods instead of multiple constructors. Example #[classmethod] pub fn from_tuples(_cls: &PyType, tups: Vec<(u32, u32)>) -> PyResult<Py<PyIntervalSet>> {
David Sanders
@davesque
I'm trying to write a python extension with a function that returns the python type bytes. What rust type should the rust function that's annotated with #[pyfunction] return to accomplish this?
gperinazzo
@gperinazzo
@davesque Have you tried returning a PyByteArray?
David Sanders
@davesque
Actually, I ended up returning PyResult<PyObject> and change the return expression to Ok(PyBytes::new(py, val).into()) and that worked.
The problem was that I was trying to return PyResult<PyBytes> and rust was complaining that a trait bound wasn't met for IntoPyResult from PyResult<PyBytes>.
Sorry, made a correction up there. It was IntoPyResult.
David Sanders
@davesque
Here was the exact print out:
error[E0277]: the trait bound `std::result::Result<pyo3::types::string::PyBytes, pyo3::err::PyErr>: pyo3::derive_utils::IntoPyResult<_>` is not satisfied
  --> src/lib.rs:74:1
   |
74 | #[pyfunction]
   | ^^^^^^^^^^^^^ the trait `pyo3::derive_utils::IntoPyResult<_>` is not implemented for `std::result::Result<pyo3::types::string::PyBytes, pyo3::err::PyErr>`
   |
   = help: the following implementations were found:
             <std::result::Result<T, pyo3::err::PyErr> as pyo3::derive_utils::IntoPyResult<T>>
   = note: required by `pyo3::derive_utils::IntoPyResult::into_py_result`
Yuji Kanagawa
@kngwyu
Hmm, it looks weird, Ok(PyBytes) should work...
Kixiron
@Kixiron
I'm getting some weird errors
ImportError: bad magic number in 'pacman_utils_native': b'MZ\x90\x00'
I can provide my code if needed