Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
en:debugging_of_scripts_with_visual_studio_2017 [2019/06/16 12:10]
hlinke [Debugging of Scripts with Visual Studio 2017]
en:debugging_of_scripts_with_visual_studio_2017 [2019/06/16 12:56] (aktuell)
hlinke [Description of the Config parameters]
Zeile 1: Zeile 1:
 ====== Python Scripting for VEGAS Pro ====== ====== Python Scripting for VEGAS Pro ======
 +
 +VEGASPython is embedded in VEGAS. This can create issues for some Python debuggers.
 +I am using the WING Python IDE [[https://wingware.com/]].
 +There is a free version (WING IDE Personal) for non-comercial use and a professional version available. 
 +Other debuggers may work as well, but I have not tested them.
 +If you have experience with another debugger, please inform me and I will add this information to this chapter.
  
 ===== Debugging using WING Python IDE ===== ===== Debugging using WING Python IDE =====
  
-Debugging with Visual Studio is still possible but not recommended anymore. +For debugging VEGASPython scripts with WING IDE please follow following steps:
- +
-I recommend the Wing Python IDE [[https://wingware.com/]]. +
- +
-There is a free version (WING IDE Personal) for non-comercial use and a professional version available. +
- +
-For debugging Pythondeo with WING IDE please follow following steps:+
  
   - copy the file wingdbstub.py from the wing IDE program directory to the VEGASPython_PN directory, where your VEGASPython code is located.   - copy the file wingdbstub.py from the wing IDE program directory to the VEGASPython_PN directory, where your VEGASPython code is located.
-  - add the following line at the begin of theh python code: "import wingdbstub"+  - open wingdbstub.py and change the line: "kEmbedded = 0" to "kEmbedded = 1" 
 +  - add the following line at the begin of the python code: "import wingdbstub"
   - Turn on listening for externally initiated debug connections in Wing, which is most easily done by clicking on the bug icon in the lower left of the main window and selecting "Accept Debug Connections" in the popup menu that appears.   - Turn on listening for externally initiated debug connections in Wing, which is most easily done by clicking on the bug icon in the lower left of the main window and selecting "Accept Debug Connections" in the popup menu that appears.
  
 Load the Python Script into Wing IDE and set breakpoints. Load the Python Script into Wing IDE and set breakpoints.
  
-Start the script from VEGAS menu. (It is not possible to debug interactive scripts from the interactive window) +Start the script from VEGAS extension menu. (It is not possible to debug interactive scripts from the interactive window)
- +
-When you do changes to the script VEGAS needs to be restarted as a scripts are automatically precompiled when the are used the first time and as long VEGAS is runningit will execute the already loaded code!  +
- +
- +
  
 +When you do changes to the script VEGAS needs to be restarted to load the updated script.
  
-==== Visual Studio Installation ==== +===== The VEGASPYTHON Config File ===== 
-Here is what you have to do to setup your editing system for VEGASPython:+In the main directory where you extarcted the ZIP file you will find the file VEGASPython_CONFIG.JSON. 
 +This file provides important config parameters to support the debugging:
  
-  - Download Microsoft Visual Studio 2017 community edition: [[https://visualstudio.microsoft.com/de/downloads/]] +This is the content of the file:
-  - Install Visual Studio +
-  - When the Installer askswhich development invironment should be installed? - select "Python" (if you want to use other environemnts too, feel free to add them) +
-  - Take for all other questions the standard answer+
  
 +{
 +    
 +    {
 +    "PythonPath": "",
 +    "debugmode": false,
 +    "debugprecmd": "import wingdbstub;print ('Wing Debug started')",
 +    "debugpostcmd": "print ('Debug ended')",
 +    "debugusereload": true
 +    }
 +}
  
-==== Editing Python Files with Visual Studio ==== +If you are familiar with JSON files you will know that the structure has to be maintained. Otherwise the parameters will not be recognized any more. Change value only between the "" or change true to false or viceversa.
-Open Visual Studio+
  
-A Window like the following one will open:+==== Description of the Config parameters ==== 
 +=== PythonPath === 
 +as default Python is installed in the subdirectory \Python37 of the VEGASPython installation directory. 
 +This is good for users who do not want to deal with Python. 
 +If you have your own Python Installation(it must be Python 3.7.x) the you can here specify the directory where it resides.
  
-{{:en:vegaspython14b.jpg?direct&400|}}+Example: 
 +"PythonPath""C:\\Python37"
  
-If you are not familiar with Visual Studio, this start page may overload you. +If the parameter is empty 
-With Python you do not have to bother with creating a project and define all the parameters. +
-We will use Visual Stduio only as an Editor.+
  
-So the only step we are doing: We go to the "FileMenu and open an existing Scripfile or create a new Scripfile. +Do not forget to double "\" in the Path.
-New scripts I usually place in the "Test" subdirectory of VEGASPYTHON. So the new script shows up in Vegas in the scrit submenu "Test".+
  
-{{:en:vegaspython27b.jpg?direct&400|}}+=== debugmode=== 
 +debugmode is the main switch for the debugging parameters.
  
-  +"debugmode"false
-{{:en:vegaspython27c.jpg?direct&400|}}+
  
-{{:en:vegaspython18a.jpg?direct&400|}}+The debug parameters are ignored
  
-In this example we select the file test.py that is located in the sub-directory "testof the VEGASPython directory.+"debugmode": true
  
 +The debug parameters are used.
  
-{{:en:vegaspython28a.jpg?direct&400|}}+=== debugprecmd === 
 +Defines Python commands that need to be executed before the start of the Python script. 
 +Here you can add commands that are needed by the debugger to start the debugging and connect with the embedded Python interpreter.
  
-After opening the file, you can edit the file now in the Visual Studio Editor.+Example:
  
-{{:en:vegaspython19b.jpg?direct&400|}}+"debugprecmd""import wingdbstub;print ('Wing Debug started')"
  
-==== Debugging Python Files with Visual Studio ====+Imports the wingdbstub.py that is needed by WING Python IDE to start the debugging. You can remove this when you do not use WING Python IDE.
  
-Visual Studio can do much more for us that only editing the script. +=== debugpostcmd === 
-You can set breakpoints at every line of the script by clicking at the front of the line.+Defines Python commands that need to be executed after the end of the Python script. 
 +Here you can add commands that are needed by the debugger to stop the debugging.
  
-{{:en:vegaspython22b.jpg?direct&400|}}+Example:
  
-To start the debugging, start VEGAS and load your test project.+"debugpostcmd": "print ('Debug ended')"
  
-When VEGAS is started, we now have to tell Visual Studio, which program it has to monitor. +=== debugusereload === 
-We do this by opening the "Debug"-Menu and select the menu entry "Attach to process". +As explained above you need to restart VEGAS after any change in the Python script.
-The following window opens:+
  
-{{:en:vegaspython23b.jpg?direct&400|}}+To avoid this restart and reduce the turn arround times VEGASPython can use the "reload" command to load a script.
  
-Search in this wondow for "Vegas160.exe" or similar depending on the Vegas version you are running. +Reloading a module is not a clean concept and can create some issue. Please read the chapter reload() in the Python documentation before using this fundtion: 
-Select it and click on the "Attach"-Button.+[[https://docs.python.org/3/library/imp.html?highlight=reload#imp.reload]]
  
-{{:en:vegaspython24a.jpg?direct&400|}}+example:
  
-From now on Visual Studio monitors what Vegas is doing.+"debugusereload": true
  
-When we look into Visual Studio it shows now the break points with an empty circle. This shows that the script was not started yet. 
  
-{{:en:vegaspython29a.jpg?direct&400|}} 
  
-Now we can start the "test" Script. 
-We open it the same way we open all Python scripts. 
  
-{{:en:vegaspython30b.jpg?direct&400|}}+"debugusereload"true
  
  
-When the script started and we have set a break pint in the script, Visual Studio stops the script, when the script reaches the breakpoint. 
  
-{{:en:vegaspython31a.jpg?direct&400|}} 
  
-With the key "F10" we can now setp through the script. 
  
-{{:en:vegaspython32a.jpg?direct&400|}} 
  
-And we can even inspect variables. But unfortunately this inspection is only possible for local variable in functions. 
  
  
-{{:en:vegaspython33a.jpg?direct&400|}} 
  
-{{:en:vegaspython34a.jpg?direct&400|}} 
  
  

Andere Sprachen
QR-Code
QR-Code en:debugging_of_scripts_with_visual_studio_2017 (erstellt für aktuelle Seite)