Wing Tipshttps://wingware.com/Tips, tricks, and helpful hints for Wingware's Python IDEsThu, 18 Apr 2019 13:29:48 GMTPyRSS2Gen-1.0.0http://www.dalkescientific.com/Python/PyRSS2Gen.htmlUsing Anaconda with Wing Python IDEhttps://wingware.com/blog/anaconda<p>In this issue of <a class="reference" href="/hints">Wing Tips</a> we take a look at how to use the <a class="reference" href="https://www.anaconda.com/distribution/">Anaconda Distribution</a> of Python with <a class="reference" href="/">Wing</a>.</p> <p>Anaconda's key advantage is its easy-to-use package management system. Anaconda comes with a large collection of third party packages that are not in an installation of Python from <a class="reference" href="https://python.org">python.org</a>. Many <a class="reference" href="https://docs.anaconda.com/anaconda/packages/pkg-docs/">additional packages</a> can be installed quickly and easily as needed, from the command line with <tt class="literal"><span class="pre">conda</span> <span class="pre">install</span></tt>.</p> <p>Anaconda's marketing focuses on data science and machine learning applications, but its extensive packages library makes it a good option also for other types of desktop and web development.</p> <p>There is much <a class="reference" href="https://www.bernat.tech/pep-517-518/">ongoing work</a> in the world of Python packaging but, at least for now, Anaconda seems to fail less often than other solutions for resolving dependencies and installing necessary packages automatically.</p> <div class="section"> <h3 class="title-3">Configuring the Environment</h3> <p>To use the Anaconda with Wing, simply set the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> used in your Wing project to Anaconda's <tt class="literal"><span class="pre">python</span></tt> or <tt class="literal"><span class="pre">python.exe</span></tt>. How you do this depends on whether you are creating a new project or have an existing project that you want to modify.</p> <div class="section"> <h4 class="title-4">New Projects</h4> <p>To create a new Wing project that uses Anaconda, select <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu and then under <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> select <tt class="literal"><span class="pre">Custom</span></tt> and enter the full path to Anaconda's <tt class="literal"><span class="pre">python</span></tt> or <tt class="literal"><span class="pre">python.exe</span></tt>.</p> <p>In many cases, Wing will automatically find Anaconda and include it in the drop down menu to the right of the entry area that enables when <tt class="literal"><span class="pre">Custom</span></tt> is chosen:</p> <img alt="/images/blog/anaconda/new-project.gif" backrefs="" caption="Shown Above: Choose &quot;New Project&quot; from the &quot;Project Menu&quot;, select &quot;Custom&quot; for &quot;Python Executable&quot;, find Anaconda in the drop down menu, and press &quot;OK&quot; to create the new project." class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/anaconda/new-project.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown Above: Choose "New Project" from the "Project Menu", select "Custom" for "Python Executable", find Anaconda in the drop down menu, and press "OK" to create the new project.</i></p><p>If Anaconda does not appear in Wing's list of available Python installations, and you don't know the full path to use, then you can start Anaconda from the command line outside of Wing and use the value printed by the following, when run interactively:</p> <pre class="literal-block"> import sys print(sys.executable) </pre> </div> <div class="section"> <h4 class="title-4">Existing Projects</h4> <p>To change an existing project to use Anaconda Python, the steps are the same as above except that the change is made under <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu.</p> </div> <div class="section"> <h4 class="title-4">Virtualenv</h4> <p>If you are using virtualenv with Anaconda, use the full path of the virtualenv's <tt class="literal"><span class="pre">python.exe</span></tt> or <tt class="literal"><span class="pre">python</span></tt> instead. When in doubt, you can print <tt class="literal"><span class="pre">sys.executable</span></tt> as already described to find the correct full path to use in Wing's <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> configuration.</p> </div> <div class="section"> <h4 class="title-4">☕ Et Voila!</h4> <p>In most cases, that is all that you need to do. Wing will start using your Anaconda installation immediately for source intelligence, for the next debug session, and in the integrated <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> after it is restarted from its <tt class="literal"><span class="pre">Options</span></tt> menu.</p> </div> </div> <div class="section"> <h3 class="title-3">Fixing Import Errors on Windows</h3> <p>On Windows, Anaconda may fail to load DLLs when its <tt class="literal"><span class="pre">python.exe</span></tt> is run directly from the command line or within Wing. This is due to the fact that by default the Anaconda installer no longer sets the <tt class="literal"><span class="pre">PATH</span></tt> that it needs to run, in order to avoid conflicting with different Python installations on the same system.</p> <div class="section"> <h4 class="title-4">Simple Solution</h4> <p>A simple solution to fix this problem is to run <tt class="literal"><span class="pre">Scripts\activate</span></tt> (located within your Anaconda installation) on the command line, and then start Wing from within the activated environment, for example with <tt class="literal"><span class="pre">c:\Program</span> <span class="pre">Files</span> <span class="pre">(x86)\Wing</span> <span class="pre">Pro</span> <span class="pre">7\bin\wing.exe</span></tt>. This causes Wing to inherit the necessary <tt class="literal"><span class="pre">PATH</span></tt> that was set up by Anaconda's <tt class="literal"><span class="pre">activate</span></tt> script.</p> <p>This solution works well if you will be using the same Anaconda installation for all projects that you open in a session. If you change to projects that use a different Python installation, you will need to quit and restart Wing in the correct environment.</p> </div> <div class="section"> <h4 class="title-4">Recommended Solutions</h4> <p>Our recommended solutions require a bit more work up front, but once in place they automatically set the necessary <tt class="literal"><span class="pre">PATH</span></tt> without the potential for polluting other Python installations with unwanted environment.</p> <p>A good one-time fix is to create a small wrapper script called <tt class="literal"><span class="pre">wrap_anaconda.bat</span></tt> and place the following into it:</p> <pre class="literal-block"> &#64;echo off set ANACONDA_DIR=%USERPROFILE%\Anaconda3 set PATH=%PATH%;%ANACONDA_DIR%;%ANACONDA_DIR%\DLLS;%ANACONDA_DIR%\Library;%ANACONDA_DIR%\Library\bin;%ANACONDA_DIR%\Scripts;%ANACONDA_DIR%\mingw-w64\bin %ANACONDA_DIR%\python.exe %* </pre> <p>You may need to change the value of <tt class="literal"><span class="pre">ANACONDA_DIR</span></tt> to match where Anaconda is installed on your system.</p> <p>Then set <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in Wing's <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> to the full path of this batch file. This sets up the necessary environment and then runs Anaconda's Python. No other configuration is necessary, and this script can also be used on the command line or in other IDEs.</p> <p>A similar solution that does not require creating a wrapper script is to set the necessary <tt class="literal"><span class="pre">PATH</span></tt> in Wing's <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>, from the <tt class="literal"><span class="pre">Project</span></tt> menu. Add the following to <tt class="literal"><span class="pre">Environment</span></tt> under the <tt class="literal"><span class="pre">Environment</span></tt> tab:</p> <pre class="literal-block"> ANACONDA_DIR=${USERPROFILE}\Anaconda3 PATH=${PATH};$(ANACONDA_DIR);${ANACONDA_DIR}\DLLS;${ANACONDA_DIR}\Library; ${ANACONDA_DIR}\Library\bin;${ANACONDA_DIR}\Scripts;${ANACONDA_DIR}\mingw-w64\bin </pre> <p>Again, you may need to change the value of <tt class="literal"><span class="pre">ANACONDA_DIR</span></tt> to match where Anaconda is installed on your system.</p> <p>Both of these solutions work well if there are multiple Python installations on your system, because it ensures that the correct <tt class="literal"><span class="pre">PATH</span></tt> is always set when the project is open, allowing other projects to use a different environment.</p> <br> <br><p>That's it for now! In next week's <a class="reference" href="/hints">Wing Tips</a> we'll get back to looking at some of the lesser-known but useful features in Wing.</p> </div> </div> https://wingware.com/blog/anacondaThu, 18 Apr 2019 01:00:00 GMTAuto-Editing in Wing Pro (Part 3 of 3)https://wingware.com/blog/wingpro-auto-editing-3<p>Wing Pro implements a suite of auto-editing operations that take care of common low-level editing tasks. In the previous installments of this 3-part <a class="reference" href="/hints">Wing Tips</a> series on Wing Pro's auto-editing features we looked at <a class="reference" href="/hints/wingpro-auto-editing-1">managing Python code blocks</a> and <a class="reference" href="/hints/wingpro-auto-editing-2">auto-invocation</a>.</p> <p>To finish up this series, let's take a look at PEP 8 compliant auto-spacing and a few less frequently needed but useful operations.</p> <div class="note"> <strong>Note:</strong> If you have Wing Personal, you don't have the features described here. We'll return to features that are also present in Wing Personal next time. Or <a class="reference" href="/">try Wing Pro</a> on a free trial.</div> <div class="section"> <h3 class="title-3">Auto-Entering Spaces and PEP 8</h3> <p>Wing Pro can auto-enter spacing as you type, but this operation is off by default since it may take some getting used to. Once enabled with the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-Editing</span> <span class="pre">&gt;</span> <span class="pre">Auto-Enter</span> <span class="pre">Spaces</span></tt> preference, you can type <tt class="literal"><span class="pre">x=1</span></tt> to get <tt class="literal"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">1</span></tt> or <tt class="literal"><span class="pre">i=range(x=0,10)</span></tt> to enter <tt class="literal"><span class="pre">i</span> <span class="pre">=</span> <span class="pre">range(x=0,</span> <span class="pre">10)</span></tt>. Spacing is entered in a PEP 8 compliant way.</p> <img alt="/images/blog/wingpro-auto-editing/auto-spacing.gif" backrefs="" caption="Shown above: Type &quot;t([1,2,3],y=f)&quot; without any spaces; PEP 8 compliant spacing is auto-entered as needed." class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/wingpro-auto-editing/auto-spacing.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Type "t([1,2,3],y=f)" without any spaces; PEP 8 compliant spacing is auto-entered as needed.</i></p><p>Some options for auto-spacing are available on the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-Editing</span></tt> preferences page, to control whether spaces are auto-entered after unambiguous keyword names are entered, whether to prevent insertion of spacing that is not PEP 8 compliant, and how to place spaces in type annotations.</p> <div class="note"> <strong>PEP 8 Reformatting:</strong> If you're interested in maintaining strict PEP 8 compliance, you can enable automatic PEP 8 reformatting in the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">PEP</span> <span class="pre">8</span></tt> preferences group. Reformatting takes place either after leaving an edited line or for the whole file when it is saved to disk. Or, trigger reformatting manually from the <tt class="literal"><span class="pre">Source</span> <span class="pre">&gt;</span> <span class="pre">PEP</span> <span class="pre">8</span></tt> menu group.</div> </div> <div class="section"> <h3 class="title-3">Correcting Out-of-Order Typing</h3> <p>Wing recognizes some types of out-of-order typing and adjusts them automatically, as a way to save on keystrokes. Some of the transformations include:</p> <table border="0" class="table" frame="border"> <colgroup> <col width="29%" /> <col width="71%" /> </colgroup> <thead valign="bottom"> <tr><th>Keys Pressed</th> <th>Keys Entered</th> </tr> </thead> <tbody valign="top"> <tr><td>if x(:)</td> <td>if x(): followed by a new line and indentation</td> </tr> <tr><td>def x(-)</td> <td>def x() -&gt; for entering a type annotation</td> </tr> <tr><td>x()t</td> <td>x().t</td> </tr> <tr><td>x(.y)</td> <td>x().y</td> </tr> <tr><td>x(,)</td> <td>x(),</td> </tr> </tbody> </table> <img alt="/images/blog/wingpro-auto-editing/out-of-order.gif" backrefs="" caption="Shown above: Type &quot;def x(:)&quot; to start the first def, &quot;def y(a,b-)&quot; for the second, and finally &quot;c=a,x(,)b&quot;" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/wingpro-auto-editing/out-of-order.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Type "def x(:)" to start the first def, "def y(a,b-)" for the second, and finally "c=a,x(,)b"</i></p></div> <div class="section"> <h3 class="title-3">Changing Type of Quotes on a String</h3> <p>When the caret is just after a string and a quote character is pressed, the quotes around the string are changed to that type of quote. This works with regular and triple-quoted strings, although it's most useful for regular strings when the string needs to be edited to contain a quote character.</p> <img alt="/images/blog/wingpro-auto-editing/change-quote.gif" backrefs="" caption="Shown above: Type 'x = &quot;test&quot;', move caret to right, and then press ' to change to single quotes so the string can contain a double quote" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/wingpro-auto-editing/change-quote.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Type 'x = "test"', move caret to right, and then press ' to change to single quotes so the string can contain a double quote</i></p><br> <br><p>That's it for our three-part <a class="reference" href="/hints">Wing Tips</a> series on auto-editing in Wing Pro. For details on all the available auto-editing operations, see <a class="reference" href="/doc/edit/auto-editing">Auto-Editing</a> in the Wing Pro manual.</p> <p>Auto-editing is just one way in which Wing helps with writing, testing, and debugging Python code. Next week we'll move on to some of the others.</p> </div> https://wingware.com/blog/wingpro-auto-editing-3Thu, 11 Apr 2019 01:00:00 GMTAuto-Editing in Wing Pro (Part 2 of 3)https://wingware.com/blog/wingpro-auto-editing-2<p>Wing Pro implements a suite of auto-editing operations that take care of common low-level editing tasks. <a class="reference" href="/hints/wingpro-auto-editing-1">Last week</a> we looked at creating and managing blocks in Python code.</p> <p>In part two of this <a class="reference" href="/hints">Wing Tips</a> series on Wing Pro's auto-editing feature we turn to auto-invocation, which makes writing Python code that calls functions and methods easier and less prone to errors.</p> <div class="note"> <strong>Note:</strong> If you have Wing Personal, you don't have these features. Please bear with us through this and the next installment in this series. We'll return to features that are also present in Wing Personal after that. Or <a class="reference" href="/">try Wing Pro</a> on a free trial.</div> <div class="section"> <h3 class="title-3">Auto-Enter Invocation Args</h3> <p>When an invocation is typed in Wing Pro, for example <tt class="literal"><span class="pre">getattr(</span></tt>, the editor temporarily inserts all the arguments for <tt class="literal"><span class="pre">getattr</span></tt> and enters a data entry mode in which the <tt class="literal"><span class="pre">Tab</span></tt> key can be used to move between the arguments and default values. When the caret moves out of the argument list, data entry mode ends and any unchanged default arguments are removed.</p> <img alt="/images/blog/wingpro-auto-editing/auto-invocation.gif" backrefs="" caption="Shown above: Type &quot;self.a&quot; followed by Tab for completion, Tab five times to reach the last argument value, and then &quot;Fa&quot; followed by tab for completion; after leaving the invocation, unchanged default arguments are removed." class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/wingpro-auto-editing/auto-invocation.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Type "self.a" followed by Tab for completion, Tab five times to reach the last argument value, and then "Fa" followed by tab for completion; after leaving the invocation, unchanged default arguments are removed.</i></p><p>In cases like the above, where locals are named the same as the required arguments, very little extra work is needed to complete the invocation. In other cases, you may just want to overtype what Wing enters, which is easy to do since the all the arguments are initially selected.</p> <div class="note"> <strong>Configuring Python:</strong> Auto-invocation and many of Wing Pro's other features rely on the IDE's analysis of your source code and the modules that you import. This only works if Wing knows which Python you are using and where to look for modules. In most cases, setting <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu is all you'll need. This should be set to the value of <tt class="literal"><span class="pre">sys.executable</span></tt> (after <tt class="literal"><span class="pre">import</span> <span class="pre">sys</span></tt>) in the target Python installation. In some cases you may also need to add to <tt class="literal"><span class="pre">Python</span> <span class="pre">Path</span></tt> in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>, so all the modules you import can be found.</div> </div> <div class="section"> <h3 class="title-3">Auto-Entering Overridden Methods</h3> <p>A similar auto-editing operation enters an overridden method's arguments, when defining a method that overrides a method in an inherited class.</p> <img alt="/images/blog/wingpro-auto-editing/auto-override.gif" backrefs="" caption="Shown above: Type &quot;def G&quot; followed by Tab for completion, and then ``:`` to move into the method body; method arguments are auto-entered based on the overridden method in class CNewsPage." class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/wingpro-auto-editing/auto-override.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Type "def G" followed by Tab for completion, and then ``:`` to move into the method body; method arguments are auto-entered based on the overridden method in class CNewsPage.</i></p></div> <div class="section"> <h3 class="title-3">Nested Invocations</h3> <p>Nested invocations are also supported, for cases where another invocation is made within an outer invocation.</p> <img alt="/images/blog/wingpro-auto-editing/recursive-invoke.gif" backrefs="" caption="Shown above: Type &quot;d = join(&quot; to start invocation, press Tab to move to first argument, enter &quot;convert(&quot; to start recursive invocation, enter arguments for &quot;convert&quot; by tabbing between them, Tab to return to and complete invocation of &quot;join&quot;." class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/wingpro-auto-editing/recursive-invoke.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Type "d = join(" to start invocation, press Tab to move to first argument, enter "convert(" to start recursive invocation, enter arguments for "convert" by tabbing between them, Tab to return to and complete invocation of "join".</i></p><br><br><p>That's it for now. In the next and last part of this 3-part <a class="reference" href="/hints">Wing Tips</a> series on Wing Pro's auto-editing features we'll be looking at auto-spacing, PEP 8, and a few other operations.</p> </div> https://wingware.com/blog/wingpro-auto-editing-2Thu, 04 Apr 2019 01:00:00 GMTAuto-Editing in Wing Pro (Part 1 of 3)https://wingware.com/blog/wingpro-auto-editing-1<p><a class="reference" href="/">Wing Pro</a> implements a suite of auto-editing operations that take care of common low-level editing tasks, like moving Python code into a new block, entering invocation arguments, and maintaining PEP 8 compliance as you type. Some of the simpler auto-editing operations, like auto-closing <tt class="literal"><span class="pre">(</span></tt> or <tt class="literal"><span class="pre">[</span></tt>, are enabled by default and easy to understand. Others may be missed unless you know about them, and some need to be enabled in preferences before they can be used.</p> <p>In this and the next two installments of <a class="reference" href="/hints">Wing Tips</a> we'll be looking at some useful Wing Pro auto-editing operations that are not so easy to discover.</p> <div class="note"> <strong>Note:</strong> If you have Wing Personal, you don't have these features. Please bear with us through this and the next two installments. We'll return to features that are also present in Wing Personal after that. Or <a class="reference" href="/">try Wing Pro</a> on a free trial.</div> <div class="section"> <h3 class="title-3">Creating Blocks with the Colon Key</h3> <p>To quickly turn an existing section of Python code into a new block, select it and then press the colon key. Wing Pro indents the selected lines and positions the caret so you can type <tt class="literal"><span class="pre">if</span></tt>, <tt class="literal"><span class="pre">for</span></tt>, <tt class="literal"><span class="pre">while</span></tt>, <tt class="literal"><span class="pre">def</span></tt> or any other keyword that starts a block.</p> <img alt="/images/blog/wingpro-auto-editing/apply-colon.gif" backrefs="" caption="Shown above: Select lines then type &quot;:if ar&quot; followed by Tab for auto-completion; a new block is created from the selection." class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/wingpro-auto-editing/apply-colon.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Select lines then type ":if ar" followed by Tab for auto-completion; a new block is created from the selection.</i></p></div> <div class="section"> <h3 class="title-3">Creating a Try/Except Block</h3> <p>If you select lines of Python code and type <tt class="literal"><span class="pre">:try</span></tt> Wing adds <tt class="literal"><span class="pre">except</span></tt> automatically and selects it so you can either replace <tt class="literal"><span class="pre">except</span></tt> with <tt class="literal"><span class="pre">finally</span></tt>, press the right arrow key to enter an exception specifier, and/or use <tt class="literal"><span class="pre">Tab</span></tt> to move into the <tt class="literal"><span class="pre">except</span></tt> or <tt class="literal"><span class="pre">finally</span></tt> block.</p> <img alt="/images/blog/wingpro-auto-editing/apply-colon-try.gif" backrefs="" caption="Shown above: Select lines then type &quot;:try&quot; followed Right Arrow, Space, &quot;P&quot;, Tab to auto-complete &quot;ParseError&quot;, and then Tab to move into the except block." class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/wingpro-auto-editing/apply-colon-try.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Select lines then type ":try" followed Right Arrow, Space, "P", Tab to auto-complete "ParseError", and then Tab to move into the except block.</i></p><div class="note"> <strong>Note:</strong> Other keys can also be applied to selections. For example <tt class="literal"><span class="pre">&quot;</span></tt> encloses the selection in quotes, <tt class="literal"><span class="pre">(</span></tt> encloses it in parenthesis, and <tt class="literal"><span class="pre">#</span></tt> toggles whether it is commented out.</div> </div> <div class="section"> <h3 class="title-3">Creating Blocks without Selecting</h3> <p>It's also possible to create new blocks without selecting any lines first. In some versions of Wing, this option needs to be enabled with the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-Editing</span> <span class="pre">&gt;</span> <span class="pre">Manage</span> <span class="pre">Blocks</span> <span class="pre">on</span> <span class="pre">Repeated</span> <span class="pre">Colon</span> <span class="pre">Presses</span></tt> preference. Once that is done and a new block is entered, the colon key can be pressed a second time to move the next line into the new block, and a third time to also move the rest of a contiguous block of lines into the new block.</p> <img alt="/images/blog/wingpro-auto-editing/colon-manage.gif" backrefs="" caption="Shown above: Type &quot;if use_&quot; followed by Tab for completion and ``:`` three times to pull more and more code into the new block." class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/wingpro-auto-editing/colon-manage.gif" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Type "if use_" followed by Tab for completion and ``:`` three times to pull more and more code into the new block.</i></p><p>Note that you can also just select a block of code and press the <tt class="literal"><span class="pre">Tab</span></tt> key to reindent it. If multiple indentations are possible for that block, Wing toggles between them each time you press <tt class="literal"><span class="pre">Tab</span></tt>.</p> <br> <br><p>That's it for now. In the next part of this 3-part <a class="reference" href="/hints">Wing Tips</a> series on auto-editing in Wing Pro we'll be looking at auto-invocation, which makes writing Python code that calls functions and methods easier and less prone to errors.</p> </div> https://wingware.com/blog/wingpro-auto-editing-1Thu, 28 Mar 2019 01:00:00 GMTDeveloping and Debugging Python Code Running on Vagrant Containershttps://wingware.com/blog/vagrant<img src="https://wingware.com/images/screenshots/wing6-screenshot-dark.png" width=560 height=419 class="eye-candy-image"><p><a class="reference" href="http://www.vagrantup.com/">Vagrant</a> provides a way to set up lightweight containers that are isolated from your host OS. Containers are very useful in software development because they are easy to share with other developers, so that everybody on a software development team is working with exactly the same coding environment.</p> <p>However, since these containers are often fairly stripped down, developing and debugging on the container may not be as convenient as working on your regular development system.</p> <p>One way to make this easier for Python is to set up remote development from <a class="reference" href="https://wingware.com">Wing Pro</a>. In this model, code is developed, tested, and debugged on the container from a copy of Wing Pro running on your regular desktop or laptop system.</p> <div class="section"> <h3 class="title-3">Prerequisites</h3> <p>This guide assumes you have already installed and started using <a class="reference" href="http://www.vagrantup.com/">Vagrant</a>. Wing Pro supports working with Vagrant boxes running Linux (32-bit or 64-bit) or OS X. As of now, other OS types such as FreeBSD won't work.</p> <p>You will also need to make sure that Python is installed in the Vagrant box. If Python is not present, Wing Pro's remote agent installation process will fail.</p> <p>On Windows, you may need to install PuTTY or one of the OpenSSH ports if you don't already have this set up, so you can connect to the Vagrant container. See <a class="reference" href="/doc/proj/ssh-setup-details">SSH Setup Details</a> in Wing Pro's documentation for details.</p> <p>If you do not already have Wing Pro installed, <a class="reference" href="https://wingware.com/downloads/wingpro">download it now</a>.</p> </div> <div class="section"> <h3 class="title-3">Creating a Project</h3> <p>After you have started Wing Pro, creating a project for an existing Vagrant container is easy:</p> <div class="ordered-list"><ul><li><span class="bullet"> Start your container as usual, with <tt class="literal"><span class="pre">vagrant</span> <span class="pre">up</span></tt></span></li> <li><span class="bullet"> Use <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu in Wing Pro and then select <tt class="literal"><span class="pre">Connect</span> <span class="pre">to</span> <span class="pre">Vagrant</span></tt> as your project type</span></li> <li><span class="bullet"> Fill in or browse to the full path of your Vagrant project directory which contains your <tt class="literal"><span class="pre">Vagrantfile</span></tt> and press <tt class="literal"><span class="pre">OK</span></tt></span></li> <li><span class="bullet"> Only on Windows with PuTTY, you will be asked to convert Vagrant's private key into a PuTTY key. To do this, Wing starts <tt class="literal"><span class="pre">puttygen</span></tt> with the private key already loaded into it. Press <tt class="literal"><span class="pre">Save</span> <span class="pre">private</span> <span class="pre">key</span></tt> to save the key as <tt class="literal"><span class="pre">private_key.ppk</span></tt> in the current directory. Confirm saving without password (the original also doesn't have a password) and then quit <tt class="literal"><span class="pre">puttygen</span></tt> to continue the project setup process in Wing.</span></li> <li><span class="bullet"> Install the remote agent when prompted.</span></li> </ul></div><p>Once this is done, Wing should confirm that the remote agent installation is working.</p> <p>Then you can add your source directories to the project with <tt class="literal"><span class="pre">Add</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. Finally, use <tt class="literal"><span class="pre">Save</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu to write Wing Pro's project file to local disk.</p> <p>You can now edit, debug, test, search, and manage files on the Vagrant container, or launch commands running in the container from Wing Pro's <tt class="literal"><span class="pre">OS</span> <span class="pre">Commands</span></tt> tool. Even though Wing Pro is running on your host OS, everything you do takes place in the Vagrant container, as controlled by the remote agent.</p> <p>If you have any problems getting this to work, feel free to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> for help.</p> <p>To learn more about Wing Pro's remote development capabilities, see <a class="reference" href="/doc/proj/remote-hosts">Remote Hosts</a>.</p> <p>To learn more about Wing Pro's features, take a look at the Tutorial in the <tt class="literal"><span class="pre">Help</span></tt> menu or the <a class="reference" href="/doc/howtos/quickstart">Quickstart Guide</a>.</p> </div> <div class="section"> <h3 class="title-3">How It Works</h3> <p>Wing uses <tt class="literal"><span class="pre">vagrant</span> <span class="pre">ssh-config</span></tt> to inspect your Vagrant container and fill in the necessary settings in Wing's project file. Then all communication with the container is through SSH.</p> <p>To see the settings that Wing created during <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt>, take a look at <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu. The <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> was set to point to a remote host named <tt class="literal"><span class="pre">vagrant</span></tt>. Click on <tt class="literal"><span class="pre">Edit</span></tt> here or use <tt class="literal"><span class="pre">Remote</span> <span class="pre">Hosts</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu to access the remote host configuration. The values that Wing sets up are: <tt class="literal"><span class="pre">Identifier</span></tt>, <tt class="literal"><span class="pre">Hostname</span></tt>, and <tt class="literal"><span class="pre">WINGHOME</span></tt> under the <tt class="literal"><span class="pre">General</span></tt> tab, and <tt class="literal"><span class="pre">SSH</span> <span class="pre">Port</span></tt> and <tt class="literal"><span class="pre">Private</span> <span class="pre">Key</span></tt> under the <tt class="literal"><span class="pre">Options</span></tt> tab. Settings these values manually achieves exactly the same result as using <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt>.</p> <p>The installation process will also add the Vagrant container's SSH host key as a known host in <tt class="literal"><span class="pre">~/.ssh/known_hosts</span></tt> or in the registry if using PuTTY on Windows.</p> </div> <div class="section"> <h3 class="title-3">Usage Hints</h3> <div class="section"> <h4 class="title-4">Selecting the Python Installation</h4> <p>In cases where Wing is not picking up the right Python to use automatically, for example if multiple installations of Python are present on the Vagrant container, you can select the correct one with <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in the remote host configuration, which you can access from <tt class="literal"><span class="pre">Remote</span> <span class="pre">Hosts</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu.</p> <p>To check that the correct installation is being used, select <tt class="literal"><span class="pre">Restart</span> <span class="pre">Shell</span></tt> from the <tt class="literal"><span class="pre">Options</span></tt> menu of the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> tool and type the following in the shell:</p> <pre class="literal-block"> import sys sys.executable </pre> </div> <div class="section"> <h4 class="title-4">Synced Folders</h4> <p>As far as Wing is concerned, all files and directories are located in the Vagrant container and Wing never accesses local copies of the files maintained by Vagrant's synchronization commands.</p> <p>If you need to update your local copies of files for some other reason while working with Wing, run <tt class="literal"><span class="pre">vagrant</span> <span class="pre">rsync</span></tt>, or set up continuous synchronization with <tt class="literal"><span class="pre">vagrant</span> <span class="pre">rsync-auto</span></tt>.</p> </div> <div class="section"> <h4 class="title-4">Password-less Private Keys</h4> <p>Vagrant uses password-less private keys by default. If you want to use private keys with passwords, you'll need to load the key into the SSH user agent (<tt class="literal"><span class="pre">ssh-agent</span></tt> or <tt class="literal"><span class="pre">pageant</span></tt> for PuTTY) and change <tt class="literal"><span class="pre">Options</span> <span class="pre">&gt;</span> <span class="pre">Private</span> <span class="pre">Key</span></tt> in Wing's <tt class="literal"><span class="pre">vagrant</span></tt> remote host configuration to <tt class="literal"><span class="pre">Use</span> <span class="pre">SSH</span> <span class="pre">User</span> <span class="pre">Agent</span></tt>.</p> </div> </div> <div class="section"> <h3 class="title-3">Related Documents</h3> <p>For more information see:</p> <div class="bullet-list"><ul><li><span class="bullet"> <a class="reference" href="http://vagrantup.com/">Vagrant home page</a> provides downloads and documentation.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/proj/remote-hosts">Remote Hosts</a> for details on configuring remote development in Wing Pro.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/howtos/quickstart">Quickstart Guide</a> contains additional basic information about getting started with Wing Pro.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/intro/tutorial">Tutorial</a> provides a gentler introduction to Wing Pro's features.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/manual">Wing Pro Reference Manual</a> documents Wing Pro in detail.</span></li> </ul></div></div> https://wingware.com/blog/vagrantTue, 25 Sep 2018 01:00:00 GMTUsing Wing Pro with Windows Subsystem for Linuxhttps://wingware.com/blog/wsl<img src="https://wingware.com/images/screenshots/wing6-screenshot-dark.png" width=560 height=419 class="eye-candy-image"><p><a class="reference" href="https://wingware.com">Wing Pro</a> is a Python IDE that can be used to develop, test, and debug Python code running on <a class="reference" href="https://docs.microsoft.com/en-us/windows/wsl/about">Windows Subsystem for Linux</a> (WSL).</p> <p>This document describes how to configure Wing Pro for WSL. To get started using Wing Pro as your Python IDE, please refer to the tutorial in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu or read the <a class="reference" href="/doc/howtos/quickstart">Quickstart Guide</a>.</p> <div class="section"> <h3 class="title-3">Prerequisites</h3> <p>To use Wing Pro with <a class="reference" href="https://docs.microsoft.com/en-us/windows/wsl/about">WSL</a> you will need to install Python on WSL and be able to SSH from Windows into WSL without entering a password. If you haven't already done this, see <tt class="literal"><span class="pre">Setting</span> <span class="pre">up</span> <span class="pre">WSL</span></tt> below before trying to create a project in Wing Pro.</p> <p>If you do not already have Wing Pro installed, <a class="reference" href="https://wingware.com/downloads/wingpro">download it now</a>.</p> </div> <div class="section"> <h3 class="title-3">Creating a Project</h3> <p>To create a Wing Pro project that accesses Linux under WSL:</p> <div class="ordered-list"><ul><li><span class="bullet"> Use <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu and then select <tt class="literal"><span class="pre">Connect</span> <span class="pre">to</span> <span class="pre">WSL</span></tt> as your project type.</span></li> <li><span class="bullet"> Set <tt class="literal"><span class="pre">Identifier</span></tt> to <tt class="literal"><span class="pre">wsl</span></tt> or some other short name for the WSL-hosted Linux.</span></li> <li><span class="bullet"> Set <tt class="literal"><span class="pre">Host</span> <span class="pre">Name</span></tt> to <tt class="literal"><span class="pre">username&#64;127.0.0.1</span></tt> where <tt class="literal"><span class="pre">username</span></tt> is replaced with the user name running on Linux. The user name is needed even if it is the same as the user running on Windows.</span></li> <li><span class="bullet"> Set <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to <tt class="literal"><span class="pre">/usr/bin/python3</span></tt> or the full path to the Python executable you wish to use on Linux.</span></li> <li><span class="bullet"> If you are running the SSH server on Linux under a non-standard port, set <tt class="literal"><span class="pre">SSH</span> <span class="pre">Port</span></tt> under the <tt class="literal"><span class="pre">Options</span></tt> tab.</span></li> <li><span class="bullet"> Leave the rest of the configuration values set to their defaults and press <tt class="literal"><span class="pre">OK</span></tt>.</span></li> </ul></div><p>Wing Pro should install the remote agent and confirm that it is working. Then you can add files and directories and configure your project from the <tt class="literal"><span class="pre">Project</span></tt> menu. You will be able to edit, debug, test, search, and manage files on the WSL-hosted Linux installation, or launch commands running on Linux from Wing Pro's <tt class="literal"><span class="pre">OS</span> <span class="pre">Commands</span></tt> tool.</p> <p>To learn more about Wing Pro's remote development capabilities, see <a class="reference" href="/doc/proj/remote-hosts">Remote Hosts</a>.</p> <p>To learn more about Wing Pro's features, take a look at the Tutorial in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu or the <a class="reference" href="/doc/howtos/quickstart">Quickstart Guide</a>.</p> <p><strong>Notes</strong></p> <p>Selecting the <tt class="literal"><span class="pre">Connect</span> <span class="pre">to</span> <span class="pre">WSL</span></tt> project type when creating your project automatically unchecks <tt class="literal"><span class="pre">Use</span> <span class="pre">SSH</span> <span class="pre">Tunnel</span> <span class="pre">for</span> <span class="pre">username&#64;localhost</span></tt> under the <tt class="literal"><span class="pre">Advanced</span></tt> tab of the remote host configuration. Other than this, the remote host configuration created in the above instructions is the same as for any other remote host.</p> </div> <div class="section"> <h3 class="title-3">Setting up WSL</h3> <p>Here is one way to set up WSL with Ubuntu as the Linux distribution and PuTTY as the SSH client:</p> <p><strong>Enable WSL and Install Ubuntu Linux:</strong></p> <div class="bullet-list"><ul><li><span class="bullet"> Enable WSL in Windows 10+. This is done in the Settings app under Apps &gt; Apps &amp; features &gt; Related settings / Programs and features &gt; Turn Windows features on and off. Restart when prompted.</span></li> <li><span class="bullet"> Install Ubuntu from the Microsoft Store.</span></li> <li><span class="bullet"> Install Python in Ubuntu with <tt class="literal"><span class="pre">sudo</span> <span class="pre">apt-get</span> <span class="pre">install</span> <span class="pre">python3</span></tt></span></li> </ul></div><p><strong>Set up password-less SSH access to Ubuntu:</strong></p> <div class="bullet-list"><ul><li><span class="bullet"> Install <a class="reference" href="https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html">PuTTY</a> if you don't already have it. You should install all the tools from the <tt class="literal"><span class="pre">MSI</span></tt> installer.</span></li> <li><span class="bullet"> Create an SSH key pair and add it to <tt class="literal"><span class="pre">~/.ssh/authorized_keys</span></tt> on Ubuntu, as described in <a class="reference" href="/doc/proj/ssh-setup-details-putty">Working with PuTTY</a>.</span></li> </ul></div><p><strong>Each time you restart Windows or Ubuntu:</strong></p> <div class="bullet-list"><ul><li><span class="bullet"> Start <tt class="literal"><span class="pre">pageant</span></tt> from Windows and right-click on the icon that appears in the lower right of Windows to load your private key into Pageant.</span></li> <li><span class="bullet"> Run <tt class="literal"><span class="pre">sudo</span> <span class="pre">service</span> <span class="pre">ssh</span> <span class="pre">--full-restart</span></tt> on Ubuntu to make sure the SSH server is started.</span></li> </ul></div><p>Now running <tt class="literal"><span class="pre">plink</span> <span class="pre">username&#64;127.0.0.1</span></tt> on Windows should connects to Ubuntu without prompting for a password.</p> <p><strong>Notes</strong></p> <p>In the unlikely event that you already have an SSH server running somewhere on your system on port 22, you will need to change the port number used on Ubuntu in <tt class="literal"><span class="pre">/etc/ssh/ssh_config</span></tt> and then execute <tt class="literal"><span class="pre">sudo</span> <span class="pre">service</span> <span class="pre">ssh</span> <span class="pre">--full-restart</span></tt> again.</p> <p>Other Linux distributions are available in the Microsoft Store.</p> <p>It is also possible to use Open SSH instead of PuTTY. See <a class="reference" href="/doc/proj/ssh-setup-details-openssh">Working with OpenSSH</a> for details.</p> </div> <div class="section"> <h3 class="title-3">Resources</h3> <p>For more information see:</p> <div class="bullet-list"><ul><li><span class="bullet"> <a class="reference" href="https://docs.microsoft.com/en-us/windows/wsl/about">Windows Subsystem for Linux</a> provides information on getting starting with WSL.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/proj/remote-hosts">Remote Hosts</a> for details on configuring remote development.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/howtos/quickstart">Quickstart Guide</a> contains additional basic information about getting started with Wing Pro.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/intro/tutorial">Tutorial</a> provides a gentler introduction to Wing Pro's features.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/manual">Wing Reference Manual</a> documents Wing Pro in detail.</span></li> </ul></div></div> https://wingware.com/blog/wslSun, 16 Sep 2018 01:00:00 GMTUsing Wing Pro for Remote Python Web Developmenthttps://wingware.com/blog/remote-web-dev<img src="https://wingware.com/images/screenshots/wing6-screenshot-dark.png" width=560 height=419 class="eye-candy-image"><p><a class="reference" href="https://wingware.com/">Wing Pro</a> is a Python IDE that can be used to develop, test, and debug websites running on a remote server, VM, or other system where an IDE cannot be installed. Debugging takes place in the context of the web server or web framework, as code is invoked by browser page load. Wing provides auto-completion, call tips, find uses, and many other features that help you work with Python code.</p> <p>If you do not already have Wing Pro installed, <a class="reference" href="https://wingware.com/downloads/wingpro">download it now</a> so that you can follow along with the configuration steps described below.</p> <p>This article focuses specifically on how to configure Wing for remote web development. If you want to know more about Wing's features in general, please refer to the <tt class="literal"><span class="pre">Tutorial</span></tt> in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu or read the <a class="reference" href="/doc/howtos/quickstart">Quickstart Guide</a>.</p> <p>See also <a class="reference" href="/doc/howtos/web">Web Development How-Tos</a> for configuration tips for specific web frameworks, such as <a class="reference" href="/doc/howtos/django">Django</a>, <a class="reference" href="/doc/howtos/flask">Flask</a>, and others.</p> <div class="section"> <h3 class="title-3">Setting up SSH Access</h3> <p>Wing Pro's <a class="reference" href="/doc/proj/remote-hosts">remote development support</a> assumes that you have already set up password-less remote access to the remote host. This means that you should have your SSH key loaded into the SSH agent so that you can type <tt class="literal"><span class="pre">ssh</span> <span class="pre">hostname</span></tt> or equivalent on the command line to connect to the remote host without entering a password.</p> <p>If you don't already have this working, see <a class="reference" href="/doc/proj/ssh-setup-details">SSH Setup Details</a> for instructions.</p> </div> <div class="section"> <h3 class="title-3">Installing the Remote Agent</h3> <p>The next step is to set up a remote host configuration from <tt class="literal"><span class="pre">Remote</span> <span class="pre">Hosts</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. Press the <tt class="literal"><span class="pre">+</span></tt> icon to add a new remote host configuration.</p> <p>You will need to choose an identifier that Wing will use to refer to the host, enter the hostname (optionally in <tt class="literal"><span class="pre">username&#64;hostname</span></tt> form) and specify where on the remote host you want Wing to install its remote agent (this directory is referred to as <tt class="literal"><span class="pre">WINGHOME</span></tt>). You will only rarely need to specify any of the other values in a remote host configuration. For now, leave them blank. For example:</p> <img alt="/images/blog/remote-web-dev/remote-host-config.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/remote-host-config.png" /><p>Once you submit the dialog for creating the configuration, Wing will try to probe that remote host. It will fail and then prompt to install the remote agent like this:</p> <img alt="/images/blog/remote-web-dev/probe-failed.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/probe-failed.png" /><p>Press <tt class="literal"><span class="pre">Install</span> <span class="pre">Remote</span> <span class="pre">Agent</span></tt>. After the installation is complete, Wing probes again and should show a success dialog with some information about the remote host:</p> <img alt="/images/blog/remote-web-dev/probe-succeeded.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/probe-succeeded.png" /><p>Next return to the <tt class="literal"><span class="pre">Remote</span> <span class="pre">Hosts</span></tt> dialog and click on the checkbox under <tt class="literal"><span class="pre">Shared</span></tt>. This specifies that the remote host configuration you've just created should be shared by all projects, so that it isn't just stored in the currently open project:</p> <img alt="/images/blog/remote-web-dev/remote-config-shared.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/remote-config-shared.png" /></div> <div class="section"> <h3 class="title-3">Setting up a Project</h3> <p>Now it's time to set up a project that accesses your files on the remote host. To do this, select <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu and use the <tt class="literal"><span class="pre">Generic</span> <span class="pre">Python</span></tt> project type:</p> <img alt="/images/blog/remote-web-dev/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/new-project.png" /><p>There is also a project type for remote projects, but let's use the <tt class="literal"><span class="pre">Generic</span> <span class="pre">Python</span></tt> project type so that you will see where the relevant configuration takes place.</p> <p>Click <tt class="literal"><span class="pre">OK</span></tt> to create the project, and then go into <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu. Set the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to <tt class="literal"><span class="pre">Remote</span></tt> and select the remote host you've just configured:</p> <img alt="/images/blog/remote-web-dev/project-props.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/project-props.png" /><p>Next add your files to the project with the <tt class="literal"><span class="pre">Add</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> item in the <tt class="literal"><span class="pre">Project</span></tt> menu. Press the <tt class="literal"><span class="pre">Browse...</span></tt> button next to the <tt class="literal"><span class="pre">Directory</span></tt> field to display a dialog that browses the file system on the remote host. Go into the directory you want to add and press <tt class="literal"><span class="pre">Select</span> <span class="pre">Directory</span></tt>.</p> <p>Wing will spend some time scanning the disk and analyzing files but you should already be able to open and edit source files stored on the remote host by double clicking on them in the <tt class="literal"><span class="pre">Project</span></tt> tool.</p> </div> <div class="section"> <h3 class="title-3">Starting Debug</h3> <p>There are two ways to start debug on your remote host: (1) In some cases, you can launch your web framework directly from the IDE, which uses its remote agent to run your code on the configured remote host, or (2) in many cases the web server or web framework is started from outside the IDE, so debug needs to be initiated from the outside.</p> <p>You may already know which of these options you need to choose. If not, look at <a class="reference" href="/doc/howtos/web">How-Tos for Web Development</a> to see if there are configuration tips for your web development framework.</p> <div class="section"> <h4 class="title-4">Launching From the IDE</h4> <p>If you can launch your web framework from the IDE, just open the Python file that serves as its main entry point, select <tt class="literal"><span class="pre">Set</span> <span class="pre">Current</span> <span class="pre">As</span> <span class="pre">Main</span> <span class="pre">Debug</span> <span class="pre">File</span></tt> from the <tt class="literal"><span class="pre">Debug</span></tt> menu, and start debugging with <tt class="literal"><span class="pre">Debug/Continue</span></tt> in the <tt class="literal"><span class="pre">Debug</span></tt> menu or by using the <img alt="debug" backrefs="" class="inline-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/continue.png" /> icon in the toolbar.</p> <p>If you need to add some command line arguments to pass to your code, right click on the main debug file, select <tt class="literal"><span class="pre">Properties</span></tt>, and enter the arguments under the <tt class="literal"><span class="pre">Debug/Execute</span></tt> tab.</p> </div> <div class="section"> <h4 class="title-4">Externally Launched Code</h4> <p>For cases where you can't launch your debug code from the IDE, Wing provides a module <tt class="literal"><span class="pre">wingdbstub.py</span></tt> that you can import to initiate debug.</p> <p>When you installed the remote agent above, Wing wrote a preconfigured copy of <tt class="literal"><span class="pre">wingdbstub.py</span></tt> to the <tt class="literal"><span class="pre">WINGHOME</span></tt> directory you specified in your remote host configuration. Copy that file to the same directory as your code and add the following to your code before it reaches anything you'll want to debug:</p> <pre class="literal-block"> import wingdbstub </pre> <p>Next tell Wing to listen for connections from an externally launched debug process. This is done by clicking on the bug icon in the lower left of Wing's window and checking on <tt class="literal"><span class="pre">Accept</span> <span class="pre">Debug</span> <span class="pre">Connections</span></tt>:</p> <img alt="/images/blog/remote-web-dev/accept-debug-connections.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/accept-debug-connections.png" /><p>If you hover the mouse over the bug icon, Wing shows that it is listening for connections, both on the local host and on the configured remote host:</p> <img alt="/images/blog/remote-web-dev/listen-state.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/listen-state.png" /><p><strong>Note:</strong> If you are using <tt class="literal"><span class="pre">apache</span></tt> or your code runs as a user that is different from the one used in your remote host configuration, you'll need to adjust permissions on some files as described in the section <tt class="literal"><span class="pre">Managing</span> <span class="pre">Permissions</span></tt> below.</p> </div> </div> <div class="section"> <h3 class="title-3">Debugging Code</h3> <p>Now you can set some breakpoints by clicking on the breakpoint margin to the left of your code. For example:</p> <img alt="/images/blog/remote-web-dev/breakpoint-set.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/breakpoint-set.png" /><p>Once this is done you can point your browser at a web page that executes code with a breakpoint, and Wing should stop on it:</p> <img alt="/images/blog/remote-web-dev/breakpoint-reached.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/breakpoint-reached.png" /><p>Use <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> in the <tt class="literal"><span class="pre">Tools</span></tt> menu to view the stack and debug data:</p> <img alt="/images/blog/remote-web-dev/stack-data.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/stack-data.png" /><p>Or just interact with the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Probe</span></tt> tool (also in the <tt class="literal"><span class="pre">Tools</span></tt> menu), which is an auto-completing Python command shell that runs within the current debug stack frame:</p> <img alt="/images/blog/remote-web-dev/debug-probe.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-web-dev/debug-probe.png" /><p>This technique should work with any web development framework. See <a class="reference" href="/doc/howtos/web">Web Development How-Tos</a> for details on using Wing with specific frameworks.</p> </div> <div class="section"> <h3 class="title-3">Managing Permissions</h3> <p>If you are debugging code that is running under Apache or another web server, the code is being run as a user that may not be the same as the one you used when installing the remote agent. For example, your remote host configuration may set <tt class="literal"><span class="pre">Hostname</span></tt> to <tt class="literal"><span class="pre">devel&#64;192.168.0.50</span></tt> while the code is actually run by the user <tt class="literal"><span class="pre">apache</span></tt>.</p> <p>In this case, Wing will not accept the debug connection because the security token from the user running the code does not match what Wing is expecting from the way it installed and configured the remote agent.</p> <p>To solve this, go into the <tt class="literal"><span class="pre">WINGHOME</span></tt> where you installed the remote agent and change the permissions of the file <tt class="literal"><span class="pre">wingdebugpw</span></tt> so that the user running the code can also read it. For example, if both your users are members of the group <tt class="literal"><span class="pre">webdev</span></tt> then you can do this:</p> <pre class="literal-block"> chgrp webdev wingdebugpw </pre> <p>A less secure solution is just to change the permissions of this file so everyone can read it:</p> <pre class="literal-block"> chmod 644 wingdebugpw </pre> <p>The disadvantage of this approach is that other users could potentially use the contents of this file to connect to your instance of Wing against your will.</p> </div> <div class="section"> <h3 class="title-3">Resources</h3> <div class="bullet-list"><ul><li><span class="bullet"> <a class="reference" href="/doc/howtos/web">Web Development How-Tos</a> contains instructions for using Wing with specific web development frameworks, such as <a class="reference" href="/doc/howtos/django">Django</a>, <a class="reference" href="/doc/howtos/flask">Flask</a>, <a class="reference" href="/doc/howtos/pyramid">Pyramid</a>, <a class="reference" href="/doc/howtos/web2py">web2py</a>, and others.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/proj/remote-hosts">Remote Hosts</a> documentation provides details for configuring Wing Pro to work with remote hosts.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/howtos/quickstart">Quick Start</a> provides an introduction to Wing's features.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/intro/tutorial">Tutorial</a> takes you through Wing's features step by step.</span></li> <li><span class="bullet"> <a class="reference" href="/doc/manual">Wing Reference Manual</a>, which describes Wing in detail.</span></li> </ul></div></div> https://wingware.com/blog/remote-web-devTue, 16 May 2017 01:00:00 GMTUsing Wing Pro with Jupyter Notebookshttps://wingware.com/blog/jupyter<img src="https://wingware.com/images/screenshots/wing6-screenshot-dark.png" width=560 height=419 class="eye-candy-image"><p><a class="reference" href="http://wingware.com/">Wing Pro</a> is a Python IDE that can be used to develop, test, and debug Python code written for <a class="reference" href="http://jupyter.org/">Jupyter</a>, an open source scientific notebook system.</p> <p>This article explains how to configure Wing Pro for Jupyter. If you do not already have Wing Pro installed, <a class="reference" href="http://wingware.com/downloads/wing-pro">download it now</a>.</p> <div class="section"> <h3 class="title-3">Setting up Debug</h3> <p>Since Jupyter is started outside of Wing, you will need to initiate debug from your code or from the Jupyter notebook. There are a few configuration options that need to be set correctly for this to work properly.</p> <p><strong>Configure wingdbstub.py</strong></p> <p>To initiate debug, you will need to copy <tt class="literal"><span class="pre">wingdbstub.py</span></tt> out of your Wing installation (on OS X it is located in <tt class="literal"><span class="pre">Contents/Resources</span></tt> within the <tt class="literal"><span class="pre">.app</span></tt> bundle) and place it in the same directory as your <tt class="literal"><span class="pre">.ipynb</span></tt> file.</p> <p>You may need to set <tt class="literal"><span class="pre">WINGHOME</span></tt> inside of <tt class="literal"><span class="pre">wingdbstub.py</span></tt> to the installation location of Wing. This is set automatically during installation of Wing except on OS X, on Windows if you use the zip installer, and on Linux if you use the tar installer to install Wing. An alternative to editing <tt class="literal"><span class="pre">wingdbstub.py</span></tt> is just to set the environment variable <tt class="literal"><span class="pre">WINGHOME</span></tt> before you run <tt class="literal"><span class="pre">jupyter</span> <span class="pre">notebook</span></tt>.</p> <p><strong>Listen for Debug Connections</strong></p> <p>Next, tell Wing to listen for externally initiated debug connections by clicking on the bug icon in the lower left of Wing's window and checking on <tt class="literal"><span class="pre">Accept</span> <span class="pre">Debug</span> <span class="pre">Connections</span></tt>.</p> <p><strong>Starting Debug</strong></p> <p>Now add code like the following to the top of your Jupyter notebook:</p> <pre class="literal-block"> import wingdbstub wingdbstub.Ensure() </pre> <p>When you run that cell, Wing will start debugging Jupyter. You should see Wing's toolbar change and the <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> tool should show one running process:</p> <img alt="/images/doc/en/howtos/jupyter/debug-connected.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/doc/en/howtos/jupyter/debug-connected.png" /></div> <div class="section"> <h3 class="title-3">Working with the Debugger</h3> <p>To try out debugging, save a file named <tt class="literal"><span class="pre">testdebug.py</span></tt> in the same directory as your <tt class="literal"><span class="pre">.ipynb</span></tt> file with the following contents:</p> <pre class="literal-block"> def run(): print(&quot;Hello world&quot;) x = 1 print(&quot;Done&quot;) </pre> <p>Open this in Wing and place a breakpoint on the first line by of the body of <tt class="literal"><span class="pre">run()</span></tt> by clicking on the breakpoint margin to the left, as follows:</p> <img alt="/images/doc/en/howtos/jupyter/breakpoint.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/doc/en/howtos/jupyter/breakpoint.png" /><p>Now add the following cell to your Jupyter notebook:</p> <pre class="literal-block"> import testdebug testdebug.run() </pre> <p>When you execute that cell, Wing should stop on the breakpoint in <tt class="literal"><span class="pre">testdebug.py</span></tt>:</p> <img alt="/images/doc/en/howtos/jupyter/at-breakpoint.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/doc/en/howtos/jupyter/at-breakpoint.png" /><p>Now you can use the toolbar icons to step through code, view data in the <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> tool in Wing, interact in the context of the current debug stack frame with the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Probe`,</span> <span class="pre">and</span> <span class="pre">use</span> <span class="pre">all</span> <span class="pre">of</span> <span class="pre">Wing's</span> <span class="pre">other</span> <span class="pre">debugging</span> <span class="pre">features</span> <span class="pre">on</span> <span class="pre">your</span> <span class="pre">code.</span>&nbsp; <span class="pre">See</span> <span class="pre">the</span> <span class="pre">``Tutorial</span></tt> in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu for more detailed information on Wing's debugging capabilities.</p> <p>To complete execution of your cell, press the green continue arrow <img alt="continue" backrefs="" class="inline-image" dupnames="" ids="" names="" src="https://wingware.com/images/doc/en/howtos/jupyter/continue.png" /> in the toolbar. Now if you execute the cell again, you should reach your breakpoint a second time. Then continue again to complete execution of the cell.</p> <p><strong>Limitation</strong></p> <p>Jupyter does not provide a usable filename for code that resides directly in a notebook <tt class="literal"><span class="pre">.ipynb</span></tt> file (it is simply set to names like <tt class="literal"><span class="pre">&lt;ipython-input-1&gt;</span></tt>). As a result you cannot stop in or step through code in the notebook itself. Instead, you need to place your code in a Python file that is imported into the notebook, and then set breakpoints and step through code in the Python file.</p> </div> <div class="section"> <h3 class="title-3">Editing Code</h3> <p>Now try edit code in <tt class="literal"><span class="pre">testdebug.py</span></tt> to change <tt class="literal"><span class="pre">Hello</span> <span class="pre">world</span></tt> to <tt class="literal"><span class="pre">Hello</span> <span class="pre">everyone</span></tt> and save the file. If you execute your cell again in Jupyter you'll notice the text being output has not changed. This is because the module has already been imported by Python and Jupyter is not automatically reloading it. To load your changes you'll need to restart the kernel from Jupyter's toolbar or its <tt class="literal"><span class="pre">Kernel</span></tt> menu. In many cases <tt class="literal"><span class="pre">Restart</span> <span class="pre">and</span> <span class="pre">Run</span> <span class="pre">All</span></tt> in the <tt class="literal"><span class="pre">Kernel</span></tt> menu will be the most efficient way to reload your code and get back to your breakpoint.</p> <p>Try selecting the <tt class="literal"><span class="pre">Source</span> <span class="pre">Assistant</span></tt> from Wing's <tt class="literal"><span class="pre">Tools</span></tt> menu and then adding some other code in <tt class="literal"><span class="pre">testdebug.py</span></tt>, for example add <tt class="literal"><span class="pre">z</span> <span class="pre">=</span> <span class="pre">yy</span></tt> for your code reads as follows:</p> <pre class="literal-block"> def run(): print(&quot;Hello everyone&quot;) z = yy print(&quot;Done&quot;) </pre> <p>Notice that Wing offers auto-completion and updates the <tt class="literal"><span class="pre">Source</span> <span class="pre">Assistant</span></tt> with call tips, documentation, and other information about what you are typing, or what you have selected in the auto-completer. If a debug process is active and paused and the code you are typing is on the stack, then Wing includes also symbols found through inspection of the live runtime state in the auto-completer. In some code (but not the above example) this can include information Wing was not able to find through static analysis of the Python code.</p> <p>Working in live code like this is a great way to write new code in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Probe</span></tt>, where you can try it out immediately.</p> <p>Or, you can work in the editor and try out selected lines of code by pressing the <img alt="set-active-range" backrefs="" class="inline-image" dupnames="" ids="" names="" src="https://wingware.com/images/doc/en/howtos/jupyter/set-active-range.png" /> icon in top right of the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Probe</span></tt> to make an active range. Once that is done, you can execute those lines repeatedly by pressing the <img alt="execute" backrefs="" class="inline-image" dupnames="" ids="" names="" src="https://wingware.com/images/doc/en/howtos/jupyter/execute.png" /> icon in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Probe</span></tt>:</p> <img alt="/images/doc/en/howtos/jupyter/active-range.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/doc/en/howtos/jupyter/active-range.png" /></div> <div class="section"> <h3 class="title-3">Stopping on Exceptions</h3> <p>Since Jupyter handles all exceptions that occur while executing a cell, Wing will not stop on most exceptions in your code. Instead, you will get the usual report in the notebook output area.</p> <p>Try this by now by restarting the Jupyter kernel and executing your edited copy of <tt class="literal"><span class="pre">testdebug.py</span></tt>, which should read as follows:</p> <pre class="literal-block"> def run(): print(&quot;Hello everyone&quot;) z = yy print(&quot;Done&quot;) </pre> <p>Jupyter will report the exception in the notebook (undefined symbol <tt class="literal"><span class="pre">yy</span></tt>), but Wing will not stop on it.</p> <p>It is possible to get Wing to stop on exceptions, although currently the only way to do that is to edit code in IPython's <tt class="literal"><span class="pre">interactiveshell.py</span></tt>. You can easily find that by setting a breakpoint in <tt class="literal"><span class="pre">run()</span></tt> as before and going up the stack in Wing using the <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> or <tt class="literal"><span class="pre">Call</span> <span class="pre">Stack</span></tt> tool. Then add the following code to the final <tt class="literal"><span class="pre">except:</span></tt> clause in <tt class="literal"><span class="pre">InteractiveShell.runcode</span></tt>:</p> <pre class="literal-block"> if 'WINGDB_ACTIVE' in os.environ: import logging logging.exception(sys.exc_info()[1]) </pre> <p>This will log the exception, which Wing takes as a clue that it should report the exception to the user. You will need to restart the Jupyter kernel after making this change. Then try executing your cell again and you will see Wing now reports the exception:</p> <img alt="/images/doc/en/howtos/jupyter/exception.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/doc/en/howtos/jupyter/exception.png" /><p>You can continue as usual from the exception and it will also be reported in the Jupyter notebook.</p> </div> <div class="section"> <h3 class="title-3">Fixing Failure to Debug</h3> <p>If you accidentally disconnect Wing's debugger from Jupyter, for example by pressing the red stop icon <img alt="stop" backrefs="" class="inline-image" dupnames="" ids="" names="" src="https://wingware.com/images/doc/en/howtos/jupyter/stop.png" /> in Wing's toolbar, you can reestablish the debug connection at any time by re-executing the first cell we set up above, or by placing the following code into any other code that gets executed:</p> <pre class="literal-block"> import wingdbstub wingdbstub.Ensure() </pre> <p>Note that if you plan to restart the Jupyter kernel every time you start debug then you don't need the <tt class="literal"><span class="pre">wingdbstub.Ensure</span></tt> line. This makes sure that debug is active and connected to the IDE, so it is only needed if the debug connection has been dropped since the first time <tt class="literal"><span class="pre">wingdbstub</span></tt> was imported.</p> <p>If debugging stops working entirely and this does not solve it, you will need to restart the Jupyter kernel from its toolbar or <tt class="literal"><span class="pre">Kernel</span></tt> menu and then re-execute the above code to start debugging again.</p> </div> <div class="section"> <h3 class="title-3">Reloading Changed Modules</h3> <p>The instructions above rely on restarting of the kernel as the way to reload changed code into Jupyter. Module reloading is also an option, making it possible to reload code without restarting the kernel.</p> <p>Simple module reloading can be done using Python's builtin function <tt class="literal"><span class="pre">reload()</span></tt> (or in Python 3.x instead <tt class="literal"><span class="pre">imp.reload()</span></tt> after <tt class="literal"><span class="pre">import</span> <span class="pre">imp</span></tt>). For details see <a class="reference" href="https://dpb.bitbucket.io/reloading-modified-code-when-using-the-ipython-interactive-shell.html">instructions for reloading in IPython</a>.</p> <p>Or, for more complex cases, the <a class="reference" href="http://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html">autoreload extension</a> for IPython may help.</p> <p>In general module reload can be problematic if old program state is not cleared correctly, and the complexity of this depends on the modules being used and their implementations. Simply restarting the kernel is always the safest option.</p> </div> <div class="section"> <h3 class="title-3">References</h3> <p>For more information see:</p> <div class="bullet-list"><ul><li><span class="bullet"> <a class="reference" href="/doc/howtos/quickstart">Quickstart Guide</a> for a quick overview of Wing's features</span></li> <li><span class="bullet"> <a class="reference" href="/doc/intro/tutorial">Tutorial</a> for a gentle introduction to Wing's features</span></li> <li><span class="bullet"> <a class="reference" href="/doc/manual">Wing Reference Manual</a></span></li> <li><span class="bullet"> <a class="reference" href="http://jupyter.org/">Jupyter home page</a></span></li> </ul></div></div> https://wingware.com/blog/jupyterTue, 11 Apr 2017 01:00:00 GMTWing Python IDE Product Line Changeshttps://wingware.com/blog/product-line <div id="videogallery"><div class="screenshot-holder"> <img class="modal-img screenshot-right screenshot-clickable" id="screenshot-0" src="https://wingware.com/images/screenshots/wing6-screenshot-dark.png" alt="Wing Pro Screenshot" onclick="modal_show_image(this, 2870)"> </div></div> <p>Wing Python IDE has been around for almost 20 years. In Wing version 6, we've made significant changes to the product line to allow for more widespread access to free versions of the IDE, and to introduce an annual license option for those that prefer it.</p> <p>This article summarizes the product line and available licensing options as of March 2017.</p> <div class="section"> <h3 class="title-3">Wing Pro</h3> <p>Wing Pro is our full-featured Python IDE for professional programmers. It provides a powerful debugger, intelligent editor, extensive code inspection and navigation features, project management with version control, remote development, unit testing, refactoring, and an API for extending the IDE in Python.</p> <p>Wing Pro works with Django, Jupyter, PyQt, Blender, Maya, and many other frameworks for web, scientific, UI, animation, and game development.</p> <p>This is a licensed product, with a per-user license for multiple machines running any OS. The product provides a free trial consisting of three 10-day periods, or more on request. Both perpetual and annual licenses are available for commercial and non-commercial use.</p> <p>Students, educators, and unpaid open source developers can apply to receive a <a class="reference" href="/store/free">free license</a> for Wing Pro. We also provide discounts for startup companies, recent graduates, and users of competing products.</p> <p>All the purchasing options and available discounts are listed in the <a class="reference" href="/store">Wingware store</a>. Or just <a class="reference" href="/downloads/wing-pro">download Wing Pro</a> and try it.</p> </div> <div class="section"> <h3 class="title-3">Wing Personal</h3> <p>Wing Personal is a free Python IDE for students and hobbyists. It omits the more advanced features of Wing Pro but provides a simplified debugger and editor, limited code inspection and navigation features, and project management. Wing Personal is a good way to get started with Wing if you want to keep things simple at first. You can switch to Wing Pro later at any time.</p> <p>Wing Personal is free and does not require a license. You can just <a class="reference" href="/downloads/wing-personal">download</a> and use it.</p> </div> <div class="section"> <h3 class="title-3">Wing 101</h3> <p>Wing 101 is a very simplified Python IDE designed for teaching beginning programmers. It omits most of the features of Wing Pro and is intended only for people that are just learning how to program for the first time. If you already know how to program but are just getting started with Python, try Wing Personal or Wing Pro instead.</p> <p>Wing 101 is also free and does not require a license. You can just <a class="reference" href="/downloads/wing-101">download</a> and use it.</p> </div> <div class="section"> <h3 class="title-3">Compare Product Features</h3> <div class="bullet-list"><ul><li><span class="bullet"> <a class="reference" href="/downloads">Downloads</a> shows a high-level comparison of the products.</span></li> <li><span class="bullet"> <a class="reference" href="/wingide/features">Product Feature Comparison</a> details how the products differ.</span></li> <li><span class="bullet"> <a class="reference" href="/">Product Overview</a> describes the features of Wing Pro</span></li> </ul></div></div> <div class="section"> <h3 class="title-3">Wing Pro Licensing</h3> <div class="bullet-list"><ul><li><span class="bullet"> <a class="reference" href="/store">Wingware Store</a> lists all the licensing and discount options.</span></li> <li><span class="bullet"> <a class="reference" href="/store/terms">Terms of Sale</a> describes the licensing and support model.</span></li> <li><span class="bullet"> <a class="reference" href="/store/free">Free Licenses for Wing Pro</a> are available for students, educators, and unpaid open source developers.</span></li> </ul></div></div> https://wingware.com/blog/product-lineWed, 22 Mar 2017 01:00:00 GMTRemote Python Development with Wing Pro 6https://wingware.com/blog/remote-development<div class="section"> <h3 class="title-3">Introduction</h3> <p><a class="reference" href="/downloads/wing-pro">Wing Pro 6</a> adds the ability to connect to a remote host through a secure SSH tunnel in order to work with files stored remotely in the same way that Wing supports working with files on your local system. Editing, debugging, testing, searching, version control, Python Shell, OS Commands, and other features all work with remote systems.</p> <p>Currently, Wing can work remotely to OS X and Intel or ARM Linux systems. This includes any PEP 513 compatible Intel Linux system and ARM systems like Raspberry Pi and Jolla phone. We are still expanding the range of remote systems that we support. For a detailed list of the remote host types supported in the current release, please see <a class="reference" href="/doc/install/supported-platforms">Supported Platforms</a>. If you try a device and cannot get it working, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support at wingware dot com</a> for help.</p> </div> <div class="section"> <h3 class="title-3">Configuration</h3> <p>Before you can set up remote development in Wing, you first need to have an SSH key pair and set up password-less (SSH key authenticated) remote access to your target host using <tt class="literal"><span class="pre">ssh</span></tt> on Linux and OS X or either OpenSSH (provided by <tt class="literal"><span class="pre">Cygwin</span></tt>, <tt class="literal"><span class="pre">Git</span> <span class="pre">Bash</span></tt>, or similar) or <tt class="literal"><span class="pre">PuTTY</span></tt> on Windows. If you don't already have this, please refer to <a class="reference" href="/doc/proj/ssh-setup-details">SSH Setup Details</a> in Wing's documentation.</p> <p>Once you have password-less SSH access working outside of Wing, in most cases Wing will automatically find and use your SSH configuration. If it fails to do that in the steps that follow, you may need to set the <tt class="literal"><span class="pre">Network</span> <span class="pre">&gt;</span> <span class="pre">SSH</span> <span class="pre">Executable</span></tt> preference to the full path to <tt class="literal"><span class="pre">ssh</span></tt>, <tt class="literal"><span class="pre">ssh.exe</span></tt>, or PuTTY's <tt class="literal"><span class="pre">plink.exe</span></tt>, and/or ensure that Wing can access the SSH user agent. See the <tt class="literal"><span class="pre">Accessing</span> <span class="pre">SSH</span> <span class="pre">From</span> <span class="pre">Wing</span></tt> section in <a class="reference" href="/doc/proj/remote-hosts">Remote Hosts</a> for detailed instructions.</p> </div> <div class="section"> <h3 class="title-3">Creating a Project</h3> <p>To set up a new project that works with a remote host, select <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu and choose <tt class="literal"><span class="pre">Connect</span> <span class="pre">to</span> <span class="pre">Remote</span> <span class="pre">Host</span> <span class="pre">(via</span> <span class="pre">SSH)</span></tt> as the project type. Then enter an <tt class="literal"><span class="pre">Identifier</span></tt> to use for the remote host, the <tt class="literal"><span class="pre">`Host</span> <span class="pre">Name</span></tt> or ip address (optionally in the form <tt class="literal"><span class="pre">username&#64;hostname</span></tt>), and for <tt class="literal"><span class="pre">WINGHOME</span></tt> specify the location at which Wing should install its remote agent on the remote host. You only need to specify <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> if Python is not on the <tt class="literal"><span class="pre">PATH</span></tt> on your selected remote host or you want to select one of several Python installations (this is relatively rare).</p> <p>For example, here is a configuration to access a RedHat Linux system on my local network from Windows 10:</p> <img alt="/images/blog/remote-development/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-development/new-project.png" /><p>To keep things simple, leave <tt class="literal"><span class="pre">Store</span> <span class="pre">Project</span> <span class="pre">on</span> <span class="pre">Remote</span> <span class="pre">Host</span></tt> unchecked and then press <tt class="literal"><span class="pre">OK</span></tt>. This will create the project and a remote host configuration, and will try to contact the remote agent. Unless you've already installed the remote agent on that remote host in the <tt class="literal"><span class="pre">WINGHOME</span></tt> your specified, you will get a dialog that looks like this:</p> <img alt="/images/blog/remote-development/install-agent.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-development/install-agent.png" /><p>Press <tt class="literal"><span class="pre">Install</span> <span class="pre">Remote</span> <span class="pre">Agent</span></tt> and Wing will install the agent and then retry establishing a connection to the agent. If this succeeds, you will see a dialog as follows:</p> <img alt="/images/blog/remote-development/install-success.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-development/install-success.png" /><p>Close this dialog and you will see a confirmation that the project was created successfully:</p> <img alt="/images/blog/remote-development/confirmation.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-development/confirmation.png" /><p>In this case, just select <tt class="literal"><span class="pre">Save</span> <span class="pre">Later</span></tt>.</p> </div> <div class="section"> <h3 class="title-3">Using Your Project</h3> <p>Now you can right-click on the <tt class="literal"><span class="pre">Project</span></tt> tool (accessed from the <tt class="literal"><span class="pre">Tools</span></tt> menu) and select <tt class="literal"><span class="pre">Add</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> to add a directory containing your source code. Don't add your entire home directory or many 1000's of files since remote development does have higher latency for processing files than local development. Press the <tt class="literal"><span class="pre">Browse</span></tt> button in the <tt class="literal"><span class="pre">Add</span> <span class="pre">Directory</span></tt> dialog to browse files on the remote system. Afterward, save the project to local disk with <tt class="literal"><span class="pre">Save</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu.</p> <p>If you restart the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> from its <tt class="literal"><span class="pre">Options</span></tt> menu, Wing should start the shell on the remote host. For example, here is Python running remotely on a CentOS 6 system from Wing on Windows 10:</p> <img alt="/images/blog/remote-development/python-shell.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-development/python-shell.png" /><p>To debug, open a file from the directory you added to the project and select <tt class="literal"><span class="pre">Start/Continue</span></tt> in the <tt class="literal"><span class="pre">Debug</span></tt> menu. Wing launches the file in the debugger on the remote host and will reach breakpoints and exceptions. Debugging a remote file works the same way as for local files. You can use the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Probe</span></tt>, <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt>, <tt class="literal"><span class="pre">Watch</span></tt> and other tools to inspect and debug your code.</p> <img alt="/images/blog/remote-development/debugging.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-development/debugging.png" /><p>Other tools, including the <tt class="literal"><span class="pre">Testing</span></tt> tool for unit testing, the version control integrations, and <tt class="literal"><span class="pre">OS</span> <span class="pre">Commands</span></tt> for executing non-Python command lines all work on the remote host. Everything you do is protected through the use of secure SSH tunnels to the remote host.</p> </div> <div class="section"> <h3 class="title-3">Details</h3> <p>The remote host configuration you created along with your project is stored within the project file in this case, because you stored the project on local disk. You can view and edit the configuration, or create other remote host configurations, from <tt class="literal"><span class="pre">Remote</span> <span class="pre">Hosts</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. Here is an example where two remote hosts were created:</p> <img alt="/images/blog/remote-development/remote-hosts.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-development/remote-hosts.png" /><p>It is possible to set up multiple remote host configurations for one project, but the project's <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> (from the <tt class="literal"><span class="pre">Project</span></tt> menu) can only point to one of the remote hosts, and that is where the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and debug processes are run. Changing the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> is what determines whether a project points to local disk or some remote system. Here are the <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> that were set up automatically in the project we created above:</p> <img alt="/images/blog/remote-development/project-properties.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/remote-development/project-properties.png" /><p><strong>Remotely Stored Projects</strong></p> <p>In this example, we stored the project file on local disk. Project files can also be stored on the remote host. In that case, the remote host configuration needs to be checked as <tt class="literal"><span class="pre">Shared</span></tt>, as for remote host <tt class="literal"><span class="pre">osx</span></tt> in the <tt class="literal"><span class="pre">Manage</span> <span class="pre">Remote</span> <span class="pre">Hosts</span></tt> dialog above. This stores the remote host configuration locally so that it can be used to access the remote project later with <tt class="literal"><span class="pre">Open</span> <span class="pre">Remote</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu.</p> <p>You can also use this feature to remotely open a regular Wing project, for example to work on something that resides on your desktop computer while you relax on the couch with your laptop.</p> <p><strong>Remote Display with X11</strong></p> <p>To work with code that displays a user interface, you will need to either display those windows to a screen attached to the remote host (by setting the <tt class="literal"><span class="pre">DISPLAY</span></tt> environment variable in your Project Properties, for example to <tt class="literal"><span class="pre">:0.0</span></tt>) or you can forward display to occur on the same machine where Wing is running. For the latter, unless Wing is running on Linux, you will need to run an X11 server such as <tt class="literal"><span class="pre">Xquartz</span></tt> on OS X or <tt class="literal"><span class="pre">MobaXTerm</span></tt> on Windows. Then check on the <tt class="literal"><span class="pre">Forward</span> <span class="pre">X11</span></tt> option in your remote host configuration, under the <tt class="literal"><span class="pre">Options</span></tt> tab.</p> <p>For more detailed instructions and advanced configuration options see <a class="reference" href="/doc/proj/remote-hosts">Remote Hosts</a>.</p> <p>Don't hesitate to contact us at <a class="reference" href="mailto:support&#64;wingware.com">support at wingware dot com</a> if you need help getting remote development working.</p> </div> https://wingware.com/blog/remote-developmentTue, 17 Jan 2017 01:00:00 GMTUsing Multiple Selections to Edit Python Code in Winghttps://wingware.com/blog/multiple-selections<div class="section"> <h3 class="title-3">Introduction</h3> <p>This is the first in a series of articles on features that are new or improved in Wing Python IDE version 6.</p> <p><a class="reference" href="http://wingware.com/wingide/">Wing</a> is a family of Python IDEs with closely integrated editing, debugging, and unit testing capabilities. Wing version 6 improved and extended support for multiple selections on the editor, making it easier to select and then apply edits to a number of selections at once.</p> <p>The first thing to say about multiple selections is that they are not the right tool to use if you are trying to change the name of a symbol globally across multiple files. In that case, you should use <tt class="literal"><span class="pre">Rename</span> <span class="pre">Symbol</span></tt> refactoring instead from the <tt class="literal"><span class="pre">Refactor</span></tt> menu. This will complete the operation in one step, rather than requiring editing each file</p> <p>That said, multiple selections are very useful when you are trying to change a subset of occurrences of a symbol, or want to edit strings that are not symbol or that occur in comments or strings.</p> </div> <div class="section"> <h3 class="title-3">Making Selections</h3> <p>Multiple selections are created by selecting one occurrence of the string you want to edit and using the multiple selection icon in the toolbar, or the key bindings for the commands found in the <tt class="literal"><span class="pre">Edit</span> <span class="pre">&gt;</span> <span class="pre">Multiple</span> <span class="pre">Selections</span></tt> menu to also select other occurrences of that string:</p> <img alt="/images/blog/multiple-selections/toolbar.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/multiple-selections/toolbar.png" /><p>Adding the next occurrence, or dropping the current occurrence and adding the next one, are the most common way in which multiple selections are made. You can also add all occurrences of the current selection within the file, class, function, method, or block, and there are options to select only occurrences that match in case or that are whole words.</p> <p>Another way to make multiple selections is to <tt class="literal"><span class="pre">Ctrl-Alt-click</span></tt> (or <tt class="literal"><span class="pre">Option-Command-click</span></tt> on OS X) and select an additional non-empty range of text. This can be combined with the above to create arbitrary sets of selections that don't necessarily all contain the same text.</p> </div> <div class="section"> <h3 class="title-3">Managing Selections</h3> <p>After you've started making selections, Wing will show a popup that includes all the selections, whether or not they are on screen:</p> <img alt="/images/blog/multiple-selections/example.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/multiple-selections/example.png" /><p>Clicking on items in the popup will scroll the editor to show that selection. You can remove items accidentally selected by mousing over the item and pressing the red <tt class="literal"><span class="pre">X</span></tt> icon.</p> </div> <div class="section"> <h3 class="title-3">Editing Selections</h3> <p>Once you have all the selections that you want made in the editor, you can move the caret or type and your edits will be applied to all the selections at once. For example, pressing left arrow, then <tt class="literal"><span class="pre">Delete</span></tt> for forward-delete, and then <tt class="literal"><span class="pre">x</span></tt> will replace the first letter of each selection with <a href="#id1" name="unknown"><span class="problematic">``</span></a>x`:</p> <div class="system-message"> <p class="system-message-title">System Message: WARNING/2 (<tt>&lt;string&gt;</tt>, line 60); <em><a href="#id2">backlink</a></em></p> Inline literal start-string without end-string.</div> <img alt="/images/blog/multiple-selections/result.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/multiple-selections/result.png" /><p>For more information, please see <a class="reference" href="/doc/edit/multiple-selections">Multiple Selections</a> in the documentation or just <a class="reference" href="/downloads/wing-pro">Download Wing</a> and try it with your own source code. The <a class="reference" href="/doc/howtos/quickstart">Quick Start</a> will take you through the basics of setting up the IDE, and the <a class="reference" href="/doc/intro/tutorial">Tutorial</a> provides a more in-depth introduction to all of Wing's features.</p> </div> https://wingware.com/blog/multiple-selectionsThu, 12 Jan 2017 01:00:00 GMTDeveloping Code on Raspberry Pi with Wing Python IDEhttps://wingware.com/blog/raspberry-pi <div id="videogallery"><div class="screenshot-holder"> <img class="modal-img screenshot-right screenshot-clickable" id="screenshot-0" src="https://wingware.com/images/screenshots/wing6-screenshot-dark.png" alt="Wing Pro Screenshot" onclick="modal_show_image(this, 2870)"> </div></div> <p><a class="reference" href="http://wingware.com/wingide/">Wing</a> is an integrated development environment that can be used to develop and debug Python code running on the <a class="reference" href="http://raspberrypi.org/">Raspberry Pi</a>. Wing provides auto-completion, call tips, a powerful debugger, and many other features that help you write, navigate, and understand Python code.</p> <div class="section"> <h3 class="title-3">Important Note</h3> <p>This article was written before the introduction of Wing Pro 6's powerful remote development features. Please refer to <a class="reference" href="/blog/remote-development">Remote Python Development with Wing Pro 6</a> for a much easier way to get started with Wing and Raspberry Pi.</p> <p>Note that Wingware provides free licenses for Wing Pro for <a class="reference" href="/store/free">classroom and educational use</a>.</p> <p>The instructions that follow can still be used with Wing Personal, which omits the new remote development feature.</p> </div> <div class="section"> <h3 class="title-3">Introduction</h3> <p>The Raspberry Pi is not really capable of running Wing itself, but you can set up Wing on a computer connected to the Raspberry Pi to work on and debug Python code remotely.</p> <p>To do this, you will first need (1) a network connection between the Raspberry Pi and the computer where Wing will be running, and (2) a way to share files between the two computers.</p> <p>The easiest way to connect the Raspberry Pi to your network is with ethernet, or see the instructions at the end of <a class="reference" href="http://wingware.com/doc/howtos/raspberry">Using Wing with Raspberry Pi</a> for configuring a wifi connection.</p> <p>For file sharing, use <tt class="literal"><span class="pre">Samba</span></tt>, or simply transfer a copy of your files to the Raspberry Pi using <tt class="literal"><span class="pre">scp</span></tt> or <tt class="literal"><span class="pre">rsync</span></tt>.</p> </div> <div class="section"> <h3 class="title-3">Installing and Configuring the Debugger</h3> <p>Once you have a network connection and some sort of file sharing set up, the next step is to install and configure Wing's debugger. This is done as follows:</p> <div class="bullet-list"><ul><li><span class="bullet"> If you do not already have Wing installed, <a class="reference" href="http://wingware.com/downloads">download it now</a> on Windows, Linux, or OS X.</span></li> <li><span class="bullet"> Download the <a class="reference" href="http://wingware.com/pub/wingide/7.0.0/wing-debugger-raspbian-7.0.0-11.tgz">Raspberry Pi debugger package</a> to your Raspberry Pi and unpack it with <tt class="literal"><span class="pre">tar</span> <span class="pre">xzf</span> <span class="pre">wing-debugger-raspbian-7.0.0-11.tgz</span></tt>. This creates a directory named <tt class="literal"><span class="pre">wing-debugger-raspbian-7.0.0-11</span></tt>.</span></li> <li><span class="bullet"> Launch Wing and make sure that <tt class="literal"><span class="pre">Accept</span> <span class="pre">Debug</span> <span class="pre">Connections</span></tt> is checked when you click on the bug icon in the lower left of Wing's main window. Hovering the mouse over the bug icon will show additional status information, including the port Wing is listening on, which should be <tt class="literal"><span class="pre">50005</span></tt> by default.</span></li> <li><span class="bullet"> Copy <tt class="literal"><span class="pre">wingdebugpw</span></tt> from the machine where you have Wing installed to the Raspberry Pi and place it into the directory <tt class="literal"><span class="pre">wing-debugger-raspbian-7.0.0-11</span></tt>. This file is located in the <tt class="literal"><span class="pre">Settings</span> <span class="pre">Directory</span></tt>, which is listed 5th in Wing's <tt class="literal"><span class="pre">About</span></tt> box.</span></li> <li><span class="bullet"> On the Raspberry Pi, use <tt class="literal"><span class="pre">/sbin/ifconfig</span></tt> to determine the IP address of the Raspberry Pi (not 127.0.0.1, but instead the number listed under <tt class="literal"><span class="pre">eth0</span></tt> or <tt class="literal"><span class="pre">wlan0</span></tt> if you're using wifi).</span></li> <li><span class="bullet"> <p>On the host where Wing is running (not the Raspberry Pi), establish an ssh reverse tunnel to the Raspberry Pi so the debugger can connect back to the IDE. On Linux and OS X this is done as follows:</p> <pre class="literal-block"> ssh -N -R 50005:localhost:50005 &lt;user&gt;&#64;&lt;rasp_ip&gt; </pre> <p>You'll need to replace <tt class="literal"><span class="pre">&lt;user&gt;&#64;&lt;rasp_ip&gt;</span></tt> with the login name on the Raspberry Pi and the ip address from the previous step.</p> <p>The <tt class="literal"><span class="pre">-f</span></tt> option can be added just after <tt class="literal"><span class="pre">ssh</span></tt> to cause <tt class="literal"><span class="pre">ssh</span></tt> to run in the background. Without this option, you can use <tt class="literal"><span class="pre">Ctrl-C</span></tt> to terminate the tunnel. With it, you'll need to use <tt class="literal"><span class="pre">ps</span></tt> and <tt class="literal"><span class="pre">kill</span></tt> to manage the process.</p> <p>On Windows, use <a class="reference" href="http://www.putty.org/">PuTTY</a> to configure an ssh tunnel using the same settings on the <tt class="literal"><span class="pre">Connections</span> <span class="pre">&gt;</span> <span class="pre">SSH</span> <span class="pre">&gt;</span> <span class="pre">Tunnels</span> <span class="pre">page</span></tt>: Set <tt class="literal"><span class="pre">Source</span> <span class="pre">port</span></tt> to <tt class="literal"><span class="pre">50005</span></tt>, <tt class="literal"><span class="pre">Destination</span></tt> to <tt class="literal"><span class="pre">localhost:50005</span></tt>, and select the <tt class="literal"><span class="pre">Remote</span></tt> radio button, then press the <tt class="literal"><span class="pre">Add</span></tt> button. Once this is done the tunnel will be established whenever PuTTY is connected to the Raspberry Pi.</p> </span></li> <li><span class="bullet"> <p>In Wing's Preferences, use the <tt class="literal"><span class="pre">Debugger</span> <span class="pre">&gt;</span> <span class="pre">External/Remote</span> <span class="pre">&gt;</span> <span class="pre">Location</span> <span class="pre">Map</span></tt> preference to set up a mapping from the location of your files on the remote host (the Raspberry Pi) and the machine where the IDE is running.</p> <p>For example, if you have files in <tt class="literal"><span class="pre">/home/pi/</span></tt> on your Raspberry Pi that match those in <tt class="literal"><span class="pre">/Users/pitest/src/</span></tt> on the machine where Wing is running, then you would add those two to the location mapping for <tt class="literal"><span class="pre">127.0.0.1</span></tt>, with <tt class="literal"><span class="pre">home/pi/</span></tt> as the remote directory and <tt class="literal"><span class="pre">/Users/pitest/src/</span></tt> as the local directory.</p> <p>Don't add a location map for the Raspberry Pi's ip address because your ssh tunnel makes it look like the connection is coming from <tt class="literal"><span class="pre">127.0.0.1</span></tt> and not the Raspberry Pi.</p> </span></li> </ul></div></div> <div class="section"> <h3 class="title-3">Invoking the Debugger</h3> <p>There are two ways to invoke the debugger: (1) from the command line, or (2) from within your Python code. The latter is useful if debugging code running under a web server or other environment not launched from the command line.</p> <p><strong>Debugging from the Command Line</strong></p> <p>To invoke the debugger without modifying any code, use the following command:</p> <pre class="literal-block"> wing-debugger-raspbian-7.0.0-11/wingdb yourfile.py arg1 arg2 </pre> <p>This is the same thing as <tt class="literal"><span class="pre">python</span> <span class="pre">yourfile.py</span> <span class="pre">arg1</span> <span class="pre">arg2</span></tt> but runs your code in Wing's debugger so you can stop at breakpoints and exceptions in the IDE, step through your code, and interact using the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Probe</span></tt> in the <tt class="literal"><span class="pre">Tools</span></tt> menu.</p> <p>By default this runs with <tt class="literal"><span class="pre">python</span></tt> and connects the debugger to <tt class="literal"><span class="pre">localhost:50005</span></tt>, which matches the above ssh tunnel configuration. To change which Python is run, set the environment variable <tt class="literal"><span class="pre">WINGDB_PYTHON</span></tt>:</p> <pre class="literal-block"> export WINGDB_PYTHON=/some/other/python </pre> <p><strong>Starting Debug from Python Code</strong></p> <p>To start debug from within Python code that is already running, edit <tt class="literal"><span class="pre">wing-debugger-raspbian-7.0.0-11/wingdbstub.py</span></tt> and change the line <tt class="literal"><span class="pre">WINGHOME</span> <span class="pre">=</span> <span class="pre">None</span></tt> to <tt class="literal"><span class="pre">WINGHOME</span> <span class="pre">=</span> <span class="pre">/home/pi/wing-debugger-raspbian-7.0.0-11</span></tt> where <tt class="literal"><span class="pre">/home/pi</span></tt> should be replaced with the full path where you unpacked the debugger package earlier. Use <tt class="literal"><span class="pre">pwd</span></tt> to obtain the full path if you don't know what it is.</p> <p>Copy your edited <tt class="literal"><span class="pre">wingdbstub.py</span></tt> into the same directory as your code and add <tt class="literal"><span class="pre">import</span> <span class="pre">wingdbstub</span></tt> to your code. This new line is what initiates debugging and connects back to the IDE through the ssh tunnel.</p> <p>An alternative to editing <tt class="literal"><span class="pre">wingdbstub.py</span></tt> is to set <tt class="literal"><span class="pre">WINGHOME</span></tt> in the environment instead with a command like <tt class="literal"><span class="pre">export</span> <span class="pre">WINGHOME=/home/pi/wing-debugger-raspbian-7.0.0-11</span></tt>.</p> </div> <div class="section"> <h3 class="title-3">Further Reading</h3> <p>For additional configuration options and trouble-shooting, see <a class="reference" href="http://wingware.com/doc/howtos/raspberry">Using Wing with Raspberry Pi</a>.</p> <p>Use the <a class="reference" href="http://wingware.com/doc/intro/tutorial">Tutorial</a> in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu to learn more about the features available in Wing , or take a look at the <a class="reference" href="http://wingware.com/doc/howtos/quickstart">Quickstart Guide</a>.</p> <p>More information on Wing can be found in the <a class="reference" href="http://wingware.com/">product overview</a>.</p> </div> https://wingware.com/blog/raspberry-piWed, 06 May 2015 01:00:00 GMTFind Symbol in Project in Wing Prohttps://wingware.com/blog/find-symbol<p>Wing Pro has long had the ability to jump to the point of definition of a symbol in source code (press <tt class="literal"><span class="pre">F4</span></tt> or right-click to select <tt class="literal"><span class="pre">Goto</span> <span class="pre">Definition</span></tt>). This works whether or not the symbol is defined in the same file or in an imported module or package.</p> <p>Similarly, the <tt class="literal"><span class="pre">Find</span> <span class="pre">Symbol</span></tt> dialog in the <tt class="literal"><span class="pre">Source</span></tt> menu jumps to symbols anywhere in the current file when you type a fragment that matches its name.</p> <p>Wing Pro 5.1 takes this a step further by adding a <tt class="literal"><span class="pre">Find</span> <span class="pre">Symbol</span> <span class="pre">in</span> <span class="pre">Project</span></tt> dialog that works the same way but searches all files in the project for matching symbols:</p> <img alt="/images/blog/find-symbol/find-symbol.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/find-symbol/find-symbol.png" /><p>When you type a fragment, it can apply anywhere within the symbol name. Multiple fragments separated by spaces can be used to narrow down context as well as symbol name, for example matching class name and then method name:</p> <img alt="/images/blog/find-symbol/find-symbol-fragment.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/find-symbol/find-symbol-fragment.png" /><p><tt class="literal"><span class="pre">Find</span> <span class="pre">Symbol</span> <span class="pre">in</span> <span class="pre">Project</span></tt> is very fast, and it is a great way to quickly navigate through hundreds of thousands of lines of code. It is listed in the <tt class="literal"><span class="pre">Source</span></tt> menu, along with the key binding that can be used to display it (Ctrl-Shift-T in most keyboard personalities). If you want to define your own key binding, the command name is <tt class="literal"><span class="pre">find-symbol-in-project</span></tt>.</p> https://wingware.com/blog/find-symbolWed, 06 May 2015 01:00:00 GMTInteractive Python in Wing Pro: The Debug Probehttps://wingware.com/blog/debug-probe-intro<p>Wing Pro is a Python IDE with a powerful debugger that makes it easier to work interactively with Python. In addition to debugging, it is also a great way to navigate and understand unfamiliar code, and to write new code interactively in the live runtime state for which it is being designed.</p> <div class="section"> <h3 class="title-3">Debug Probe</h3> <p>The Debug Probe is an important part of Wing Pro's support for interactive development. This is a Python shell that works in the current debug stack frame when the debug process is paused by a breakpoint or exception.</p> <img alt="Debug Probe" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/debug-probe/debug-probe.png" /><p>To use the Debug Probe, set a breakpoint in your code and start debugging from the toolbar icon <img alt="debug" backrefs="" class="inline-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/debug-probe/debug_continue.png" /> or <tt class="literal"><span class="pre">Debug</span></tt> menu. When you reach the breakpoint or any exception, you can start working interactively in the Debug Probe.</p> <p>The menus at the top of the Debug Probe are used to select the process, thread, and stack frame you want to work within. Any changes made in the Debug Probe, or side effects of code that is invoked here, are made within the selected stack frame.</p> <p>The Debug Probe provides auto-completion that is integrated with Wing's Source Assistant, where you can see call signature, documentation, and other information relevant to the code you are typing.</p> <img alt="Source Assistant" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/debug-probe/source-assistant.png" /><p>You can easily jump to point of definition of symbols in the debug probe or their types by pressing <tt class="literal"><span class="pre">F4</span></tt> or by navigating from the links in the Source Assistant.</p> </div> <div class="section"> <h3 class="title-3">Conditional Breakpoints</h3> <p>Conditional breakpoints are handy for isolating a particular case for which new code is being written, giving you direct and convenient access to the actual data being passed to the code that you are working on. Everything you write can immediately be tested against the live runtime state.</p> <img alt="Setting a Conditional Breakpoint" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/debug-probe/conditional-breakpoint.png" /><p>To set or edit a conditional breakpoint, right click on the left-most margin in the editor. Breakpoints can also be ignore-counted or enabled/disabled from here, and an overview of breakpoints with statistics is available in the <tt class="literal"><span class="pre">Breakpoints</span></tt> tool in the <tt class="literal"><span class="pre">Tools</span></tt> menu.</p> </div> <div class="section"> <h3 class="title-3">Active Ranges</h3> <p>In some cases it's useful to set a range of code in the editor as active in the Debug Probe, in order to make it easier to execute while working on it. This is done with the icons in the upper right corner of the Debug Probe.</p> <img alt="Active Range in the Debug Probe" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/debug-probe/active-range.png" /><p>Once an active range is set, it is highlighted in the editor and can be sent to the Debug Probe by pressing the icon in the top right of the Debug Probe or by binding a key to the command <tt class="literal"><span class="pre">debug-probe-evaluate-active-range</span></tt>.</p> </div> <div class="section"> <h3 class="title-3">Getting Started with Wing Pro</h3> <p>A quick introduction to Wing Pro's features can be found in our <a class="reference" href="http://localhost/blog/new-screencast">Feature Overview Screencast</a>.</p> <p>Or just <a class="reference" href="http://wingware.com/downloads/downloads">download Wing Pro</a> and give it a try. The <tt class="literal"><span class="pre">Tutorial</span></tt> in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu is a great way to get started.</p> </div> https://wingware.com/blog/debug-probe-introTue, 31 Mar 2015 01:00:00 GMTMultiprocess Debugging in Wing IDE Pro 5.1https://wingware.com/blog/multiprocess-debug<p>Wing IDE Pro's debugger makes is easier to work interactively with Python. In addition to debugging, it is also a great way to navigate and understand unfamiliar code, and to write new code interactively in the live runtime state for which the code is being designed.</p> <p>Starting with Wing 5.1, multiple debug connections can be made at once, so it is much easier to write and debug multi-process code.</p> <div class="section"> <h3 class="title-3">Multi-Process Debugging</h3> <p>Wing 5.1 adds a process selector wherever a stack selector is shown in the user interface, in addition to a thread selector if there are multiple threads in the debug process. The process selector groups processes into a process tree, showing the relationship between them regardless of how they were created or debug-enabled.</p> <img alt="Process Selector" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/multiprocess-debug/process-selector.png" /><p>When multiple processes are being debugging, pressing the <tt class="literal"><span class="pre">Alt</span></tt> key causes the Debug/Continue, Stop, Restart, and Pause toolbar icons to apply that operation to all the active processes:</p> <img alt="/images/blog/multiprocess-debug/toolbar.png" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/multiprocess-debug/toolbar.png" /><p>These operations are also in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">&gt;</span> <span class="pre">Processes</span></tt> menu, along with commands for starting additional new debug processes from the IDE.</p> <p>Options to control multi-process debugging are in the <tt class="literal"><span class="pre">Debugger</span> <span class="pre">&gt;</span> <span class="pre">Processes</span></tt> preferences group. For example, you can control when Wing switches to a newly attached debug process and which processes to kill when killing a single debug process.</p> <img alt="Multi-Process Debug Preferences" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/multiprocess-debug/prefs.png" /></div> <div class="section"> <h3 class="title-3">Automatically Debugging Child Processes</h3> <p>Optionally, you can also automatically debug-enable sub-processes created with <tt class="literal"><span class="pre">multiprocessing</span></tt>, via <tt class="literal"><span class="pre">sys.executable</span></tt>, and (on Posix) with <tt class="literal"><span class="pre">os.fork()</span></tt>.</p> <p>Automatically debugging child processes is off by default since it can be confusing or unwanted in some code bases. It can be enabled with the <tt class="literal"><span class="pre">Debugger</span> <span class="pre">&gt;</span> <span class="pre">Processes</span> <span class="pre">&gt;</span> <span class="pre">Debug</span> <span class="pre">Child</span> <span class="pre">Processes</span></tt> preference or (preferably, in most cases) on a project-by-project basis with the <tt class="literal"><span class="pre">Debug/Execute</span> <span class="pre">&gt;</span> <span class="pre">Debug</span> <span class="pre">Child</span> <span class="pre">Properties</span></tt> setting in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>.</p> <img alt="Enabling Child Process Debugging" backrefs="" class="doc-image" dupnames="" ids="" names="" src="https://wingware.com/images/blog/multiprocess-debug/child-process-debug.png" /><p>This option is useful when working with auto-reloading web application frameworks like <a class="reference" href="/doc/howtos/flask">Flask</a> or <a class="reference" href="/doc/howtos/google-app-engine">Google App Engine</a>, because Wing will automatically debug the reloaded server processes.</p> </div> <div class="section"> <h3 class="title-3">Manually Debugging Child Processes</h3> <p>There are cases where sub- processes cannot be automatically debugged, such as when <tt class="literal"><span class="pre">os.exec()</span></tt> is used (on Posix) or if the process is started without referencing <tt class="literal"><span class="pre">sys.executable</span></tt>. In these cases, the process can still be debugged by importing <tt class="literal"><span class="pre">wingdbstub</span></tt>, which is a module provided by Wing IDE to initiate debugging from outside of the IDE.</p> <p>In these cases, you will need to enable <tt class="literal"><span class="pre">Accept</span> <span class="pre">Debug</span> <span class="pre">Connections</span></tt> by clicking on the bug icon in the lower left of Wing's window. This causes Wing to use a fixed port for accepting debug connections. The default matches the port configured <tt class="literal"><span class="pre">wingdbstub.py</span></tt> in your Wing IDE installation.</p> <p>Details on doing this are in <a class="reference" href="/doc/debug/debugging-externally-launched-code">Debugging Externally Launched Code</a> in Wing's reference manual.</p> </div> <div class="section"> <h3 class="title-3">Resources</h3> <p>More information can be found in <a class="reference" href="/doc/debug/multiprocess">Multi-Process Debugging</a> in the Wing IDE manual.</p> <p>A quick introduction to Wing IDE's features can be found in our <a class="reference" href="http://localhost/blog/new-screencast">Feature Overview Screencast</a>.</p> <p>Or just <a class="reference" href="http://wingware.com/downloads/wing-pro">download Wing IDE</a> and give it a try. The <tt class="literal"><span class="pre">Tutorial</span></tt> in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu is a great way to get started.</p> </div> https://wingware.com/blog/multiprocess-debugFri, 20 Mar 2015 01:00:00 GMT