Pycharm fast review

Hi there,

I've tested Pycharm beta version which has already a professional IDE features list.

i have some question about features :

1) intention actions for functions :

for example, you type :

def main():
    print("hello world")
    myfun(1,2,3)
   
if __name__=='__main__':
    main()

if you put cursor on myfun and press Alt+Enter, there are no intention action for creating a function with this name. It seems that this kind of intention actions only exists for classes (missing method).

2) Can you put specific parameter in Run > Edit Configurations in order to open pop-up when execute a command in order to set a script parameter ?

for example : in menu Run > Edit Configurations, you add script parameters :

Script : .../p1.py

Script parameters : --flows=flows.xml --toxml=flow1

(here i want to set --toxml parameter value each time i run my script (flow1, flow32, flow 76) via a popup window)

this feature exists in eclipse (see variable ${string_prompt}, ${file_prompt},... (for example : http://stackoverflow.com/questions/313270/how-to-make-eclipse-prompt-me-for-command-line-arguments)

3) for refactoring purposes, an extract function similar to extract method could be interesting.

what do you think ?

regards,

volov

7 comments

Hello vo,

I've tested Pycharm beta version which has already a professional IDE

features list.

i have some question about features :

1) intention actions for functions :

for example, you type :

def main():

print("hello world")

myfun(1,2,3)

if __name__=='__main__':

main()

if you put cursor on myfun and press Alt+Enter, there are no intention

action for creating a function with this name. It seems that this

kind of intention actions only exists for classes (missing method).

Indeed, right now we don't offer any quickfixes for unresolved unqualified

references. This will likely be implemented in a future version:

http://youtrack.jetbrains.net/issue/PY-2092

2) Can you put specific parameter in Run > Edit Configurations in

order to open pop-up when execute a command in order to set a script

parameter ?

for example : in menu Run > Edit Configurations, you add script

parameters :

Script : .../p1.py

Script parameters : --flows=flows.xml --toxml=flow1

(here i want to set --toxml parameter value each time i run my script

(flow1, flow32, flow 76) via a popup window)

this feature exists in eclipse (see variable $,

$,... (for example :

http://stackoverflow.com/questions/313270/how-to-make-eclipse-prompt-m

e-for-command-line-arguments)

No, there is no such feature in the IntelliJ Platform (and, consequently,

in PyCharm) at the moment. You can file a YouTrack issue.

3) for refactoring purposes, an extract function similar to extract

method could be interesting.

In fact the "Extract method" refactoring works just fine for functions outside

of classes. The name might be confusing, but we prefer to stick to the canon

here.

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

0

Hello Dmitry,

thanks a lot for your feedbacks.

A) first, happy to learn about future features like quickfixes for unresolved unqualified references !

B) for the ${prompt_string}, i will take a look on how to create a track as i think more in python than in java, you could use script with required parameters that could vary (you have the feeling of the Up key in shell, replace a script argument then press Enter : i think that this one could be longer in PyCharm to setUp without this prompt and even with prompt it will be longer than shell command line + history. But IDE leverages when you could mix this feature with Run in debug mode :-) .

note : i've noticed that Run in debug mode opens a Debug tab at the bottom of the window but when your script exits with an error, you're stick to this tab with "no content" or "disconnected" msgs. A cool thing would be to focus on Console tab when an error occurs.

C) for the extract function, i've tested on a simple script and it works as you said. On another script, a little popup appears with msg like : "Cannot perform refactoring when execution flow is interrupted". As this script requires script parameters to work (filenames to work on), i wonder if this is possible to fix this point in order to refactor as my script works fine when it gets its required parameters. Do not know how to fix it.

regards,

volov.

0

Hello vo,

note : i've noticed that Run in debug mode opens a Debug tab at the

bottom of the window but when your script exits with an error, you're

stick to this tab with "no content" or "disconnected" msgs. A cool

thing would be to focus on Console tab when an error occurs.

We try to minimize focus switches not controlled by the developer because

they can disrupt the development flow. We do highlight tabs which contain

new content with special icons.

C) for the extract function, i've tested on a simple script and it

works as you said. On another script, a little popup appears with msg

like : "Cannot perform refactoring when execution flow is

interrupted". As this script requires script parameters to work

(filenames to work on), i wonder if this is possible to fix this point

in order to refactor as my script works fine when it gets its required

parameters. Do not know how to fix it.

Most likely this depends not on the parameters, but on the structure of the

code block you're trying to extract. If you show me a sample code fragment,

I'll try to explain what happens in that specific case.

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

0

Hello Dmitry,

here is a piece of code where i want to use extract_method <from here> to <to here> marks (added in the source) :

def main(args,mopts):
    if len(mopts) == 0:
        toolbox.usage()
        sys.exit(0)
    if '--reference' in mopts and '--toxml' in mopts:
        # read reference file
        reference_filename=mopts['--reference'].strip("\r")
        d_flowdata=read_xls(dataname="referentiel",filename=reference_filename,sheetname="referentiel",klass="Reference",keyfieldname="sdinru",keyformatterfunc=lambda x: x.upper().strip(" \n\t"),keyextract=key_flowref_extract)
        # index d_flowdata by flowname
        d_flowref={}
        for flux_sdinru in d_flowdata:
            ref_item=d_flowdata[flux_sdinru]
            if ref_item.flux in d_flowref:
                d_flowref[ref_item.flux].append(ref_item)
            else:
                d_flowref[ref_item.flux]=[ref_item]
        # xml conversion
        flowname=mopts['--toxml'].strip("\n\t ")
        # select flowref[flowname] items
        root=Node("sirhius",{},[])
        if flowname in d_flowref:
            for pflowref in d_flowref[flowname]:
                # for each flowline
                fields=[]
                # extract fields
                for att in ('champs1','champs2','champs3'):
                    val=getattr(pflowref,att).strip("\t\n ")
                    if len(val) > 0:
                        fields.append(val)
                # split fields
                for i in range(len(fields)):
                    if fields[i].find("=") > -1:
                        fields[i]=fields[i].split("=")
                    else:
                        fields[i]=(fields[i],None)
                # split field name
                for i in range(len(fields)):
                    fields[i]=([e.strip(" \t\n") for e in fields[i][0].split("_")],fields[i][1])
                    check_nodes(fields[i][0])
                # check nodes
                nodes=fields[0][0]
