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 [2018/10/14 13:20]
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 ======
  
-===== Python Script Features =====+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 of Scripts with Visual Studio 2017 ====+===== Debugging using WING Python IDE =====
  
-The interactive VEGASPython Window is only foreseen for very short scripts needing a few lines. +For debugging VEGASPython scripts with WING IDE please follow following steps:
-For longer scripts it is proposed to use a Python Script Editor that supports the writing of Python code. +
-But this is not all. It is very unusual that the script you have written is working correctly from the start. +
-There are always small things that are wrong - especially simple typos or logical flow errors.+
  
-As PYTHON is an interpreted language, most erros can only be found when the script is executed+  - copy the file wingdbstub.py from the wing IDE program directory to the VEGASPython_PN directory, where your VEGASPython code is located. 
 +  - 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 Wingwhich 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.
  
-This seems to be a disadvantage. But: Due to the interpretation of the script at runtime the turn arround times frem chnaging the script to seeing the results or error is much faster than in other languages.+Load the Python Script into Wing IDE and set breakpoints.
  
-Especially the startup time of VEGAS and opening a test project can take a lot of time.+Start the script from VEGAS extension menu(It is not possible to debug interactive scripts from the interactive window)
  
-With VEGASPython, Vegas stays open with the test project all the time. You only have to restart the script for testing after you updated it.+When you do changes to the script VEGAS needs to be restarted to load the updated script.
  
-It may be surprising but the best support for VEGASPython editing and debugging is provided by Microsoft Visual Studio 2017 (this is the current version). +===== The VEGASPYTHON Config File ===== 
-You can use the free community version of Visual Studio 2017And with Python you can use Visual Studio as a simple editor and debuggerYou do not have to deal with all the other complex development project setups.+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:
  
-=== Visual Stduio Installation === +This is the content of the file:
-Here is what you have to do to setup your editing system for VEGASPython:+
  
-  - Download Microsoft Visual Studio 2017 community edition: [[https://visualstudio.microsoft.com/de/downloads/]] +{ 
-  - Install Visual Studio +     
-  - When the Installer askswhich development invironment should be installed? - select "Python" (if you want to use other environemnts toofeel 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 
 +    } 
 +}
  
 +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.
  
-=== Debugging with Visual Studio === +==== Description of the Config parameters ==== 
-Open Visual Studio+=== 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.
  
-A Window like the following one will open:+Example: 
 +"PythonPath": "C:\\Python37"
  
-{{:en:vegaspython14b.jpg?direct&400|}}+If the parameter is empty 
  
-If you are not familiar with Visual Studio, this start page may overload you. +Do not forget to double "\" in the Path.
-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 "File" Menu and open an exsting Python file or create a new Python file.+=== debugmode=== 
 +debugmode is the main switch for the debugging parameters.
  
-{{:en:vegaspython27b.jpg?direct&400|}}+"debugmode"false
  
-  +The debug parameters are ignored
-{{:en:vegaspython27c.jpg?direct&400|}}+
  
-{{:en:vegaspython18a.jpg?direct&400|}}+"debugmode"true 
 + 
 +The debug parameters are used. 
 + 
 +=== 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. 
 + 
 +Example: 
 + 
 +"debugprecmd": "import wingdbstub;print ('Wing Debug started')" 
 + 
 +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. 
 + 
 +=== debugpostcmd === 
 +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. 
 + 
 +Example: 
 + 
 +"debugpostcmd": "print ('Debug ended')" 
 + 
 +=== debugusereload === 
 +As explained above you need to restart VEGAS after any change in the Python script. 
 + 
 +To avoid this restart and reduce the turn arround times VEGASPython can use the "reload" command to load a script. 
 + 
 +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: 
 +[[https://docs.python.org/3/library/imp.html?highlight=reload#imp.reload]] 
 + 
 +example: 
 + 
 +"debugusereload": true 
 + 
 + 
 + 
 + 
 +"debugusereload": true
  
-In this example we select the file test.py that is located in the sub-directory "test" of the VEGASPython directory. 
  
  
-{{:en:vegaspython28a.jpg?direct&400|}} 
-After opening the file, you can edit the fil ein the Visual Studio Editor.  
  
-{{:en:vegaspython29a.jpg?direct&400|}} 
  
-{{:en:vegaspython30b.jpg?direct&400|}} 
  
-{{:en:vegaspython31a.jpg?direct&400|}} 
  
-{{:en:vegaspython32a.jpg?direct&400|}} 
  
-{{: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)