Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/ and http://code.google.com/p/ruby-perl/ , but they both seem rather outdated.
Has someone generated a Ruby interface for Python's C API?
Edit: Python can be integrated with many other languages according to http://wiki.python.org/moin/IntegratingPythonWithOtherLanguages . However, that list doesn't include Ruby.
My school (Georgia Tech), along with Bryn Mawr and Microsoft Research, are doing a project right now called Pyjama. Basically, it uses the Microsoft DLR to allow you to freely mix Python and Ruby. I haven't tried it, but it sounds pretty cool.
Here's an example from the website. You enter the class in "Python mode". Then it gets compiled, and you run the command in "Ruby mode".
class PythonClass:
def hello(self, value):
print "Python says hello to", value
pc = python_class().new
pc.hello "Ruby"
Which produces "Python says hello to Ruby".
Integrating dynamic languages is one of the goals of the Parrot project. It's a virtual machine that dynamic language compilers target. Once compiled to the same virtual machine, you should be able to used the "object" form in any of the languages no matter the object's source.
The issue at the moment, however, is stabilizing the virtual machine and finishing off the mostly done compilers. However, that's been the state for a long time. :)
You can write extensions for Ruby in C.
So, if Python has a C API, you can write a C extension for Ruby which uses this API.
I know nothing about the Python API or how large of a piece you want to integrate with, but if it is not too big, this could (possibly) give you a way to run Python code from Ruby.
For a research project I wanted to use the fabulous matplotlib that's available for Python. I also found that library that you referred to. However, it doesn't look like something popular and well tested. So I decided to write the script that generated graphs using pure Python and called it from Ruby via popen. That worked very well for me.
It might by possible, but not very practical. It would be significantly easier to port whatever modules you need from one to the other than it would be to embed one of the interpreters within the other.
If you absolutely have to use both languages in a project, your best option would probably the combination of Jython and Jruby, or IronPython and IronRuby. I'm not sure if you could get them to talk to each other, but at the very least you could host them on the same virtual machine.
Another strategy, as used by Facebook, is to expose APIs via Thrift. You define lightweight service APIs and the RPCs are inter-process.
Related
I want to know if there is a way to integrate a library written in Python into my Rails application. I have always used gems to implement outside libraries so I have no idea how to do this(yet).
Is it possible to use this Python library?
This is mostly what you want:
Calling Python from Ruby
I've looked into this question before and, excepting the Heroku deploy, the answer was "easily! check this out". (On a fun note, there's a gem to let you embed Perl code in a Ruby file)
However, while I can't seem to find it right now, I remember reading that deploying both to Heroku required a custom buildpac, since one won't normally include the binaries necessary for the other.
I need to send code to remote clients to be executed in them but security is a concern for me right now. I don't want unsafe code to be executed there so I would like to control what a program is doing. I mean for example, know if is making connections, where is connecting to, if is reading local files, etc. Is this possible with Python?
EDIT: I'm thinking in something similar to Android permission system. I want to know what a code will do and if it does something different, stop it.
You could use a different Python runtime:
if you run your script using Jython; you can exploit Java's permission system
with Pypy's sandboxed version you can choose what is allowed to run in your controller script
There used to be a module in Python called bastian, but that was deprecated as it wasn't that secure. There's also I believe something called RPython, but I don't know too much about that.
I would in this case use Pyro and write the code on the target server. That way you know clients can only execute written and tested code.
edit - it's probably worth noting that Pyro also supports http://en.wikipedia.org/wiki/Privilege_separation - although I've not had to use it for that.
I think you are looking for a sandboxed python. There used to be an effort to implement this, but it has been abolished a couple of years ago.
Sandboxed python in the python wiki offers a nice overview of possible options for your usecase.
The most rigourous (but probably the slowest) way is to run Python on a bare OS in an emulator.
Depending on the OS you use, there are several ways of running programs with restrictions, but without the overhead of an emulator:
FreeBSD has a nice integrated solution in the form of jails.
These grew out of the chroot system call.
Linux-VServer aims to do more or less the same on Linux.
As far as I understand Eclipse doesn't provide user with python bindings by default. Nor any projects of such kind was I able to find with google.
Are there any third-party plugins for that? Any tutorial? May be with Jython?..
As far as I know, you need to use Java. Eclipse is written in Java, and even the vanilla application is made up of several Java components glued together by the core plugin loader. Jython might work if:
you can cross-compile Python to Java bytecode (indeed you can, thanks to sayth for pointing that out), and
you can access the Eclipse APIs inside Jython.
So, here's more or less what your plugin's architecture might look like. If you can get at the Eclipse APIs, then you can write most of it in Jython, and then make a Java wrapper for it with the Embedding Jython instructions.
If you can't get the Eclipse functionality into your Jython, then you can still write some of your code in python, and then have the Eclipse API access happening on your Java layer. This will be annoying in proportion to how evenly split your code is between python and Java. I've worked on a project before where we embedded python into C++ (or it might have been the other way around...), and it's a major headache if you don't plan it out right.
I have searched a lot and I have understood that there exists inline::Python for putting in python code within Perl..
But I am looking for some means by which I can access modules and functions written in Perl by not writing any Perl code, through a python code.
Maybe, I am asking for too much?
I believe this is the sort of thing that the Parrot project aims to allow. It's a VM that's supposed to be able to run various dynamic languages, including Python and Perl. I've no idea how ready it is for real use, though, and I've never seen any instructions for people wanting to use Parrot, rather than develop it.
You could use Python's language services to parse Perl and generate a Python AST (with an appropriate FFI for any modules written in C), but I have not seen such an undertaking before.
I'm hoping to integrate Mercurial into my Rails site. I want to run basic commands like status, summary, log, and maybe even clone. I'd like to interface directly with the Mercurial libraries and avoid doing any command line parsing via regex.
Mercurial is written in Python; I am using Ruby. So, I need Mercurial Ruby bindings. It seems, however, that there are none. So, plan B would be to go with something like Ruby/Python (an extension library to embed the Python interpreter in Ruby) or rubypython (a C bridge between Ruby and Python with a Ruby interface).
Do you all see any reason why one of these libraries won't provide me what I am wanting?
Does anyone have any alternative ideas?
I would look at the redmine code, and do whatever they do.
So, I need Mercurial Ruby bindings. It seems, however, that there are none.
You are right. But there is something even better than a Ruby binding to the Python Mercurial implementation: a Ruby (plus little bits of C) Mercurial implementation!
Check out the Mercurial-Ruby gem, released by the team at Beanstalk.
https://github.com/iSabanin/mercurial-ruby