Hi all , I need to invoke python rutines from Pharo. I need some orientation about the best way to do it. TIA Ing. Pablo Digonzelli Software Solutions IP-Solutiones SRL |
Search the [pharo-dev] list for Ephestos by kilon. cheers -ben |
Hi there, I promised to do this a long time ago, but since you asked it I done it now. So as Ben said I am the author of Ephestos, a communication bridge between Blender and Pharo . To go directly to the how to . Ephestos is basically a socket bridge that send via sockets strings from pharo to python that then python executes as python commands. Ephestos is made so it works inside blender but I promised Atals a spin off project that allows the same socket bridge to be used as a standalone. To use do the following. 1) Get Ephestos , you can find it and install it with the configuration browser in your image in Pharo 3 and Pharo 4. Make sure you have a recent release though because I added it recently. 2) Get pyAtlas , this is the python side , you can get it from here --> https://github.com/kilon/pyAtlas 3) in your command line cd to the pyAtlas directory and execute : python3 pyAtlas.py 4) in Pharo you can now try any python code you want for example Ephestos sendMessage: 'print("hello world")'. Ephestos sendMessage: 'x = 3'. x := Ephestos getValue: 'x'. x inspect. Ephestos sendMessage: string, basically sends the python command to be executes while getValue: sends the command and returns a value as a string. you can use string 'exit' to close the socket bridge but this part is buggy as it seems to keep the binding of the sokcet active and I have to wait to clean it up in macos to reopen the bridge. You can also use pharo syntax and python errors will trigger the pharo debugger with a title the python error itself. You can find more information about Ephestos in my gitbook that can be read here Also I forgot to add that sendMessage can send multiline strings , so its possible to send python class definitions and other stuff, you type the string exactly as you would type python code respecting whitespaces. If you want to execute loads of lines of python code then it would be better to put your code in a python module and do Ephestos sendMessage: 'import mymodule' assuming your module is called 'mymodule' , python import basically are executions of code. If you have any questions just ask. Bare in mind this is a socket bridge so its not ideal for sending thousands of messages per second and you may run into the occasional bug or two which I will fix if you report it. Nonetheless it should allow you to execute any kind of code and not just call python functions or python methods. On Thu, Sep 25, 2014 at 7:40 PM, Ben Coman <[hidden email]> wrote:
|
a minor correction to the previous email its python3 pyatlas.py and not python3 pyAtlas.py also I forgot to make clear that it works for pyhton 2.7 and python 3. On Thu, Sep 25, 2014 at 8:11 PM, kilon alios <[hidden email]> wrote:
|
Yes , I was aware of the excellent work of kilon. I was hoping that this be the way to solve my issue. Thanks kilon, I will follow your instructions and comment the results into the list. Ing. Pablo Digonzelli Software Solutions IP-Solutiones SRL De: "kilon alios" <[hidden email]> Para: "Any question about pharo is welcome" <[hidden email]> Enviados: Jueves, 25 de Septiembre 2014 14:13:34 Asunto: Re: [Pharo-users] invoking python from pharo a minor correction to the previous email its python3 pyatlas.py and not python3 pyAtlas.py also I forgot to make clear that it works for pyhton 2.7 and python 3. On Thu, Sep 25, 2014 at 8:11 PM, kilon alios <[hidden email]> wrote:
|
Its far from excellent. Its not as tested as I want it to be, and the code could be much better but it works and makes interfacing with python code very easy. Its also an ongoing project that I will keep adding feature to , for example I would like to extend pharo syntax to more complex stuff than calling python methods like defining python classes etc so you wont have to use sendMessage and getValue at all and not have to write a line of python code. In short do all your python coding using 100% pharo syntax. But that will take a lot of time to do because it will require a fully python syntax parser. I have updated the code to resolve the error when issuing a command to close the bridge with Ephestos sendMessage:'exit'. This command basically terminate pyAtlas and closes it server socket. I dont know if its Pharo or Python or Macos but it looks like it takes time to free up the socket address so you will need 20 seconds to restart pyAtlas again. I tried to set the timeout of the socket to 1 second but it looks to me it still uses the default 20 seconds timeout. I guess 20 sec is not that bad for a pre alpha software :D But anyway that should not be a problem since you will have to rerun pyatlas every 20 sec , which is something you would not want to do . I was actually planning to test Ephestos with pyQT and pyCuda and make a youtube video about it but have not found the time yet. Probably in the weekend. On Thu, Sep 25, 2014 at 9:23 PM, Pablo R. Digonzelli <[hidden email]> wrote:
|
Excellent, I will waiting ... Ing. Pablo Digonzelli Software Solutions IP-Solutiones SRL De: "kilon alios" <[hidden email]> Para: "Any question about pharo is welcome" <[hidden email]> Enviados: Jueves, 25 de Septiembre 2014 16:01:08 Asunto: Re: [Pharo-users] invoking python from pharo Its far from excellent. Its not as tested as I want it to be, and the code could be much better but it works and makes interfacing with python code very easy. Its also an ongoing project that I will keep adding feature to , for example I would like to extend pharo syntax to more complex stuff than calling python methods like defining python classes etc so you wont have to use sendMessage and getValue at all and not have to write a line of python code. In short do all your python coding using 100% pharo syntax. But that will take a lot of time to do because it will require a fully python syntax parser. I have updated the code to resolve the error when issuing a command to close the bridge with Ephestos sendMessage:'exit'. This command basically terminate pyAtlas and closes it server socket. I dont know if its Pharo or Python or Macos but it looks like it takes time to free up the socket address so you will need 20 seconds to restart pyAtlas again. I tried to set the timeout of the socket to 1 second but it looks to me it still uses the default 20 seconds timeout. I guess 20 sec is not that bad for a pre alpha software :D But anyway that should not be a problem since you will have to rerun pyatlas every 20 sec , which is something you would not want to do . I was actually planning to test Ephestos with pyQT and pyCuda and make a youtube video about it but have not found the time yet. Probably in the weekend. On Thu, Sep 25, 2014 at 9:23 PM, Pablo R. Digonzelli <[hidden email]> wrote:
|
have you tried Ephestos ? does it work for you ? do you like the way it works ? what you want to do with it ? I would appreciate some feedback. It does work well for me so far, but of course I want to read other people's opinion about it. I want to make it very easy for pharoers to port python libraries to pharo and mix pharo and python code or why not even support other languages. For example this morning I was looking at Meteor.js which is working similarly to Ephestos in the sense it uses a socket to send data from client to server that then server uses that data to update the webpage, it means that javascript can code this way in a live coding workflow web apps and web pages. Of course Meteor.js is far more sophisticated with database support, template support, authorisation and much more. On Thu, Sep 25, 2014 at 11:26 PM, Pablo R. Digonzelli <[hidden email]> wrote:
|
In reply to this post by kilon.alios
kilon alios wrote:
> Hi there, I promised to do this a long time ago, but since you asked it > I done it now. > > So as Ben said I am the author of Ephestos, a communication bridge > between Blender and Pharo . > > To go directly to the how to . Ephestos is basically a socket bridge > that send via sockets strings from pharo to python that then python > executes as python commands. > > Ephestos is made so it works inside blender but I promised Atals a spin > off project that allows the same socket bridge to be used as a > standalone. To use do the following. > > 1) Get Ephestos , you can find it and install it with the configuration > browser in your image in Pharo 3 and Pharo 4. Make sure you have a > recent release though because I added it recently. > > 2) Get pyAtlas , this is the python side , you can get it from here > --> https://github.com/kilon/pyAtlas > > 3) in your command line cd to the pyAtlas directory and execute : > python3 pyAtlas.py > > 4) in Pharo you can now try any python code you want > > for example > > Ephestos sendMessage: 'print("hello world")'. > Ephestos sendMessage: 'x = 3'. > x := Ephestos getValue: 'x'. > x inspect. > > Ephestos sendMessage: string, basically sends the python command to be > executes while getValue: sends the command and returns a value as a string. > > you can use string 'exit' to close the socket bridge but this part is > buggy as it seems to keep the binding of the sokcet active and I have to > wait to clean it up in macos to reopen the bridge. > > You can also use pharo syntax and python errors will trigger the pharo > debugger with a title the python error itself. > > You can find more information about Ephestos in my gitbook that can be > read here > > https://www.gitbook.io/book/kilon/ephestos > > Also I forgot to add that sendMessage can send multiline strings , so > its possible to send python class definitions and other stuff, you type > the string exactly as you would type python code respecting whitespaces. > If you want to execute loads of lines of python code then it would be > better to put your code in a python module and do > > Ephestos sendMessage: 'import mymodule' > > assuming your module is called 'mymodule' , python import basically are > executions of code. > > If you have any questions just ask. > > Bare in mind this is a socket bridge so its not ideal for sending > thousands of messages per second and you may run into the occasional bug > or two which I will fix if you report it. Nonetheless it should allow > you to execute any kind of code and not just call python functions or > python methods. > > > > On Thu, Sep 25, 2014 at 7:40 PM, Ben Coman <[hidden email] > <mailto:[hidden email]>> wrote: > > __ > Pablo R. Digonzelli wrote: >> Hi all , I need to invoke python rutines from Pharo. I need some >> orientation about the best way to do it. >> TIA >> >> **** >> ------------------------------------------------------------------------ >> *Ing. Pablo Digonzelli* >> Software Solutions >> IP-Solutiones SRL >> Metrotec SRL >> 25 de Mayo 521 >> Email: [hidden email] >> <mailto:[hidden email]> >> [hidden email] <mailto:[hidden email]> >> Cel: 5493815982714 > > Search the [pharo-dev] list for Ephestos by kilon. > cheers -ben > > I was going to say... "invoking python from Pharo" with Ephestos/Atlas would make a good chapter for Pharo For The Enterprise, but that book is actually pretty full. With other things like OSWindow and SDL coming along, I wonder if there might be a new book called "Phoreign Pharo" to accumulate solutions to access the world outside the Image. cheers -ben |
well in my case that wont be necessary since Ephestos has its own book and I will keep documenting the more features I add. I am also thinking of dropping external documentation and bringing it inside the image. If PFTE is near completion then most likely will be a next book but I decided to concentrate more on my own project . I started ambitious with this project but now I want to make something smaller, easier and more practical for my personal needs as a 3d artist. On Fri, Sep 26, 2014 at 4:58 PM, Ben Coman <[hidden email]> wrote: kilon alios wrote: |
In reply to this post by kilon.alios
I would use only the Python bridge but not the Blender features (Cube, etc). Will be the Python bridge and parser contained in its own package? I have started from MinGW and evaluatedEphestos sendMessage: 'print("hello world")'. Ephestos sendMessage: 'x = 3'. Ephestos getValue: 'x'. $ python pyAtlas.py creating thread calling create_socket_connection hello world ('pherror : ', ['', 'no error\n']) I have sent err : --->no error <---- and removed it from the list of errors ('pherror : ', ['', 'no error\n']) I have sent err : --->no error <---- and removed it from the list of errors ('eval with pherror: ', ['', 'RetValue:3']) ('pherror : ', ['', 'RetValue:3']) I have sent err : --->RetValue:3 <---- and removed it from the list of errors Is this expected? I don't know if there are other reasons but you could download the raw .py file from https://raw.githubusercontent.com/kilon/pyAtlas/master/pyatlas.py using Metacello Configuration and start the script using OSProcess or ProcessWrapper. This is how I do it for BioSmalltalk: >>... spec for: #'common' do: [ spec blessing: #'baseline'. spec preLoadDoIt: #preLoad. >>preLoad | urlIndex | urlIndex := 1. [ self downloadFiles: urlIndex ] on: ZdcPluginMissing do: [ : ex | urlIndex := urlIndex + 1. ex retry ]. >>downloadFiles: urlIndex | url response | url := (self platformFilesUrl at: urlIndex) asZnUrl. fileRef := FileSystem disk workingDirectory / url pathSegments last. (response := ZnEasy get: url) isSuccess ifTrue: [ fileRef writeStreamDo: [ : stream | stream nextPutAll: response contents ] ] ifFalse: [ self error: 'Cannot download files' ] >>platformFilesUrl " Answer a <Collection> of download URLs for the current platform " ^ Smalltalk os isWin32 ifTrue: [ #('http://...zip' 'http://...zip') ] ifFalse: [ #('http://....tar.gz' 'http://....tar.gz') ]. Cheers, Hernán 2014-09-25 14:11 GMT-03:00 kilon alios <[hidden email]>:
|
Everything you done is correct. all this information you see in your terminal is debugging of error reporting. Python errors are send back to Pharo and trigger pharo debugger. So yes everything you see is to be expected. I use it to check that everything goes as planned with python execution. if you want to disable it just do the following Ephestos sendMessage: 'alogging = False'. It will stop typing / logging all this info and instead print what you want to print. Your can turn it back to true of course pyAtlas runs the python side as standalone so there is no need to use Blender , pyAtlas works both with py 2.7 and python 3 thanks for the information on how to download the py on the go. I will definetly integrate it. On Fri, Oct 3, 2014 at 10:40 PM, Hernán Morales Durand <[hidden email]> wrote:
|
Free forum by Nabble | Edit this page |