Giter Site home page Giter Site logo

rustypy's People

Contributors

iduartgomez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rustypy's Issues

RustBinds does not contain expected methods

Documentation examples to create Rust -> Python bindings don't behave as expected.
The RustBinds object is created, but does not contain methods from the Rust target library.

Python Codebase

# main.py

from rustypy.rswrapper import bind_rs_crate_funcs
    
source_path = "/rust_code/"
compiled_lib = "/rust_code/target/debug/libsome_lib.so"
lib_binds = bind_rs_crate_funcs(source_path, compiled_lib, prefixes=[])

# AttributeError: 'RustBinds' object has no attribute 'python_bind_example'
print(lib_binds.python_bind_example())

Rust Codebase

// /rust_code/src/lib.rs

#[no_mangle]
pub extern "C" fn python_bind_example() -> Vec<i32> {
    vec![1,2,3]
}
# /rust_code/Cargo.toml
[package]
name = "rust_code"
version = "0.1.0"
authors = ["user"]
edition = "2018"

[lib]
name = "some_lib"
crate-type = ["cdylib"]

Tests

I've cloned rustypy, and run pytest from the root directory with the following output:

============================================================================================================ test session starts =============================================================================================================
platform darwin -- Python 3.7.6, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: /Users/craigfay/Repositories/rustypy
collected 0 items / 2 errors                                                                                                                                                                                                                 

=================================================================================================================== ERRORS ===================================================================================================================
__________________________________________________________________________________________________ ERROR collecting tests/test_py_to_rs.py ___________________________________________________________________________________________________
ImportError while importing test module '/Users/craigfay/Repositories/rustypy/tests/test_py_to_rs.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_py_to_rs.py:7: in <module>
    from rustypy.pywrapper import RustFuncGen
E   ModuleNotFoundError: No module named 'rustypy'
__________________________________________________________________________________________________ ERROR collecting tests/test_rs_to_py.py ___________________________________________________________________________________________________
ImportError while importing test module '/Users/craigfay/Repositories/rustypy/tests/test_rs_to_py.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_rs_to_py.py:7: in <module>
    from rustypy.rswrapper import Float, Double, Tuple
E   ModuleNotFoundError: No module named 'rustypy'
========================================================================================================== short test summary info ===========================================================================================================
ERROR tests/test_py_to_rs.py
ERROR tests/test_rs_to_py.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================================= 2 errors in 0.19s ==============================================================================================================
FVFYK1B6HV2H:rustypy craigfay$ 

Replication Steps

  • Debian GNU/Linux 10 (buster)
  • Python 3.7.3
  • rustc 1.41.0 (5e1a79984 2020-01-27)
  • cargo 1.41.0 (626f0f40e 2019-12-03)

You can reproduce the error in my my exact environment by cloning rustypy_debug and following instructions in its README.md.

If the documentation is misleading or this is a genuine bug, I'm happy to dig in and help with a PR.

Add generic support inside containers for calls to Python from Rust.

While a bit unorthodox maybe should contemplate adding support for use of generic "PyObjects" to use inside container types (like python lists) when interfacing with python from Rust.

What is blocking this is the implementation of the typing module prevents usage of generics in things like the List type.

One solution would be to add an own (lightweight) implementation of a List type like it was done with Tuple (was impossible to check the contained types of Tuple using the typing module implementation).

Python 3.7 typing module breaks container and generic type checking

Changes to the typing submodule in the std library break type checking for container types annotations like typing.List[A] or typing.Dict[K, V] due to the way those types are being constructed since the changes. Same happens to Generics...

A work around must be found and maintaining multiple version compatibility.

Unable to install the python package

$ uname
Darwin
$ python3 --version
Python 3.6.5
$ pip3 install rustypy
Collecting rustypy
  Using cached rustypy-0.1.15.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/ql/4rlmpby133l94mq01ltbscrm0000gp/T/pip-build-5xlrabyn/rustypy/setup.py", line 21, in <module>
        long_description = '\n' + convert(f, 'rst')
      File "/usr/local/lib/python3.6/site-packages/pypandoc/__init__.py", line 66, in convert
        raise RuntimeError("Format missing, but need one (identified source as text as no "
    RuntimeError: Format missing, but need one (identified source as text as no file with that name was found).

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/ql/4rlmpby133l94mq01ltbscrm0000gp/T/pip-build-5xlrabyn/rustypy/

Generate FFI calls procedurally

Since the library was initally developed a lot of new goodies have made it into the language and ecosystem, amongst them procedural macros, with this is possible to achieve a couple things:

  • Move from 'prefix based' annotation for func calls to attribute annotated func calls when discovering interfacing.
  • At compile time parse any function that requires interfacing without explicitly declaring the FFI wrapper and generate it on the flight (I believe PyO3 does something similar?).

Adding infrastructure for the latest would open more possibilities to handle more complex types (like nested structs) probably too, and the basics are there is librustypy already.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.