Ankündigung

Einklappen
Keine Ankündigung bisher.

PyCharm Debug - "normal" Pyrhon Code OK - sh. not ok?

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    PyCharm Debug - "normal" Pyrhon Code OK - sh. not ok?

    Hello Guys.

    I've managed to get the PyCharm debugger to connect to my SH.py - and can debug "normal" Python code without any link to the sh.py. But i can't get it to work when copying a .py logic file containing the sh. items....

    I've also tried with Eclipse - also no success...... Can someone please help

    Attached a screendump to see it is working in the "normal" Python Udklip.JPG

    #2
    Orion

    AS we talked about

    I've went over to using Eclipse instead for debugging

    I've followed the following guide:
    https://github.com/mknx/smarthome/wi...f-Smarthome.py

    Step 1 and 2 - no problems, worked like it should...

    I've copied the pysrc folder from the Eclipse PLugin folder, like written in the thread to /usr/local/lib/python3.4/dist-packages/pysrc (the pysrc file is then in this folder, not /pysrc/pysrc)

    Also updated the bashrc

    Going to modify:
    /usr/local/lib/python3.4/dist-packages/pydevd_file_utils.py....... Then i was wondering shouldn't that path be:
    /usr/local/lib/python3.4/dist-packages/pysrc/pydevd_file_utils.py???

    Or should all the contents from the pysrc folder be placed inside the
    /usr/local/lib/python3.4/dist-packages/ - so the path could be
    /usr/local/lib/python3.4/dist-packages/pysrc/pydevd_file_utils.py??? - Tried both patches, but no succes..

    When starting the sh-py in -d mode with the following logic script:

    for item in sh :

    for child in item :

    for gadget in child :
    print (gadget.id())
    rolloRegex = re.match(r".*Roll", gadget.id())
    if rolloRegex is not None :
    print ("Sollte ein Rolladen sein!")
    pydevd.settrace("192.168.50.124")

    I get all the childs listed inside the Sh.Py in -d mode - but i don't get any data in my Eclipse at all....

    What to do to move on here?

    Kommentar


      #3
      To your questions:

      Path should be /usr/local/lib/python3.4/dist-packages/pysrc/pydevd_file_utils.py in your example
      ​Yes and you should copy all the content under pysrc to your target directory (this includes the file above)
      Next should be that you have a logic in an running environment where you have loaded the debugger at the target:

      Code:
      import pydevd
      ​but im still struggling with that, because in a plugin I-m at the point, that i got a callback from the debugger of the target, but non from a logic.

      sorry, was my fault, I had the logic in the logic.conf still disabled. Now it works. I have the following demo:

      logic.conf:
      Code:
      [zeitschaltuhr]
         filename = zeitschaltuhr.py
         cycle = 10
      zeitschaltuhr.py:
      Code:
      import pydevd
      import logging
      
      logger = logging.getLogger('Logik:')
      
      pydevd.settrace("192.168.2.57")
      
      logger.warning('Test')
      Zuletzt geändert von Orion; 04.12.2015, 22:15.

      Kommentar


        #4
        Rasmus,

        in addition: you don't start smarthome.py with -d ! You start it normal ! The Remote Debugger is loaded with import... and started with pydev.settrace...

        Kommentar


          #5
          Hello...
          Yes ok, i understand... But in the -D mode i can see that the logger saying something

          I've tested with your "sample Logic":
          import pydevd import logging logger = logging.getLogger('Logik:') pydevd.settrace("192.168.2.57") logger.warning('Test') i can see in the Sh.py debugger when trying to set a breakpoint from Eclipse, it says:
          "Warning trying to add breakpoint to file that does not exist: /usr/local/smarthome/x:\logic_develop.py (will have no effect)

          Sh.PY react on when i set a breakpoint in Eclipse - but i don't get any debug information...... maybe because the error above?

          My setup is like:
          on my windows pc, mounted the /usr/local/smarthome/develop as a network share x:
          Here is the logic above placed, and a link from the original logic folder to this (so sh.py runs it)

          My pydevd_file_utils.py file is then:

          [(r'x:/', r'/usr/local/smarthome/develop')]

          But why is the error saying that the file is in /usr/local/smarthome - seems like it doesn't take the /develop???

          Kommentar


            #6
            Hi,

            we are coming closer to the point. Let's have a look to your pydevd_file_utils.py. It is important that you keep your actual development environment (version pydevd) on your windows pc an the one you copy to the target equal ! Takt care, because updating Eclipse might lead to a newer version of pydevd without updating the target.

            The reference in this file is used to make the link between the sources on your windows pc to the sources on your target. There is no share needed (I don't have one) it might be critical to reference on the share.

            My file looks like (i'm using a MAC as development computer):
            Code:
            [(r'/Users/mw/git/smarthome', r'/usr/smarthome'),]
            That means my development sources (on ma laptop) are located in "Users/mw/git/smarthome" where the copied ! sources on the target are located in "/usr/smarthome".

            It seams, that your directly change the files at your target, not on your development laptop an deploy them afterwards. Doing remote debugging normally has no shared directories and no access to the filesystem of the target. My setup is as said different: Development on the laptop, than deployment to the target (could be a file copy to the target) an than remote debugging where the debug client (target) uses the sources in his own filesystem an the debug server (your windows PC) uses his own sources at the PC filesystem. The pydevd_file_utils.py makes the link between these systems.

            The problem occurs, because the reference to the sources of the debug server aren't present.

            Another topic: in windows you need to use backslash instead of slash ! In the description of the wiki there is for mapped drive x even no backslash in, just "x:". An there is a description to install an new workspace in "x:". This means, that your development workspace of clips doesn't live on your PC, but your target. I'm would like to develop even when im not linked to my target, therefore i prefer the config with sources on both sides.

            Hope this helps.

            Michel

            Kommentar


              #7
              Yes we are getting much closer - thanks for the help so far

              im the remote debug guide on the mknx git it says it's easier to have a remote share... that's why I done that...

              actually i I would prefer have the debug logic locally on my pc, with no connection to sh.py.... I'll try to adjust the source in the pydev_file ....

              if if I put the logic that include the import pydevd and import logger in a folder /smarthome/develop/develop.py and create a link to the original logic folder...

              on my pc, then I put a develop.py in c:\smarthome\develop\develop.py and do the development from this...

              Should my pydevd file not look like:
              r'c:\smarthome\develop\' , r'/usr/local/smarthome/develop'???

              But it how does it actually work - I create a logic on sh.py and set it to run each 30 sec, with the import pydevd and import logging like we discussed earlier....

              What about the "local" develop logic? Do I need to have that deployed to the remote every time and restart sh.py?
              Or can the local logic be ran like it was done on the remote?
              Now when doing anything I get errors everything some sh. Statements comes...
              Zuletzt geändert von Rasmus7700; 06.12.2015, 18:57.

              Kommentar


                #8
                Hi,

                with the pydevd_file_utils.py: there should be no backslash at the end (i guess, because I don't run on windows).
                You're right, running a logic without running sh environment come to errors. In this case your way might be the right one. I#ve done it so far only with plugins an some unit tests. With this, you don't need a running system, because you code against test cases.

                Michel

                Kommentar


                  #9
                  Morning Michel

                  I'll try to adapt the pydevd_file_utils some more - it should be possible

                  But, should eclipse return something it self? or is it only when the logic is ran in sh.py it returns something - or shall i manually run the logic i'm working on in Eclipse or how? I guess this must be the same as a plugin - do you "run" the plugin from sh.py to get debug info?

                  Kommentar


                    #10
                    Hi Rasmus,

                    I run the plugin from sh if there is some debug needed in the overall system (beyond unit tests). The reason is the runtime environment (mostly the callback handling of triggered items) and the fact, that i don't want to mock the whole handling of the 'sh' object.

                    With Logics it should be simpler, because ist just a script file. I remember (but I don't know where exactly) that there should be a possibility to reload the logics without restarting smarthome.py in total. This would make logic development much more easier.

                    Eclipse itself does not return anything in there remote case if the logic is not triggered by smarthome.py. So normally final testing of a logic would also be in the smarthome.py runtime environment.

                    Michel

                    PS: another idea comes to my mind: why not putting the whole smarthome.py environment in the debugger locally (without remote target). You will get a second instance of sh, which could be run an tested fully. I had a look to make this run on my macbook, but there were some native linux routines, which are not existent in mac environment. If you are using linux environment (virtual machine on your windows pc), it should be possible. Somehow Marcus needs a powerful development environment. I don't believe that he is doing the job just by remote debugging.

                    Kommentar


                      #11
                      Hello Michel.
                      Okay, i understand.... it would be very nice if it just was to "reload" the logic script then Sh.PY ran it with the new changes... I can simply test that - i should be able to see it in the -D mode if something changes.

                      So when the logic is executed i get the output in the debugger of eclipse - but on that way, all "changes/tests" affects the whole Sh.pt environment..... In the "wiki guide" i think that's why they create a link to another folder - but i think it also affects it all... :S

                      I can see your idea, which would be very good, simply run Ubuntu in a virtual machine and do all the development inside here - is it possible to load the "whole" project into Eclipse in linux - and then simply run it as a local?
                      You are thinking of connect Eclipse to the local sh.py environment running?

                      Kommentar


                        #12
                        Hi Rasmus,

                        yes, just load the complete smarthome.py in the eclipse workspace and run it there.

                        Kommentar


                          #13
                          I've tested it, and can't get the debugger to run it - it says no errors or anything, but it doesn't generate and debug data and doesn't seem to be anything in the console output..... I've just "opened" the project in the Eclipse and tryed to press Run....

                          Am i doing anything wrong?

                          Kommentar


                            #14
                            Did you start it with run or with debug ? There are both options available. You have to run it with debug...

                            Kommentar


                              #15
                              Yes ok - also i need to run it in -d mode or?

                              Kommentar

                              Lädt...
                              X