|
View:
New views
11 Messages
—
Rating Filter:
Alert me
|
|
|
Anjuta Python Ethics & AdviceSo for my Bazaar plugin I am needing to run Python commands. This Python stuff is all new to me so I need some advice.
Ideally what I would like to do is whenever the project is in a working Bazaar directory I would grab what Bazaar calls a "WorkingTree" PyObject* to pass to all of the other commands like add and remove. I would do this during the the plugin activation. --------------------------------------------- Py_Initialize(); //Store PyObject* "Working Directory" in the plugin to pass to other commands. Py_Finalize(); //Then when an add command happens Py_Initialize(); //Pass in the stored PyObject* from above into the add function Py_Finalize(); //This won't work. My guess is that (I don't know Python terminology) the PyObject doesn't refer to the right thing after running Py_Finalize() then later Py_Initialize() --------------------------------------------------- There is two options I know of that will work, neither of which seems like the right thing to do. First is Py_Initialize on plugin activation and Py_Finalize on deactivation. Leaving it open the entire time. Secondly is just every time I run a command (add, remove, etc) open up the "WorkingTree" object fresh again. Again I don't know anything about Python but the first method seems like it would maybe screw up any one else running Python. The second method seems overkill. So essentially if any of you have Python experience and have advice on either a way of getting the method of storing the PyObject* in the plugin to work or anything really please let me know. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceHi William,
William Fagan a écrit : > //This won't work. My guess is that (I don't know Python terminology) > the PyObject doesn't refer to the right thing after running > Py_Finalize() then later Py_Initialize() Right, as I understand it, all python objects are meaningless after calling Py_Finalize. > First is Py_Initialize on plugin activation and Py_Finalize on > deactivation. Leaving it open the entire time. I think, it is supposed to be used like that most of the time. The current python loader plugin (the plugin which allow to load other plugins written in Python) is doing it like this. Py_Initialize is called on plugin activation and Py_Finalize is never called. If several plugins call Py_Initialize and Py_Finalize, we need at least to check that it's working fine whatever is the plugin loading order. I think that if you only use Py_Initialize, it should be fine, the first plugin initialize python and Py_Initialize is no-op for the next plugin. > Secondly is just every time I run a command (add, remove, etc) open up > the "WorkingTree" object fresh again. I don't really know how much time is needed by Py_Initialize, Py_Finalize and the opening of a new WorkingTree but I would rather choose the first solution. Another possibility is to write your whole plugin in Python. If you already know Python, you will probably have to improve the bindings though. Regards, Sébastien ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceYou can use Py_IsInitialized() to check if the interpreter was not initialized yet.
But, I agree with Seb, the best approach is to write the plugin entirely in python, so you can avoid these kind of problems. _Never_ Py_Finalize(), as it'll break all the other plugins On Fri, May 16, 2008 at 1:44 PM, Sébastien Granjoux <seb.sfo@...> wrote: Hi William, -- Fabio Rafael da Rosa fabiorafael.rosa@... ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceHi William!
Sorry, I don't know much about python but why do you want to ues PyObjects? Is there some special bzr python library? The usual case would be to use the bzr commmand line tool through AnjutaLauncher. Check the cvs plugin for a very simple and limited approach. Regards, Johannes Am Donnerstag, den 15.05.2008, 20:30 -0500 schrieb William Fagan: > So for my Bazaar plugin I am needing to run Python commands. This > Python stuff is all new to me so I need some advice. > > Ideally what I would like to do is whenever the project is in a > working Bazaar directory I would grab what Bazaar calls a > "WorkingTree" PyObject* to pass to all of the other commands like add > and remove. I would do this during the the plugin activation. > > --------------------------------------------- > Py_Initialize(); > //Store PyObject* "Working Directory" in the plugin to pass to other > commands. > Py_Finalize(); > > //Then when an add command happens > Py_Initialize(); > //Pass in the stored PyObject* from above into the add function > Py_Finalize(); > > //This won't work. My guess is that (I don't know Python terminology) > the PyObject doesn't refer to the right thing after running > Py_Finalize() then later Py_Initialize() > --------------------------------------------------- > > There is two options I know of that will work, neither of which seems > like the right thing to do. > First is Py_Initialize on plugin activation and Py_Finalize on > deactivation. Leaving it open the entire time. > Secondly is just every time I run a command (add, remove, etc) open up > the "WorkingTree" object fresh again. > > Again I don't know anything about Python but the first method seems > like it would maybe screw up any one else running Python. > The second method seems overkill. > > So essentially if any of you have Python experience and have advice on > either a way of getting the method of storing the PyObject* in the > plugin to work or anything really please let me know. > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceOn Sat, 2008-05-17 at 02:00 +0200, Johannes Schmid wrote:
> > The usual case would be to use the bzr commmand line tool through > AnjutaLauncher. Check the cvs plugin for a very simple and limited > approach. If you want to go this route, my Git plugin would probably be a better example, as it's a lot more extensible and works and acts a lot like the Subversion plugin. James ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceThey actually have a nice Python Bazaar library but that isn't the reason I took that route. The reason I am using the PyObject approach is...
1) The guys/girls in the #bzr channel suggested that approach (not knowing about the AnjutaLauncher) 2) I didn't know about the AnjutaLauncher thing. So it was just the first route I had to explore. I haven't taken a look at the AnjutaLauncher yet to see if it will do what I would like but it just might. My worries about that approach is it seems to me that if I were to run a command that lists all of the files that were versioned for example, they would all be printed to stdout. Which works but I have some gui's set up to try and give the user some more control. For example on a remove command I show a Gtk tree view showing all of the files applicable to be removed, which they can then select which they want to remove. So I need a little more control which the bzr library gives me. Using C routines on a python library was odd at first but I have put most of it in routines so it is pretty easy for me to use them now. For example this is what I am having to have to do to call the python bzr library in C... ps_module_name = PyString_FromString( "bzrlib.bzrdir" ); module = PyImport_Import( ps_module_name ); dictionary = PyModule_GetDict( module ); bzrdir_class = PyDict_GetItemString( dictionary, "BzrDir" ); bzrdir = PyObject_CallMethod( bzrdir_class, "open", "s", location ); All that returns an instance of a BzrDir class, then all I have to do is call methods on the directory like... py_status = PyObject_CallMethod( bzrdir, "has_branch", NULL ); which isn't so bad once I got the hang of it. I will definitly take a look at the CVS and Git plugins to explore the AnjutaLauncher more. Also if anyone sees me taking a dead end ever on here please let me know, the Anjuta environment and this Python integration is new to me. Thanks, Will On Fri, May 16, 2008 at 7:11 PM, James Liggett <jrliggett@...> wrote:
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceOn Fri, 2008-05-16 at 20:11 -0500, William Fagan wrote:
> They actually have a nice Python Bazaar library but that isn't the > reason I took that route. The reason I am using the PyObject approach > is... > 1) The guys/girls in the #bzr channel suggested that approach (not > knowing about the AnjutaLauncher) > 2) I didn't know about the AnjutaLauncher thing. > > So it was just the first route I had to explore. To tell you the truth I think I would try to make the library work if I were you. Fall back to interfacing with the command-line client as a last resort. I say this because libraries tend to be better suited to these sorts of things and are usually less work in the long run. With git I know I'm going to have problems with the differences in output between different git versions. Add to that git also does some strange things with standard error in an inconsistent way, like reporting non-error status messages and progress. Dealing with such idiosyncrasies is becoming a royal pain. ;-) That said, I think I would try to wrap these calls in a GObject class, like I did with the Subversion plugin. In fact, you could use AnjutaCommand as your base and probably borrow a lot of UI code verbatim from that plugin. Just like I do with SVN, you can take all of the common things, like that library import and dictionary lookup stuff, and put it in a base class, and derive from there to make all this stuff automatic. The only thing is that AnjutaCommand is totally undocumented, which is entirely my fault, as I never did get around to doing this when I first wrote it. Just ask and I'll help you through it. And I'll document it soon--I promise. :) And, if you do decide to use AnjutaLauncher instead, note that it will not put your stuff on stdout. What usually happens in situations where you work with another process is that the output of the program you're running is exposed to you through a one-way mechanism called a pipe. You can get pipes for standard output and standard error for reading its output, and standard input for writing (giving input) to a process. Programs normally read and write the information from the pipe like it's a file. AnjutaLauncher handles all of this for you, and gives you output from your process in a callback which you specify when you execute your "child" process. It also runs your child asynchronously, so Anjuta won't block while it's running. So don't worry; you have total control over what you do what what Bazaar gives you. I hope this helps. And I know the learning curve is a little rough if you're brand new to stuff like this. If we see that you're not doing something right, we'll be sure to set you straight. And we'll gladly help you with whatever problems you might have. Not so long ago I was in your position, and the people here were very helpful to me when I got started. So don't worry; you're in good hands. :-) James ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceWhen I started out I essentially had a copy of the subversion plugin then started slowly going through the code figuring out what everything does. Piece by piece switching out the svn stuff with bzr stuff. So if you were to look at my code you would see a lot of similarities. I am using the AnjutaCommand but wasn't quite sure what it exactly does or is capable of doing. It seems to me that it was a way to have Anjuta run the command whenever it got the chance. So the IDE could continue no matter how long the command took. I know for a fact whether I have a good idea of what it does or not that I am not using it to its full potential. So thank you James, without your Subversion plugin I would be entirely lost.
I'm glad to know that I have a backup plan with the AnjutaLauncher if it comes to that. Luckily I am getting the hang of the Bazaar Python library because it is giving me a lot more functionality. A couple issues that I have came across once I started using the Python library is that when I run Anjuta from the command line I am unable to close with Ctrl-C. Also the Recent Project selector sometimes wouldn't work. I was thinking it had something to do with leaving Python up since we can't close it. This was all just stuff I came across the end of last week and haven't had much time to experiment and get the actual cause. I will see what I come up with this week. Also everyone has been a great. I know I have already hit up a few people on IRC for help. Thanks Will On Fri, May 16, 2008 at 10:37 PM, James Liggett <jrliggett@...> wrote:
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceOn Sun, 2008-05-18 at 23:42 -0500, William Fagan wrote:
> When I started out I essentially had a copy of the subversion plugin > then started slowly going through the code figuring out what > everything does. Piece by piece switching out the svn stuff with bzr > stuff. So if you were to look at my code you would see a lot of > similarities. I am using the AnjutaCommand but wasn't quite sure what > it exactly does or is capable of doing. It seems to me that it was a > way to have Anjuta run the command whenever it got the chance. So the > IDE could continue no matter how long the command took. I know for a > fact whether I have a good idea of what it does or not that I am not > using it to its full potential. So thank you James, without your > Subversion plugin I would be entirely lost. thread to probe it to see if it's done or there's data to be handled when it has the chance. It doesn't wait to start the command at all though. You should probably be thanking and maligning me at the same time though, as the fact that you're not understanding the AnjutaCommand system as well as you may need to is my fault, because I'm too busy/lazy to document it. :( Basically, I designed this system to standardize as much as possible the process of interfacing with external components, like libraries and programs. The idea is to hide as much as possible the inner workings and the dirty work of doing a certain task, like committing to a Bazaar repository. In effect, the UI code (the code that uses the command objects to do some job) shouldn't know anything at all about the whole python bit, or even that there's a thread or anything else involved here. In some cases, you can automate and hide some of this stuff from individual commands themselves. I use this paradigm to hide the AnjutaLauncher from my git commands; the fact that AL is even involved is a non-consideration when I implement new commands or extend existing ones. In your case, I think you're using AnjutaAsyncCommand, so the idea is to hide the thread. Aside from the locking, you don't have to worry about the thread at all. As for its "potential," I made it a point to assume as little as I could about what it would be used for. In essence, you, as the programmer that uses it, gets to decide what you do with it and how you do it. Maybe that's more power than you need, but in that case I'm sure AnjutaAsyncCommand alone should do most of what you need. For your BZR specific stuff, derive from this class and put it in there, as I did with the SVN plugin. Then derive your command objects from this class, and implementing stuff should be really easy from that point. Sorry if this seems overly generic or otherwise doesn't really help much. I think it might help if I could see your code. Do you have it on the Internet someplace? It'd also help if I could see your proposal too, so I can see where you're going with this. Knowing what you're doing, what you want to do, and how you'll get there will put things into perspective for me so I can give you better and more targeted advice. I can also help you plan/design your command setup if you'd like. Thanks, James ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceHi William,
William Fagan a écrit : > A couple > issues that I have came across once I started using the Python library > is that when I run Anjuta from the command line I am unable to close > with Ctrl-C. I think, I get the same thing when the python debugger is loaded so it probably comes from the Python library initialization. We probably need to check if we can avoid this. Regards, Sébastien ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
|
|
Re: Anjuta Python Ethics & AdviceI was using the Commands purely for hiding the Bazaar Python stuff from my UI code because that is what it was looking like you were doing with the svn plugin. I didn't realize it was taking care of the threading too which is a very, very pleasent surprise. Thanks for going over an explanation of what it does because I was treating is as a black box.
I currently don't have it online yet. I really need to though. By the end of the weak I plan on having my code fairly straightforward so I will try and find a place online to host it so I can more easily get help from everybody when needed.
If I come up with any solution to the Python library initialization I will make sure and post it on here.
Thanks, Will
On Mon, May 19, 2008 at 12:27 PM, Sébastien Granjoux <seb.sfo@...> wrote:
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Anjuta-devel mailing list Anjuta-devel@... https://lists.sourceforge.net/lists/listinfo/anjuta-devel |
| Free Forum Powered by Nabble | Forum Help |