Thread: Re: [Pydev-code] Getting started with PyDev scripting
Brought to you by:
fabioz
From: Joel H. <yo...@if...> - 2006-04-13 13:38:55
Attachments:
pyedit_assign_params_to_attributes.py
|
Hi! I've cooked up a new version of my 'Assign method parameters to attributes of self' script. This one should be saner, neater, more helpful, and respectful of indent. I'm still very thankful for any hints or comments regarding anything in this code. I also have a few questions: 1) Is there some way of detecting whether or not there's a syntax error on the current line at sript execution? In the current form my script will happily propagate syntax errors from the def line, e.g: class moo: def cow(self, 1): (gives self.1 = 1 on execution) 2) Is there a bug in getInsideParentesisToks? If called with the string "(foo,)" then (the equivalent of) ['foo'] is returned. If called with the string "(foo, )" then (the equivalent of) ['foo', ''] is returned. The input values are equivalent in python, so shouldn't the returned values be equal? The reason I ask is related to my comment at line 71 in my attached script: # This can happen with legal def lines such as "def moo(self, ):" 3) Right now my script activates on "Ctrl-2" followed by "a<Enter>". I think what we initially discussed was having this as "Ctrl-2" followed by "a", which just requires swapping the True at the final line for a False. Which one should I use? The latter seems more convenient for me right now, but using it makes it impossible to execute other scripts whose names begin with "a". Is there an easy way for users to rebind script names to their needs? Who decides which script should have what name? Anyway, I'm really starting to like this pydev scripting thing. This'll be good, I'm sure. :-) Take care! /Joel Hedlund |
From: Don T. <nos...@gm...> - 2006-04-15 01:30:18
|
Joel Hedlund wrote: > Hi! > > I've cooked up a new version of my 'Assign method parameters to > attributes of > self' script. Hi Joel: I installed and played a little with your script - looking good. Since I am congenitally unable to accept any compiler error messages I changed the initial guard block from: if False: from org.python.pydev.editor import PyEdit #@UnresolvedImport cmd = 'command string' editor = PyEdit to: if False: #@UndefinedVariable # None of this code will be executed, but it will stop Pydev # extensions from complaining about undefined variables. cmd = cmd #@UndefinedVariable editor = editor #@UndefinedVariable document = document #@UndefinedVariable False = False #@UndefinedVariable True = True #@UndefinedVariable Note that bogus document = document assignment and that I have dropped the bogus import statement and used a bogus assignment for editor. At least there is only one trick being used here to resolve all of these undefined variables. Fabio: is this OK? Don. |
From: Fabio Z. <fa...@gm...> - 2006-04-16 21:48:20
|
> > document =3D document #@UndefinedVariable > False =3D False #@UndefinedVariable > True =3D True #@UndefinedVariable > > Note that bogus document =3D document assignment and that I have dropped > the bogus import statement and used a bogus assignment for editor. At > least there is only one trick being used here to resolve all of these > undefined variables. > > Fabio: is this OK? Actually, I think that putting the True/False to be recognized as globals i= n the preferences would be better... And the document should actually be: document =3D editor.getDocument() -- it is there because of 'leftovers' fro= m other notifications. Cheers, Fabio |
From: Joel H. <yo...@if...> - 2006-04-19 07:40:05
Attachments:
pyedit_assign_params_to_attributes.py
|
Hi! New version of my script here. This time I feel it's good enough to call an alpha (comments still appreciated, of course). > I installed and played a little with your script - looking good. Thanks! > Since I am congenitally unable to accept any compiler error messages :-) > document = document #@UndefinedVariable If I used a global variable named 'document' in my previous version it was most likely because of involuntary namespace pollution, and I hope the new version is free of it. Thanks for your time checking my script out! /Joel Hedlund |
From: Fabio Z. <fa...@gm...> - 2006-04-19 10:50:58
|
Hi Joel, very nice!! Didn't find any problems this time... checked with docstrings, kwargs, defaults, end of doc, etc. The only observation is that code-analysis complained about an unused variable -- the first sCurrentLine =3D oSelection.getCursorLineContents(), = in the run method, as you make the same assignment some lines below before using it again. So, what do you (all) think about which would be the best way to make those scripts available... I was thinking something as putting them (with the authors permission) toghether with the pydev distribution... The authors name would then appear on the script itself and in a brief help in the homepage toghether with an explanation on how the script works. Joel: what do you think about showing as the first script in that list? ;-) Cheers, Fabio On 4/19/06, Joel Hedlund <yo...@if...> wrote: > > Hi! > > New version of my script here. This time I feel it's good enough to call > an > alpha (comments still appreciated, of course). > > > I installed and played a little with your script - looking good. > > Thanks! > > > Since I am congenitally unable to accept any compiler error messages > > :-) > > > document =3D document #@UndefinedVariable > > If I used a global variable named 'document' in my previous version it wa= s > most > likely because of involuntary namespace pollution, and I hope the new > version > is free of it. > > Thanks for your time checking my script out! > /Joel Hedlund > > > |
From: Joel H. <yo...@if...> - 2006-04-19 11:58:22
|
Hi! > Didn't find any problems this time... checked with docstrings, kwargs, > defaults, end of doc, etc. Cool. :-) > The only observation is that code-analysis complained about an unused > variable -- the first sCurrentLine = oSelection.getCursorLineContents(), in > the run method, as you make the same assignment some lines below before > using it again. Ok. The first one is a leftover of sorts. I've deleted it now. Thanks for pointing me to it! Let's give it a few days to let people (Don?) speak their minds before I post the definitive v1.0.0 to the list? > So, what do you (all) think about which would be the best way to make those > scripts available... I was thinking something as putting them (with the > authors permission) toghether with the pydev distribution... > The authors name would then appear on the script itself and in a brief help > in the homepage toghether with an explanation on how the script works. Seems like an excellent idea. > Joel: what do you think about showing as the first script in that list? ;-) Fine by me. :-) Fabio Zadrozny wrote: > Hi Joel, very nice!! > > Didn't find any problems this time... checked with docstrings, kwargs, > defaults, end of doc, etc. > The only observation is that code-analysis complained about an unused > variable -- the first sCurrentLine = oSelection.getCursorLineContents(), in > the run method, as you make the same assignment some lines below before > using it again. > > So, what do you (all) think about which would be the best way to make those > scripts available... I was thinking something as putting them (with the > authors permission) toghether with the pydev distribution... > The authors name would then appear on the script itself and in a brief help > in the homepage toghether with an explanation on how the script works. > > Joel: what do you think about showing as the first script in that list? ;-) > > Cheers, > > Fabio > > On 4/19/06, Joel Hedlund <yo...@if...> wrote: > >>Hi! >> >>New version of my script here. This time I feel it's good enough to call >>an >>alpha (comments still appreciated, of course). >> >> >>>I installed and played a little with your script - looking good. >> >>Thanks! >> >> >>>Since I am congenitally unable to accept any compiler error messages >> >>:-) >> >> >>> document = document #@UndefinedVariable >> >>If I used a global variable named 'document' in my previous version it was >>most >>likely because of involuntary namespace pollution, and I hope the new >>version >>is free of it. >> >>Thanks for your time checking my script out! >>/Joel Hedlund >> >> >> > > |
From: Don T. <nos...@gm...> - 2006-04-24 16:09:52
|
Fabio Zadrozny wrote: > > Actually, I think that putting the True/False to be recognized as > globals in the preferences would be better... Hmmm... By this I think that you mean: Window -> Preferences -> Pydev Extensions -> Undefined and then in "Consider the following names as globals: ": "_, True, False" This certainly works but unless Pydev extensions makes this the default setting you are depending upon everybody updating this entry if they want to get rid of these error messages. Then, if they happen to be using Python 2.3 which does not define True and False, Pydev extensions would miss genuinely undefined True/False. Not a big deal, I suppose, but what do you think of using: try: True, False #@UndefinedVariable except NameError: (True, False) = (1, 0) Don. |
From: Joel H. <yo...@if...> - 2006-04-19 12:07:20
|
Hi! Is there a way of determining the pydev version from within a pydev Jython script? That could provide cleaner code for bug workarounds, I think. For example, if you'd see something like this in a script: if version < (1,0,6): do_strange_and_possibly_conditional_stuff you'd probably not get confused by the strange stuff since it quite obviously is a workaround for problems in earlier versions. Cheers! /Joel |
From: Fabio Z. <fa...@gm...> - 2006-04-19 15:15:11
|
> > Is there a way of determining the pydev version from within a pydev Jytho= n > script? Humm, I'm not sure about the 'correct' way to do this, but I guess you coul= d do that from the install dir... >>from org.python.pydev.plugin import PydevPlugin #@UnresolvedImport >>p =3D PydevPlugin.getDefault() >>print p.getBundle().getLocation() update@plugins/org.python.pydev_1.0.5.1/ That could provide cleaner code for bug workarounds, I think. > > For example, if you'd see something like this in a script: > > if version < (1,0,6): > do_strange_and_possibly_conditional_stuff > > you'd probably not get confused by the strange stuff since it quite > obviously > is a workaround for problems in earlier versions. > > Cheers! > /Joel > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting > language > that extends applications into web and mobile media. Attend the live > webcast > and join the prime developer group breaking into this new coding > territory! > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D110944&bid=3D241720&dat= =3D121642 > _______________________________________________ > pydev-code mailing list > pyd...@li... > https://lists.sourceforge.net/lists/listinfo/pydev-code > |
From: Joel H. <yo...@if...> - 2006-04-19 12:29:54
|
Hi! Would it be a good idea to add the "location of additional jydev scripts" to the PYTHONPATH for pydev jython scripts by default? That way it would be easier to put commonly used functionality for pydev scripting (such as your jython dir utils) in their own modules. This is my sys.path in pydev jython scripts: ['.', '/usr/local/lib/eclipse/plugins/org.python.pydev.jython_1.0.4/Lib', '/usr/local/lib/eclipse/plugins/org.python.pydev.jython_1.0.4/jysrc'] '.' in this case is my home dir. Cheers! /Joel Hedlund |
From: Fabio Z. <fa...@gm...> - 2006-04-19 16:27:28
|
On 4/19/06, Joel Hedlund <yo...@if...> wrote: > > Hi! > > Would it be a good idea to add the "location of additional jydev scripts" > to > the PYTHONPATH for pydev jython scripts by default? That way it would be > easier > to put commonly used functionality for pydev scripting (such as your > jython dir > utils) in their own modules. > > This is my sys.path in pydev jython scripts: > ['.', '/usr/local/lib/eclipse/plugins/org.python.pydev.jython_1.0.4/Lib', > '/usr/local/lib/eclipse/plugins/org.python.pydev.jython_1.0.4/jysrc'] Sure... could you open a 'bug' for that, so that I don't forget to do it when I do get up to the point of doing it? Cheers, Fabio |
From: Joel H. <yo...@if...> - 2006-04-19 12:53:22
|
Hi! From my assign params to attribs script: # 'onSave' can be added to the list for developing purposes. if cmd in ['onCreateActions', 'onSave']: declare_lots_of_variables_and_stuff Using 'onSave' in this manner isn't terribly clever, is it? Say that I delclare a variable and use it in a bunch of places, save and run and discover an error. Say that in the process of fixing the error I change the variable, but forget to change it *everywhere*. When I save and retry, the error may seem to be fixed, because the old value is still in memory and does not cause a NameError or such until I restart the editor. Or is there something that I missed? The reason I added 'onSave' for development is pure laziness. It's quicker to save-to-update than to restart-to-update. Is there an easy way of provoking an editor restart in eclipse/pydev, so that the scripting namespace is cleared? As you already have pointed out, I should take care not to mess around with globals and to be careful to not use stuff imported to other scripts, but is there anything else I should do to avoid this pitfall that I seem to fall into again and again? Thanks a bunch for your help! Take care! /Joel Joel Hedlund wrote: > Hi! > > Would it be a good idea to add the "location of additional jydev scripts" to > the PYTHONPATH for pydev jython scripts by default? That way it would be easier > to put commonly used functionality for pydev scripting (such as your jython dir > utils) in their own modules. > > This is my sys.path in pydev jython scripts: > ['.', '/usr/local/lib/eclipse/plugins/org.python.pydev.jython_1.0.4/Lib', > '/usr/local/lib/eclipse/plugins/org.python.pydev.jython_1.0.4/jysrc'] > > '.' in this case is my home dir. > > Cheers! > /Joel Hedlund > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > _______________________________________________ > pydev-code mailing list > pyd...@li... > https://lists.sourceforge.net/lists/listinfo/pydev-code |
From: Fabio Z. <fa...@gm...> - 2006-04-19 16:24:30
|
On 4/19/06, Joel Hedlund <yo...@if...> wrote: > > Hi! > > From my assign params to attribs script: > > # 'onSave' can be added to the list for developing purposes. > if cmd in ['onCreateActions', 'onSave']: > declare_lots_of_variables_and_stuff > > Using 'onSave' in this manner isn't terribly clever, is it? > > Say that I delclare a variable and use it in a bunch of places, save and > run > and discover an error. Say that in the process of fixing the error I > change the > variable, but forget to change it *everywhere*. When I save and retry, th= e > error may seem to be fixed, because the old value is still in memory and > does > not cause a NameError or such until I restart the editor. > > Or is there something that I missed? > > The reason I added 'onSave' for development is pure laziness. It's quicke= r > to > save-to-update than to restart-to-update. Is there an easy way of > provoking an > editor restart in eclipse/pydev, so that the scripting namespace is > cleared? As > you already have pointed out, I should take care not to mess around with > globals and to be careful to not use stuff imported to other scripts, but > is > there anything else I should do to avoid this pitfall that I seem to fall > into > again and again? Well, currently there is not a 'reload' scripts, but I guess there's a better way: ... #the code below can be uncommented when in debug mode to reload things when needed. #if cmd =3D=3D 'onSave': # from org.python.pydev.jython import JythonPlugin #@UnresolvedImport # editor.pyEditScripting.interpreter =3D JythonPlugin.newPythonInterpret= er () if cmd =3D=3D 'onCreateActions': import re from java.lang import StringBuffer from org.eclipse.jface.action import Action #@UnresolvedImport ... Or if you feel like doing it, you could probably create a script that recreated the interpreter when requested. Cheers, Fabio |
From: Don & S. - <pi...@ca...> - 2006-04-24 15:20:55
|
Fabio Zadrozny wrote: > > Actually, I think that putting the True/False to be recognized as > globals in the preferences would be better... Hmmm... By this I think that you mean: Window -> Preferences -> Pydev Extensions -> Undefined and then in "Consider the following names as globals: ": "_, True, False" This certainly works but unless Pydev extensions makes this the default setting you are depending upon everybody updating this entry if they want to get rid of these error messages. Then, if they happen to be using Python 2.3 which does not define True and False, Pydev extensions would miss genuinely undefined True/False. Not a big deal, I suppose, but what do you think of using: try: True, False #@UndefinedVariable except NameError: (True, False) = (1, 0) Don. |
From: Fabio Z. <fa...@gm...> - 2006-04-24 15:29:25
|
Well, actually, now that you mentioned it, maybe just putting: True, False =3D 1,0 in the start of the script would be enough... Cheers, Fabio On 4/24/06, Don & Sue - pi...@ca... <pi...@ca...> wrote: > > Fabio Zadrozny wrote: > > > > > Actually, I think that putting the True/False to be recognized as > > globals in the preferences would be better... > > Hmmm... > > By this I think that you mean: > > Window -> Preferences -> Pydev Extensions -> Undefined > > and then in "Consider the following names as globals: ": > "_, True, False" > > This certainly works but unless Pydev extensions makes this the default > setting you are depending upon everybody updating this entry if they > want to get rid of these error messages. Then, if they happen to be > using Python 2.3 which does not define True and False, Pydev extensions > would miss genuinely undefined True/False. > > Not a big deal, I suppose, but what do you think of using: > > try: > True, False #@UndefinedVariable > except NameError: > (True, False) =3D (1, 0) > > > Don. > > > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > pydev-code mailing list > pyd...@li... > https://lists.sourceforge.net/lists/listinfo/pydev-code > |
From: Joel H. <yo...@if...> - 2006-04-27 14:49:17
|
> So, what do you (all) think about which would be the best way to make those > scripts available... I was thinking something as putting them (with the > authors permission) toghether with the pydev distribution... > The authors name would then appear on the script itself and in a brief help > in the homepage toghether with an explanation on how the script works. Is that page accessible somewhere today? (I'd like to show my mum... ;-) /Joel > > Cheers, > > Fabio > > On 4/19/06, Joel Hedlund <yo...@if...> wrote: > >>Hi! >> >>New version of my script here. This time I feel it's good enough to call >>an >>alpha (comments still appreciated, of course). >> >> >>>I installed and played a little with your script - looking good. >> >>Thanks! >> >> >>>Since I am congenitally unable to accept any compiler error messages >> >>:-) >> >> >>> document = document #@UndefinedVariable >> >>If I used a global variable named 'document' in my previous version it was >>most >>likely because of involuntary namespace pollution, and I hope the new >>version >>is free of it. >> >>Thanks for your time checking my script out! >>/Joel Hedlund >> >> >> > > |
From: Fabio Z. <fa...@gm...> - 2006-04-27 15:04:58
|
Hi Joel, On 4/27/06, Joel Hedlund <yo...@if...> wrote: > > > > So, what do you (all) think about which would be the best way to make > those > > scripts available... I was thinking something as putting them (with the > > authors permission) toghether with the pydev distribution... > > The authors name would then appear on the script itself and in a brief > help > > in the homepage toghether with an explanation on how the script works. > > Is that page accessible somewhere today? (I'd like to show my mum... ;-) Well, still not, but you can show: http://pydev.sourceforge.net/ -- your 'alpha' was already included in the latest release ;-) I'm still making the change to hold the scripts in the page... I've already put an 'early' version of a developers manual: http://pydev.sourceforge.net/developers.html, but the scripts session was still not created. Cheers, Fabio /Joel > > > > > > Cheers, > > > > Fabio > > > > On 4/19/06, Joel Hedlund <yo...@if...> wrote: > > > >>Hi! > >> > >>New version of my script here. This time I feel it's good enough to cal= l > >>an > >>alpha (comments still appreciated, of course). > >> > >> > >>>I installed and played a little with your script - looking good. > >> > >>Thanks! > >> > >> > >>>Since I am congenitally unable to accept any compiler error messages > >> > >>:-) > >> > >> > >>> document =3D document #@UndefinedVariable > >> > >>If I used a global variable named 'document' in my previous version it > was > >>most > >>likely because of involuntary namespace pollution, and I hope the new > >>version > >>is free of it. > >> > >>Thanks for your time checking my script out! > >>/Joel Hedlund > >> > >> > >> > > > > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > pydev-code mailing list > pyd...@li... > https://lists.sourceforge.net/lists/listinfo/pydev-code > |