Differences

This shows you the differences between two versions of the page.

Link to this comparison view

setting_up_a_development_environment [2024/06/27 00:08] – external edit 127.0.0.1setting_up_a_development_environment [2026/04/07 18:27] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ===== Setting up an Indigo Plugin Development Environment ===== ===== Setting up an Indigo Plugin Development Environment =====
 If you're interested in developing an Indigo plugin to share with other users or just for yourself, the way you approach development can make a big difference. Whether you choose to write your Indigo plugin without any specialized tools or expensive software packages, or instead choose one of the open source applications -- or even a plain text editor -- there are ways to make the process easier and more streamlined. This page describes many authoring packages and steps you can take to make your effort more successful. If you're interested in developing an Indigo plugin to share with other users or just for yourself, the way you approach development can make a big difference. Whether you choose to write your Indigo plugin without any specialized tools or expensive software packages, or instead choose one of the open source applications -- or even a plain text editor -- there are ways to make the process easier and more streamlined. This page describes many authoring packages and steps you can take to make your effort more successful.
 +
 ===== Integrated Development Environments ===== ===== Integrated Development Environments =====
-Using an Integrated Development Environment (IDE) can make writing Indigo plugins much easier.  IDEs are programming environments that can help you reference Python functions, make recommendations on syntax, and even color code and highlight sections of code to make things easier for you. There are way too many Python IDEs to list them all here, but the more poplar ones include (in alphabetical order):+Using an Integrated Development Environment (IDE) can make writing Indigo plugins much easier.  IDEs are programming environments that can help you reference Python functions, make recommendations on syntax, and even color code and highlight sections of code to make things easier for you. There are way too many Python IDEs to list them all here, but the more popular ones include (in alphabetical order):
   * [[https://atom.io|Atom]] - Atom is a free and open-source text and source code editor for macOS, Linux, and Microsoft Windows with support for plug-ins written in JavaScript, and embedded Git Control. It was developed by GitHub. **NOTE:** Atom and all projects under the Atom organization are slated for an official sunset on December 15, 2022.   * [[https://atom.io|Atom]] - Atom is a free and open-source text and source code editor for macOS, Linux, and Microsoft Windows with support for plug-ins written in JavaScript, and embedded Git Control. It was developed by GitHub. **NOTE:** Atom and all projects under the Atom organization are slated for an official sunset on December 15, 2022.
   * [[https://www.barebones.com|BBEdit]] - BBEdit is a proprietary text editor made by Bare Bones Software, originally developed for Macintosh System Software 6, and currently supporting macOS. The free version of BBEdit works very well for writing Indigo plugins, and the paid version includes some IDE-type integration as well.   * [[https://www.barebones.com|BBEdit]] - BBEdit is a proprietary text editor made by Bare Bones Software, originally developed for Macintosh System Software 6, and currently supporting macOS. The free version of BBEdit works very well for writing Indigo plugins, and the paid version includes some IDE-type integration as well.
-  * [[https://www.jetbrains.com/pycharm/|PyCharm]] - PyCharm is an excellent full-featured commercial Python development environment made by Jetbrains. There are several licenses available for PyCharm from paid to free -- the license you need depends on what you use the program for.  **NOTE:** for certain features (including the ability to debug Indigo plugins from within the IDE) require a paid PyCharm Professional Edition license.+  * [[https://www.jetbrains.com/pycharm/|PyCharm]] - PyCharm is an excellent full-featured commercial Python development environment made by JetBrains. There are several licenses available for PyCharm from paid to free -- the license you need depends on what you use the program for.  **NOTE:** for certain features (including the ability to debug Indigo plugins from within the IDE) require a paid PyCharm Professional Edition license.
   * [[https://www.spyder-ide.org|Spyder]] - Spyder is an open-source cross-platform integrated development environment for scientific programming in the Python language. While it is more geared towards scientific programming, it works for non-scientific applications, too.   * [[https://www.spyder-ide.org|Spyder]] - Spyder is an open-source cross-platform integrated development environment for scientific programming in the Python language. While it is more geared towards scientific programming, it works for non-scientific applications, too.
   * [[https://www.sublimetext.com|Sublime Text]] - Sublime Text is a shareware cross-platform source code editor. It natively supports many programming languages and markup languages. Users can expand its functionality with plugins, typically community-built and maintained under free-software licenses.   * [[https://www.sublimetext.com|Sublime Text]] - Sublime Text is a shareware cross-platform source code editor. It natively supports many programming languages and markup languages. Users can expand its functionality with plugins, typically community-built and maintained under free-software licenses.
   * [[https://code.visualstudio.com|VSCode]] - VSCode is a free source code editor made by Microsoft that runs on Mac, Linux and Windows. VSCode is an extremely popular tool used for Python development.   * [[https://code.visualstudio.com|VSCode]] - VSCode is a free source code editor made by Microsoft that runs on Mac, Linux and Windows. VSCode is an extremely popular tool used for Python development.
- 
- 
  
 ===== Other Editors ===== ===== Other Editors =====
 +You can use any of several great text editors to write plugin code, but one aspect is crucial -- they must be able to save **plain text files**.
  
-You can use any of several great text editors to write plugin codebut one aspect is crucial -- they must be able to save **plain text files**. +  * **TextEdit** - the editor that ships with macOS. If you choose to use Apple's TextEdit appwhen you save your code to file, you MUST select **Make Plain Text** from the **Format** menu, and when you save, be sure that the **Plain Text Encoding** is set to ''Unicode (UTF-8)''
 +  * [[https://www.vim.org|vim]] - Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.
  
-  * **TextEdit** - the editor that ships with macOS. If you choose to use Apple's TextEdit app, when you save your code to file, you MUST select **Make Plain Text** from the **Format** menu, and when you save, be sure that the **Plain Text Encoding** is set to ''Unicode (UTF-8)''. 
-  * [[https://www.vim.org|vim]] - Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.  
 ===== Setting Up Your Development Environment ===== ===== Setting Up Your Development Environment =====
 Choosing what tools to use to develop your plugin is only one of the considerations you'll need to address. You'll also need to decide how you're going to configure your environment. Choosing what tools to use to develop your plugin is only one of the considerations you'll need to address. You'll also need to decide how you're going to configure your environment.
Line 23: Line 22:
   * **Project organization considerations** -- will you be developing on the same machine where your Indigo server lives? Where will your project files be located? On your machine? Online? A common approach is to have a separate folder structure just for development -- with subfolders dedicated to each project. You should also consider whether you'll benefit from a common location within your project space that can be used for segments of code that you'll use across multiple plugin projects.   * **Project organization considerations** -- will you be developing on the same machine where your Indigo server lives? Where will your project files be located? On your machine? Online? A common approach is to have a separate folder structure just for development -- with subfolders dedicated to each project. You should also consider whether you'll benefit from a common location within your project space that can be used for segments of code that you'll use across multiple plugin projects.
   * **Virtual environments** -- some developers choose to build their projects using [[https://docs.python.org/3/tutorial/venv.html|virtual environments]]. This allows for each project to reside in a separate environment where changes can be made to one environment while leaving the others unchanged. For example, installing different versions of Python libraries depending on the project's needs.   * **Virtual environments** -- some developers choose to build their projects using [[https://docs.python.org/3/tutorial/venv.html|virtual environments]]. This allows for each project to reside in a separate environment where changes can be made to one environment while leaving the others unchanged. For example, installing different versions of Python libraries depending on the project's needs.
-  * **Backups and version control** -- You'll want to save your work along the way. Backups are easy. Make them. Often. But you'll also want to be in a position to be able to revert back to prior versions in case you decide to undo some changes you've made. Github is a popular choice, but there are other options out there and you can always roll your own.+  * **Backups and version control** -- You'll want to save your work along the way. Backups are easy. Make them. Often. But you'll also want to be in a position to be able to revert back to prior versions in case you decide to undo some changes you've made. GitHub is a popular choice, but there are other options out there and you can always roll your own.
   * **Plugin versioning** -- You'll need to come up with a way to assign version numbers to your plugin. By incrementing the version number with each release, Indigo will be better able to identify updates and more easily install them--version numbers are required if you release your plugin through the Indigo Plugin Store. There are many ways to do versioning, but it's common to use a two- or three-number [[https://en.wikipedia.org/wiki/Software_versioning#Semantic_versioning|semantic versioning system]] where:   * **Plugin versioning** -- You'll need to come up with a way to assign version numbers to your plugin. By incrementing the version number with each release, Indigo will be better able to identify updates and more easily install them--version numbers are required if you release your plugin through the Indigo Plugin Store. There are many ways to do versioning, but it's common to use a two- or three-number [[https://en.wikipedia.org/wiki/Software_versioning#Semantic_versioning|semantic versioning system]] where:
     * Major version - often incremented with substantial changes to the software.     * Major version - often incremented with substantial changes to the software.
     * Minor version - often incremented with new features or enhancements.     * Minor version - often incremented with new features or enhancements.
     * Patch - often incremented with bug fixes and minor code refinements.     * Patch - often incremented with bug fixes and minor code refinements.
-  * **Collaboration** -- will you be working on the plugin by yourself or will you be coordinating with other developers?  If you're working in a group environment, you'll need to establish a method (again, Github is a popular choice) but also protocols for how your team's work will be combined.+  * **Collaboration** -- will you be working on the plugin by yourself or will you be coordinating with other developers?  If you're working in a group environment, you'll need to establish a method (again, GitHub is a popular choice) but also protocols for how your team's work will be combined.
   * **Symlinks**  -- Once you're ready to test your code, you'll need to install your plugin on your Indigo server in order for it to run and access to the Indigo Object Model Framework (IOM). You could choose to install your plugin like you would with any other plugin, but there is a better way -- using symbolic links. A link allows your "original" plugin code to remain outside the Indigo file system but in a place where the Indigo server will still see it. Creating symlinks for your development plugins using the Terminal app is easy:   * **Symlinks**  -- Once you're ready to test your code, you'll need to install your plugin on your Indigo server in order for it to run and access to the Indigo Object Model Framework (IOM). You could choose to install your plugin like you would with any other plugin, but there is a better way -- using symbolic links. A link allows your "original" plugin code to remain outside the Indigo file system but in a place where the Indigo server will still see it. Creating symlinks for your development plugins using the Terminal app is easy:
     - Open two Finder windows, one pointing to the folder that contains your plugin code and the second pointing to the Indigo file tree.     - Open two Finder windows, one pointing to the folder that contains your plugin code and the second pointing to the Indigo file tree.
Line 35: Line 34:
     - Drag the Indigo Plugins (Disabled) folder and drop it on the Terminal window, so it looks something like this:<code>User@My Mac ~ % ln -s /Users/User/My Development Environment/my_plugin.indigoPlugin /Library/Application\ Support/Perceptive\ Automation/Indigo\ 2022.1/Plugins\ \(Disabled\)     - Drag the Indigo Plugins (Disabled) folder and drop it on the Terminal window, so it looks something like this:<code>User@My Mac ~ % ln -s /Users/User/My Development Environment/my_plugin.indigoPlugin /Library/Application\ Support/Perceptive\ Automation/Indigo\ 2022.1/Plugins\ \(Disabled\)
 </code> </code>
-    - Switch to Terminal and hit <html><kbd>return</kbd></html>. If things went according to plan, you should see your plugin in the Plugins (Disabled) folder with a small arrow in the lower left corner (indicating that it's a linked file).+    - Switch to Terminal and hit return. If things went according to plan, you should see your plugin in the Plugins (Disabled) folder with a small arrow in the lower left corner (indicating that it's a linked file).
     - Restart the Indigo server and you should see your plugin in the Plugins Menu. With the file successfully linked, you can safely Enable and Disable the plugin in Indigo and the operating system will update the symbolic link accordingly.  You can then safely make changes to your code, save, and reload the plugin in Indigo.     - Restart the Indigo server and you should see your plugin in the Plugins Menu. With the file successfully linked, you can safely Enable and Disable the plugin in Indigo and the operating system will update the symbolic link accordingly.  You can then safely make changes to your code, save, and reload the plugin in Indigo.
   * **Hosting** -- If you choose to share your plugin with the world, you'll need a place to host the plugin files so that others can download it.   * **Hosting** -- If you choose to share your plugin with the world, you'll need a place to host the plugin files so that others can download it.
-    * **Indigo Plugin Store** -- The recommended way to share plugins with other Indigo users is via the Indigo Plugin Store. By using the store, you get a central place where users can search for plugins to solve various scenarios, you get built-in version notifications to users via the Mac Client, etc. Check out the [[https://wiki.indigodomo.com/doku.php?id=plugin_store_guidelines|Plugin Store Submission Guidelines]].  +    * **Indigo Plugin Store** -- The recommended way to share plugins with other Indigo users is via the Indigo Plugin Store. By using the store, you get a central place where users can search for plugins to solve various scenarios, you get built-in version notifications to users via the Mac Client, etc. Check out the [[https://wiki.indigodomo.com/doku.php?id=plugin_store_guidelines|Plugin Store Submission Guidelines]]. 
-    * **Github** -- Many developers manage their plugin code on GitHub, and in fact you can configure your Plugin Store entry to pull information and releases from Github (which is the recommended way of adding plugins to the store).  GitHub is a very powerful tool used for distribution, version tracking, collaboration and other things. A GitHub account is free with a few limitations that most users won't encounter.+    * **GitHub** -- Many developers manage their plugin code on GitHub, and in fact you can configure your Plugin Store entry to pull information and releases from GitHub (which is the recommended way of adding plugins to the store).  GitHub is a very powerful tool used for distribution, version tracking, collaboration and other things. A GitHub account is free with a few limitations that most users won't encounter.
   * **Providing Support** -- If you choose to share your plugin with others, it's inevitable that someone will have a question, an issue, or want to contribute code to your effort. There are a variety of ways to do this, but there are several common approaches that developers currently use:   * **Providing Support** -- If you choose to share your plugin with others, it's inevitable that someone will have a question, an issue, or want to contribute code to your effort. There are a variety of ways to do this, but there are several common approaches that developers currently use:
     * **Indigo Forums** - many developers have dedicated forums for their plugins on the Indigo forums site. If you think your plugin might qualify for its own forum, please [[mailto:[email protected]|contact Support]].     * **Indigo Forums** - many developers have dedicated forums for their plugins on the Indigo forums site. If you think your plugin might qualify for its own forum, please [[mailto:[email protected]|contact Support]].
-    * **Github Wikis** - many developers write documentation for their plugins, and on popular way to make that available to others is by creating a dedicated wiki page on Github+    * **GitHub Wikis** - many developers write documentation for their plugins, and on popular way to make that available to others is by creating a dedicated wiki page on GitHub
-    * **Plugin Issues** - Some developers prefer users report problems via the Indigo forums, while others prefer users to file issues on Github.+    * **Plugin Issues** - Some developers prefer users report problems via the Indigo forums, while others prefer users to file issues on GitHub. 
 ===== Debugging ===== ===== Debugging =====
 As a quick summary, Indigo plugins and scripts must run in a special process called the Indigo Plugin Host. That process bridges Indigo native objects (C++ objects) to python. One side effect of this requirement is that debugging a plugin has some special challenges. For instance, you can't directly debug plugins from most of the IDEs listed above. As a quick summary, Indigo plugins and scripts must run in a special process called the Indigo Plugin Host. That process bridges Indigo native objects (C++ objects) to python. One side effect of this requirement is that debugging a plugin has some special challenges. For instance, you can't directly debug plugins from most of the IDEs listed above.
Line 49: Line 49:
 However, we have facilitated the use a several Python debuggers together with Indigo: However, we have facilitated the use a several Python debuggers together with Indigo:
  
-  * [[https://docs.python.org/2/library/pdb.html|pdb]] (command line tool),  +  * [[https://docs.python.org/2/library/pdb.html|pdb]] (command line tool), 
-  * [[https://pypi.python.org/pypi/pudb/|PuDB]] (command line tool), and  +  * [[https://pypi.python.org/pypi/pudb/|PuDB]] (command line tool), and 
-  * [[https://www.jetbrains.com/pycharm/|PyCharm]] (professional version). +  * [[https://www.jetbrains.com/pycharm/|PyCharm]] (professional version).
  
 Each has its pros and cons, but all are a significant improvement over ''self.logger.debug()...'' Each has its pros and cons, but all are a significant improvement over ''self.logger.debug()...''
  
 In the Plugins Preferences tab, there is a Development section: In the Plugins Preferences tab, there is a Development section:
-{{ :ss88.png?nolink&400 |}}+{{ :ss88.png?nolink&400 |Indigo Plugin Preference for Debugging Image}}
 (Bet you didn't even remember that tab was there). Because we need to start plugins in a special way for debugging to work, we need to show some special debugging menus. Check the checkbox to see those menus in each plugin's submenu. Next, each debugger needs to be started in a specific way, so select the debugger that you want to use. (Bet you didn't even remember that tab was there). Because we need to start plugins in a special way for debugging to work, we need to show some special debugging menus. Check the checkbox to see those menus in each plugin's submenu. Next, each debugger needs to be started in a specific way, so select the debugger that you want to use.
  
Line 68: Line 68:
 ==== pdb ==== ==== pdb ====
 [[https://docs.python.org/2/library/pdb.html|pdb]] is a command line debugger that's built-in to Python. We'll let you read the docs to find commands and features. What you do need to know is when you select Enable/Reload in Debugger, Indigo will restart your plugin and open a terminal window running pdb: [[https://docs.python.org/2/library/pdb.html|pdb]] is a command line debugger that's built-in to Python. We'll let you read the docs to find commands and features. What you do need to know is when you select Enable/Reload in Debugger, Indigo will restart your plugin and open a terminal window running pdb:
-{{ :ss89.png?nolink&600 |}}+{{ :ss89.png?nolink&600 |PDB Image}}
 To add breakpoints to your code, you just add ''indigo.debugger()'' method calls where ever you want plugin execution to pause in the debugger. Trying to interactively add breakpoints from pdb or PuDB is hit-or-miss because of the threaded way in which Indigo plugins run. The most reliable to way to force a breakpoint is by manually adding the ''indigo.debugger()'' call to the python source and restarting the plugin. Also note ''indigo.debugger()'' calls are ignored (NOPs) when the plugin is not launched in debugger mode, so don't lose sleep over leaving an ''indigo.debugger()'' call in a shipping plugin. To add breakpoints to your code, you just add ''indigo.debugger()'' method calls where ever you want plugin execution to pause in the debugger. Trying to interactively add breakpoints from pdb or PuDB is hit-or-miss because of the threaded way in which Indigo plugins run. The most reliable to way to force a breakpoint is by manually adding the ''indigo.debugger()'' call to the python source and restarting the plugin. Also note ''indigo.debugger()'' calls are ignored (NOPs) when the plugin is not launched in debugger mode, so don't lose sleep over leaving an ''indigo.debugger()'' call in a shipping plugin.
  
 ==== PuDB ==== ==== PuDB ====
 [[http://heather.cs.ucdavis.edu/~matloff/pudb.html|PuDB]] is a more graphical debugger (though it's still character based), much like to the old [[https://en.wikipedia.org/wiki/Borland_Turbo_Debugger|Borland Turbo Debugger]] from many years ago: [[http://heather.cs.ucdavis.edu/~matloff/pudb.html|PuDB]] is a more graphical debugger (though it's still character based), much like to the old [[https://en.wikipedia.org/wiki/Borland_Turbo_Debugger|Borland Turbo Debugger]] from many years ago:
-{{ :ss90.png?nolink&600 |}}+{{ :ss90.png?nolink&600 |PuDB Image}}
 As with pdb, you add breakpoints to your code by adding ''indigo.debugger()'' method calls where ever you want plugin execution to pause in the debugger. As with pdb, you add breakpoints to your code by adding ''indigo.debugger()'' method calls where ever you want plugin execution to pause in the debugger.
  
 ==== PyCharm ==== ==== PyCharm ====
- +Finally, we were able to use PyCharm's **Python Debug Server** feature to enable plugin debugging (formerly referred to as "remote debugging"). It requires a bit more setup, but if you want to use a fantastic modern IDE, this is the choice for you. **Note**: because we're using the Debug Server feature, you can only use the paid professional version of PyCharm as the community edition doesn't support it.
-Finally, we were able to use PyCharm's **Python Debug Server** feature to enable plugin debugging (formerly referred to as "remote debugging"). It requires a bit more setup, but if want to use a fantastic modern IDE, this is the choice for you. **Note**: because we're using the Debug Server feature, you can only use the paid professional version of PyCharm as the community edition doesn't support it.+
  
 === Configure Local Debugging === === Configure Local Debugging ===
- 
 The most straight-forward debug configuration is to use PyCharm to debug your plugin running in Indigo on the same Mac. With your plugin's project open in PyCharm, create a run configuration of type **Python Debug Server ** (formerly **Remote Python Debug**): The most straight-forward debug configuration is to use PyCharm to debug your plugin running in Indigo on the same Mac. With your plugin's project open in PyCharm, create a run configuration of type **Python Debug Server ** (formerly **Remote Python Debug**):
  
-{{ :python_debug_server.png?nolink&600 |}}+{{ :python_debug_server.png?nolink&600 |Python Debug Server Image}}
  
-There are three important config parameters in this dialog (you can name the configuration anything you want). The first two tell how to connect: specify localhost in the **Local host name** box and 5678 in the **Port** field. The next field you need to adjust is the Path mappings field. +There are three important config parameters in this dialog (you can name the configuration anything you want). The first two tell how to connect: specify localhost in the **Local host name** box and 5678 in the **Port** field. The next field you need to adjust is the Path mappings field.
  
 Recall that the recommended way of developing Indigo plugins is to put your plugin in a central location (not inside the Indigo folders), then make a symbolic link to it in the Plugins directory. We do this because the Indigo server moves a plugin between two different folders when enabling/disabling. An IDE/editor will get confused when this happens, so by putting the actual code in a place that never moves and allowing the Indigo Server to move a symbolic link around, you get around this issue. Recall that the recommended way of developing Indigo plugins is to put your plugin in a central location (not inside the Indigo folders), then make a symbolic link to it in the Plugins directory. We do this because the Indigo server moves a plugin between two different folders when enabling/disabling. An IDE/editor will get confused when this happens, so by putting the actual code in a place that never moves and allowing the Indigo Server to move a symbolic link around, you get around this issue.
  
-Because of this, you need to tell PyCharm where the actual path to the source is when the plugin is enabled and being debugged. Click the ellipsis button at the end of the **Path mappings** field to add a mapping. On the **Local path** side, you want to specify the actual path to your plugin's source (i.e. /Users/you/path/to/myplugin.indigoPlugin). On the **Remote path** side, you want to specify the path to your plugin's symlink when the plugin is enabled (i.e. ''/Library/Application Support/Perceptive Automation/Indigo 2022.1/Plugins/myplugin.indigoPlugin)''. **TIP:** to get the path to a file in the Finder, right click on the file to show the contextual menu, then press the Option key. The Copy item will change to Copy as Pathname which is exactly what you want.+Because of this, you need to tell PyCharm where the actual path to the source is when the plugin is enabled and being debugged. Click the ellipsis button at the end of the **Path mappings** field to add a mapping. On the **Local path** side, you want to specify the actual path to your plugin's source (i.e. /Users/you/path/to/myplugin.indigoPlugin). On the **Remote path** side, you want to specify the path to your plugin's symlink when the plugin is enabled (i.e. ''/Library/Application Support/Perceptive Automation/Indigo 2022.1/Plugins/myplugin.indigoPlugin)''. **TIP:** to get the path to a file in the Finder, right-click on the file to show the contextual menu, then press the Option key. The Copy item will change to Copy as Pathname which is exactly what you want.
  
 One other option is the **Suspend after connect** checkbox: if you have that checked, then when your plugin restarts with the debugger, it will pause execution in the ''__init__()'' method. We don't recommend doing this since you can add breakpoints anywhere you want in the code, including in the ''__init__()'' method. One other option is the **Suspend after connect** checkbox: if you have that checked, then when your plugin restarts with the debugger, it will pause execution in the ''__init__()'' method. We don't recommend doing this since you can add breakpoints anywhere you want in the code, including in the ''__init__()'' method.
 +
 +<color #ed1c24>**Note:**</color> the PyCharm debug configuration dialog says that you need to install ''//pydevd//'' and add two lines of code to connect to the debug server, however, the IPH (Indigo Plugin Host) takes care of this for you so **//there's no need to complete those steps.//**
  
 That's it for setup! To debug, just run the debug configuration and then restart your plugin in the debugger. Unlike when using pdb and PuDB, you don't need to add explicit breakpoints to the source code using ''indigo.debugger()'' – rather, just interactively add breakpoints in PyCharm: That's it for setup! To debug, just run the debug configuration and then restart your plugin in the debugger. Unlike when using pdb and PuDB, you don't need to add explicit breakpoints to the source code using ''indigo.debugger()'' – rather, just interactively add breakpoints in PyCharm:
-{{ :ss92.png?nolink&600 |}}+{{ :ss92.png?nolink&600 |Breakpoints in PyCharm Image}}
 You can step through code, inspect, etc., just like you are debugging any other Python project. You can step through code, inspect, etc., just like you are debugging any other Python project.
 We hope that you'll find a great debugging solution for your needs in one of these options. We've added a couple of new API methods on the plugin objects that are part of this change: We hope that you'll find a great debugging solution for your needs in one of these options. We've added a couple of new API methods on the plugin objects that are part of this change:
Line 117: Line 117:
 def main(argv): def main(argv):
     parser = argparse.ArgumentParser(     parser = argparse.ArgumentParser(
-        description="Restart a plugin given it'full name or ID"+        description="Restart a plugin given its full name or ID"
     )     )
     parser.add_argument(     parser.add_argument(
Line 149: Line 149:
 </code> </code>
 And you would set up the external tool with these settings: And you would set up the external tool with these settings:
-{{ :remote_plugin_restart.png?nolink&600 |}}+{{:remote_plugin_restart.png?nolink&600|Remote Plugin Restart Image}}
  
 Now, when you use that External Tool, it will reload your plugin with the debugger enabled. You can even configure your debug run configuration to run this as a **Before launch** tool (see the configuration image above). So every time you run the debug configuration, it will also restart the plugin. Now, when you use that External Tool, it will reload your plugin with the debugger enabled. You can even configure your debug run configuration to run this as a **Before launch** tool (see the configuration image above). So every time you run the debug configuration, it will also restart the plugin.
  
 === Configure Remote Debugging (Experimental) === === Configure Remote Debugging (Experimental) ===
- 
 The above local debugging configuration presumes that the Indigo Server and the plugin you are debugging are running on the same machine on which you are running PyCharm. It's also possible (and experimental at this point) to debug a plugin running on an Indigo Server on a separate Mac on the network from the one on which you are running PyCharm. We're listing this approach as experimental for the time being as it hasn't been fully tested; however, the implementation shows promise. The above local debugging configuration presumes that the Indigo Server and the plugin you are debugging are running on the same machine on which you are running PyCharm. It's also possible (and experimental at this point) to debug a plugin running on an Indigo Server on a separate Mac on the network from the one on which you are running PyCharm. We're listing this approach as experimental for the time being as it hasn't been fully tested; however, the implementation shows promise.
  
-The setup is isn't radically different than the local configuration outlined above: it's the same "Python Debug Server" configuration, EXCEPT that you specify an IP address. In the Debug configuration in PyCharm you specify the IP address of the Mac //PyCharm// is running on (local won't work, it has to be the IP address). In the plugin's init method, make the very first line of the init method:+The setup isn't radically different than the local configuration outlined above: it's the same "Python Debug Server" configuration, EXCEPT that you specify an IP address. In the Debug configuration in PyCharm you specify the IP address of the Mac //PyCharm// is running on (local won't work, it has to be the IP address). In the plugin's init method, make the very first line of the init method:
  
 <code> <code>
Line 172: Line 171:
  
 ==== Plugin Specific Interactive Shell ==== ==== Plugin Specific Interactive Shell ====
- 
 Another great debugging tool is the ability to open a scripting shell that's specific to your plugin's context. This shell is like the more general shell you get when you select the **Plugins->Open Scripting Shell** menu item, except that because we launch it as part of your plugin's startup, it has access to everything in your plugin. You can call methods that your plugin implements, inspect your plugin's objects, etc. Another great debugging tool is the ability to open a scripting shell that's specific to your plugin's context. This shell is like the more general shell you get when you select the **Plugins->Open Scripting Shell** menu item, except that because we launch it as part of your plugin's startup, it has access to everything in your plugin. You can call methods that your plugin implements, inspect your plugin's objects, etc.
  
 +==== Detecting if Your Plugin is in Debug Mode  ====
 +It may be useful for your plugin to be able to detect whether it has been loaded in Debug Mode (Plugin Menu > My Plugin > Enable/Reload in Debug Mode) and what debugger it's loaded in. This can reduce the kinds of "one off" debug logging levels that might be needed in your plugin. To do this, call this command:
  
-===== Tips, Tricks and Best Practices =====+<code> 
 +indigo.host.debugMode() 
 +</code>
  
-==== External Requirements ====+Possible values are currently these integers:
  
 +<code>
 +kPluginDebugMode_none = 0,
 +kPluginDebugMode_debugPdb = 100,
 +kPluginDebugMode_debugPudb,
 +kPluginDebugMode_debugPyCharm,
 +kPluginDebugMode_debugShell = 200
 +</code>
 +
 +===== Tips, Tricks and Best Practices =====
 +==== External Requirements ====
 Python has a huge collection of libraries/modules available on [[https://pypi.org|pypi.org]] and installable with the ''pip3'' command. Your plugin can use those libraries, and by specifying which of those libraries in a ''requirements.txt'' file, Indigo will automatically install those when your plugin first starts. Check out the [[https://www.indigodomo.com/docs/python_packages#python_packages_for_plugin_developers|Python Packages for Plugin Developers]] section of the developer docs (**starting with the 2023.2 release**) for more details. Python has a huge collection of libraries/modules available on [[https://pypi.org|pypi.org]] and installable with the ''pip3'' command. Your plugin can use those libraries, and by specifying which of those libraries in a ''requirements.txt'' file, Indigo will automatically install those when your plugin first starts. Check out the [[https://www.indigodomo.com/docs/python_packages#python_packages_for_plugin_developers|Python Packages for Plugin Developers]] section of the developer docs (**starting with the 2023.2 release**) for more details.
  
-One option for setting up your development environment would be to create a virtual environment into which you install/manage the libraries that your plugin will need. This is best done when you first start working on a plugin or when you make significant changes (additional libraries, etc). There's lots of information available online regarding setting up and working with virtual environments--it may be best to start at [[https://docs.python.org/3.11/library/venv.html|the source]].+One option for setting up your development environment would be to create a virtual environment into which you install/manage the libraries that your plugin will need. This is best done when you first start working on a plugin or when you make significant changes (additional libraries, etc.There's lots of information available online regarding setting up and working with virtual environments--it may be best to start at [[https://docs.python.org/3.11/library/venv.html|the source]].
  
 Once you create a virtual environment (let's say you named it ''venv''), this is what it's directory structure will look like: Once you create a virtual environment (let's say you named it ''venv''), this is what it's directory structure will look like:
Line 210: Line 222:
  
 And this will write out the packages you have installed in your ''venv'' that the host process will install for the user. The last step would be to remove (or just move out of the way) the ''Packages'' directory, and create a release for your plugin using whatever method you currently use. And this will write out the packages you have installed in your ''venv'' that the host process will install for the user. The last step would be to remove (or just move out of the way) the ''Packages'' directory, and create a release for your plugin using whatever method you currently use.
- 
  
 ==== Indigo Utilities ==== ==== Indigo Utilities ====
Line 222: Line 233:
  
 **//The indigo-clean-and-zip-plugin utility is especially useful for developers//**. You can use this utility to prepare your ''indigoPlugin'' file for distribution. The utility will inspect the plugin package and remove unnecessary files (such as ''.pyc'' files) and zip the plugin package to the same location as the plugin file. **//Using the clean and zip tool before publishing your plugin is highly recommended.//** **//The indigo-clean-and-zip-plugin utility is especially useful for developers//**. You can use this utility to prepare your ''indigoPlugin'' file for distribution. The utility will inspect the plugin package and remove unnecessary files (such as ''.pyc'' files) and zip the plugin package to the same location as the plugin file. **//Using the clean and zip tool before publishing your plugin is highly recommended.//**
 +
 ==== Linters ==== ==== Linters ====
 There are several utilities available to improve your code; one type of utility is often referred to as a "Linter" Linters inspect your code for things that you might want to address including: There are several utilities available to improve your code; one type of utility is often referred to as a "Linter" Linters inspect your code for things that you might want to address including:
   * Syntax problems,   * Syntax problems,
-  * Duplicated code segments,  +  * Duplicated code segments,
   * typos, and   * typos, and
   * other potential issues.   * other potential issues.
Line 238: Line 250:
 debug_mode_bool = bool(debug_mode) debug_mode_bool = bool(debug_mode)
 </code> </code>
- 
  
 ==== No Module Named 'indigo' ==== ==== No Module Named 'indigo' ====
Line 249: Line 260:
 </code> </code>
 You will likely still get a syntax error warning on the ''import indigo'' line, but this is preferable to many, many syntax warnings throughout your code base. You will likely still get a syntax error warning on the ''import indigo'' line, but this is preferable to many, many syntax warnings throughout your code base.
- 
- 
- 
  
  • /www/perceptive/wiki/data/attic/setting_up_a_development_environment.1719446928.txt.gz
  • Last modified: 2024/06/27 00:08
  • by 127.0.0.1