iduartgomez / rustypy Goto Github PK
View Code? Open in Web Editor NEWAutomatic FFI and binding generation for Python <-> Rust interfacing
License: BSD 3-Clause "New" or "Revised" License
Automatic FFI and binding generation for Python <-> Rust interfacing
License: BSD 3-Clause "New" or "Revised" License
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:
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.
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.
# 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_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"]
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$
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.
$ 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/
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.
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).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.