<from here>
                l=len(nodes)
                l_1=l-1
                # try to find a node with this name
                tag=None
                last=None
                last=root
                for i in range(l):
                    clean_item=nodes[i]
                    if clean_item[0] in unicode_ascii_upper_letters:
                        # Tag
                        tag=last.find_name(clean_item)
                        if tag is None:
                            tag=Node(clean_item,{},[])
                            if i == l_1:
                                tag.value=pflowref.sdinru
                                print("set tag value {v} into Node {n}[{id}]".format(v=pflowref.sdinru,n=tag.nodename,id=id(tag)))
                            last.insert(tag)
                        else:
                            if i == l_1:
                                if tag.value is not None:
                                    raise ValueError("Could not set {v} as Node {n}[{id}] has already the value {v2}".format(v=pflowref.sdinru,n=tag.nodename,id=id(tag),v2=tag.value))
                                tag.value=pflowref.sdinru
                                print("set tag value {v} into Node {n}[{id}]".format(v=pflowref.sdinru,n=tag.nodename,id=id(tag)))
                        last=tag
                    else:
                        # attribute
                        last.add(clean_item,pflowref.sdinru)
<to here>
            root.accept(PrintNode())
            #root.treeview()
        else:
            raise ValueError("could not find {fn} in {ff}".format(ff=reference_filename,fn=flowname))

Pycharm  open a little popup at the beginning of the selection zone with this  following message : "Cannot perform refactoring when execution flow  isinterrupted".

I've installed the too big Pydev IDE to  check if it fails too. In fact, it succeeds to create a function that  i've called update_tree (see below) :

def update_tree(root, nodes, pflowref):
    l = len(nodes)
    l_1 = l - 1
    # try to find a node with this name
    tag = None
    last = root
    for i in range(l):
        clean_item = nodes[i]
        if clean_item[0] in unicode_ascii_upper_letters:
            # Tag
            tag = last.find_name(clean_item)
            if tag is None:
                tag = Node(clean_item, {}, [])
                if i == l_1:
                    tag.value = pflowref.sdinru
                    print("set tag value {v} into Node {n}[{id}]".format(v=pflowref.sdinru, n=tag.nodename, id=id(tag)))
                last.insert(tag)
            elif i == l_1:
                if tag.value is not None:
                    raise ValueError("Could not set {v} as Node {n}[{id}] has already the value {v2}".format(v=pflowref.sdinru, n=tag.nodename, id=id(tag), v2=tag.value))
                tag.value = pflowref.sdinru
                print("set tag value {v} into Node {n}[{id}]".format(v=pflowref.sdinru, n=tag.nodename, id=id(tag)))
            last = tag
        else:
            last.add(clean_item, pflowref.sdinru) # attribute

def main(args,mopts):
    if len(mopts) == 0:
        toolbox.usage()
        sys.exit(0)
    if '--reference' in mopts and '--toxml' in mopts:
        # read reference file
        reference_filename=mopts['--reference'].strip("\r")
        d_flowdata=read_xls(dataname="referentiel",filename=reference_filename,sheetname="referentiel",klass="Reference",keyfieldname="sdinru",keyformatterfunc=lambda x: x.upper().strip(" \n\t"),keyextract=key_flowref_extract)
        # index d_flowdata by flowname
        d_flowref={}
        for flux_sdinru in d_flowdata:
            ref_item=d_flowdata[flux_sdinru]
            if ref_item.flux in d_flowref:
                d_flowref[ref_item.flux].append(ref_item)
            else:
                d_flowref[ref_item.flux]=[ref_item]
        # xml conversion
        flowname=mopts['--toxml'].strip("\n\t ")
        # select flowref[flowname] items
        root=Node("sirhius",{},[])
        if flowname in d_flowref:
            for pflowref in d_flowref[flowname]:
                # for each flowline
                fields=[]
                # extract fields
                for att in ('champs1','champs2','champs3'):
                    val=getattr(pflowref,att).strip("\t\n ")
                    if len(val) > 0:
                        fields.append(val)
                # split fields
                for i in range(len(fields)):
                    if fields[i].find("=") > -1:
                        fields[i]=fields[i].split("=")
                    else:
                        fields[i]=(fields[i],None)
                # split field name
                for i in range(len(fields)):
                    fields[i]=([e.strip(" \t\n") for e in fields[i][0].split("_")],fields[i][1])
                    check_nodes(fields[i][0])
                pprint(fields)
                # check nodes
                nodes = fields[0][0]
                update_tree(root, nodes, pflowref)
            root.accept(PrintNode())
            #root.treeview()
        else:
            raise ValueError("could not find {fn} in {ff}".format(ff=reference_filename,fn=flowname))

i don't know why this message pops up  when i'm trying to refactor in pycharm.

regards,

volov.

0

Thanks a lot for reporting this, I've created an issue: http://youtrack.jetbrains.net/issue/PY-2102

Feel free to watch it and get notified once it is fixed.

Regards,

Oleg

0

Hi Oleg,

thanks a lot for your quick feedback !

i'll watch this issue.

regards,


volov

0

It is already fixed :-)

Regards,

Oleg

0

Please sign in to leave a comment.