Wing Tipshttps://wingware.com/Tips, tricks, and helpful hints for Wingware's Python IDEsTue, 31 Mar 2020 09:03:48 GMTPyRSS2Gen-1.0.0http://www.dalkescientific.com/Python/PyRSS2Gen.htmlRemote Python Development on AWS with Wing Prohttps://wingware.com/hints/aws-1<p>In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we'll start looking at how to use Wing Pro to remotely develop Python code running on an AWS instance. With minimal configuration, Wing Pro can edit, debug, test, inspect, and navigate Python code residing on an AWS instance, as if it were on the local host.</p> <div class="section"> <h3 class="title-3">Minimum Requirements</h3> <p>You will need an AWS instance that has Python installed on it, is running 32-bit or 64-bit Intel Linux, and that you can connect to using OpenSSH or PuTTY. PuTTY is recommended on Windows because it tends to be prone to fewer problems. You will need the following in order to configure Wing Pro to use your AWS instance:</p> <p><strong>(1)</strong> The user name and static IP address or DNS name used to connect to the AWS instance. Amazon Lightsail typically uses an IP address while EC2 and other variants of AWS may provide a DNS name as well. The static IP address will work in any case.</p> <p><strong>(2)</strong> The SSH key pair in a <tt class="literal"><span class="pre">*.pem</span></tt> file, as downloaded from AWS.</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">Setting up AWS</h3> <p><em>If you already have an AWS instance to work with, you can skip this section.</em></p> <p><a class="reference" href="https://aws.amazon.com/lightsail/">Amazon Lightsail</a> is the easiest way to get an AWS instance, in about 5 minutes. You will need to set up an account. Then create a <tt class="literal"><span class="pre">Linux/Unix</span></tt> instance, selecting the <tt class="literal"><span class="pre">OS</span> <span class="pre">Only</span></tt> option and the most recent <tt class="literal"><span class="pre">Ubuntu</span></tt> or any other Intel Linux with Python 2 or 3 on it.</p> <p>While setting up your instance, you can download your SSH key pair under the AWS <tt class="literal"><span class="pre">SSH</span> <span class="pre">key</span> <span class="pre">pair</span> <span class="pre">manager</span></tt>. You'll need this on your local machine, where Wing is running, in order to be able to connect to the instance.</p> <p>After the instance is created, it will remain in <tt class="literal"><span class="pre">pending</span></tt> state for a minute or so. Once it is up and running, create a static IP address under the <tt class="literal"><span class="pre">Network</span></tt> tab in the AWS Lightsail management area and attach it to your instance.</p> <p>At this point you have all that is needed to start using Wing Pro with AWS: (1) The SSH key pair that you downloaded, and (2) the user name and IP address, which are shown on the Lightsail instance management page.</p> </div> <div class="section"> <h3 class="title-3">Testing the SSH Connection</h3> <p>Before trying to use your new instance from Wing Pro, you should first try to connect using <tt class="literal"><span class="pre">ssh</span></tt> or PuTTY's <tt class="literal"><span class="pre">plink.exe</span></tt> on the command line, to make sure those are working. This is important because Wing invokes those command lines to connect to the instance.</p> <p><strong>OpenSSH</strong></p> <p>On Linux or macOS using <tt class="literal"><span class="pre">ssh</span></tt>, you need to make your <tt class="literal"><span class="pre">*.pem</span></tt> SSH key pair file readable only by the user running Wing, for example with:</p> <pre class="literal-block"> chmod 600 aws.pem </pre> <p>Otherwise, <tt class="literal"><span class="pre">ssh</span></tt> will reject it as potentially compromised.</p> <p>Once that is done, try connecting as follows, substituting the actual path to your downloaded SSH key pair and your instance's username and IP address or DNS name:</p> <pre class="literal-block"> ssh -i /path/to/mykey.pem ubuntu&#64;11.22.33.44 </pre> <p>You will be asked to add the instance's identity to your known hosts file, which you should do by typing <tt class="literal"><span class="pre">yes</span></tt>. If this is not done, <tt class="literal"><span class="pre">ssh</span></tt> will fail to connect and Wing will also not be able to connect to the instance.</p> <p><strong>PuTTY</strong></p> <p>With PuTTY on Windows, you will need to first convert the SSH key to a format that PuTTY can use. This is done by launching <tt class="literal"><span class="pre">puttygen</span></tt>, pressing the <tt class="literal"><span class="pre">Load</span></tt> button to read the <tt class="literal"><span class="pre">*.pem</span></tt> SSH key file you downloaded from the AWS management site, and then using <tt class="literal"><span class="pre">Save</span> <span class="pre">Private</span> <span class="pre">Key</span></tt> to write a <tt class="literal"><span class="pre">*.ppk</span></tt> file.</p> <p>Then you invoke <tt class="literal"><span class="pre">plink.exe</span></tt> to connect to the AWS instance as follows, substituting in the actual path to your downloaded SSH key pair and the correct username and IP address or DNS name for the AWS instance:</p> <pre class="literal-block"> plink.exe -i C:\path\to\mykey.ppk ubuntu&#64;11.22.33.44 </pre> <p>You will be asked to accept the AWS instance's identity the first time you connect, and this must be done before Wing's remote development support will work with the AWS instance.</p> </div> <div class="section"> <h3 class="title-3">Creating a Wing Project</h3> <p>Now you're ready to create a project in Wing Pro. This is done with <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. Select <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 your project type. Then enter an identifier for the remote host (any short string to identify it in Wing's UI), and the user name and IP address or DNS name used to connect to the host:</p> <img src="https://wingware.com/images/blog/aws-1/new-project.png" alt="/images/blog/aws-1/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="716px" /><p>As in the above example, <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> will usually be <tt class="literal"><span class="pre">Use</span> <span class="pre">default</span></tt>, which first tries <tt class="literal"><span class="pre">python3</span></tt> and then <tt class="literal"><span class="pre">python</span></tt>. If Python is not on the <tt class="literal"><span class="pre">PATH</span></tt> on your AWS instance or you want to specify a particular Python executable or activate a virtual environment, you can do this here.</p> <p>You will also need to point Wing at the SSH key pair file you downloaded from AWS earlier. This is done under the <tt class="literal"><span class="pre">Options</span></tt> tab using the <tt class="literal"><span class="pre">Private</span> <span class="pre">Key</span></tt> field as follows:</p> <img src="https://wingware.com/images/blog/aws-1/private-key-file.png" alt="/images/blog/aws-1/private-key-file.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="716px" /><p>Pressing <tt class="literal"><span class="pre">OK</span></tt> in the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog will create and configure the project, connect to the remote instance, install Wing's remote agent, and then offer to add source directories to the project or save the new project file:</p> <img src="https://wingware.com/images/blog/aws-1/new-project-confirm.png" alt="/images/blog/aws-1/new-project-confirm.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="612px" /><p>If you already have source code on the AWS instance, press <tt class="literal"><span class="pre">Add</span> <span class="pre">Directory</span></tt> one or more times to add directories to the project. Typically, you want to add the directories that contain code you plan to work on, and leave out directories that contain Python, the standard libraries, and other modules and packages that you may use. Wing can find those as needed, through the Python Path.</p> <p>If you are working with a blank new AWS instance, add the home directory to your project to get started. This can be changed later as needed.</p> <p>Finally, save the project to local disk. The project is now ready to use.</p> </div> <div class="section"> <h3 class="title-3">Testing a Hello World</h3> <p>To try out a simple example of editing and debugging code on the remote AWS instance, create a file <tt class="literal"><span class="pre">helloworld.py</span></tt> temporarily on the instance. This is done by right-clicking on one of the files in the <tt class="literal"><span class="pre">Project</span></tt> tool in Wing Pro and selecting <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">File</span></tt>. Enter the file name (in some key bindings this is in the data entry area at the bottom of Wing's window) and type or paste the following into the new file:</p> <div class="python-highlight"><pre><span class="kn">import</span> <span class="nn">time</span> <span class="k">print</span><span class="p">(</span><span class="s">&quot;Hello World! {}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()))</span> </pre></div> <p>After saving the file, set a breakpoint on the second line by clicking on the leftmost margin in the editor:</p> <img src="https://wingware.com/images/blog/aws-1/breakpoint.png" alt="/images/blog/aws-1/breakpoint.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="382px" /><p>Then select <tt class="literal"><span class="pre">Starting/Continue</span></tt> from the <tt class="literal"><span class="pre">Debug</span></tt> menu to start debug, or use the green play icon <img src="https://wingware.com/images/doc/en/icons/wingide-debug-continue.png" alt="play" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> in the toolbar.</p> <p>There is a slight delay to get the process started, depending on your network distance from the AWS instance, but then you should see Wing stop on the breakpoint:</p> <img src="https://wingware.com/images/blog/aws-1/breakpoint-stop.png" alt="/images/blog/aws-1/breakpoint-stop.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="382px" /><p>There's not much to see here, but you can poke around a little in the live runtime state of the paused debug process, using Wing Pro's <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>, from the <tt class="literal"><span class="pre">Tools</span></tt> menu:</p> <img src="https://wingware.com/images/blog/aws-1/debug-console.png" alt="/images/blog/aws-1/debug-console.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="526px" /><p>Once you continue debugging, the process will exit and print to the <tt class="literal"><span class="pre">Debug</span> <span class="pre">I/O</span></tt> tool:</p> <img src="https://wingware.com/images/blog/aws-1/debug-io.png" alt="/images/blog/aws-1/debug-io.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="581px" /><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/aws-1Tue, 24 Mar 2020 01:00:00 GMTGoto-Definition From the Interactive Shells in Wing Prohttps://wingware.com/hints/goto-definition-in-shells<p>In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we'll take a quick look at a lesser-known but often useful feature in Wing Pro: Jumping from symbols in the integrated shells to their point of definition in source code. This makes it a snap to bridge from runtime symbols to the source code where they are actually defined and used.</p> <div class="section"> <h3 class="title-3">Debug Console Example</h3> <p>In this example, the debugger is stopped and I'm working in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>, which is an interactive shell that runs in the context of the currently selected debug stack frame. While trying to determine why <tt class="literal"><span class="pre">handler.exit_status</span></tt> is <tt class="literal"><span class="pre">None</span></tt>, I jump to its point of definition from the right-click context menu:</p> <img src="https://wingware.com/images/blog/goto-definition-in-shells/debug-console.gif" alt="/images/blog/goto-definition-in-shells/debug-console.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>From here, I could set a breakpoint and restart debug, or right-click on the editor to select <tt class="literal"><span class="pre">Find</span> <span class="pre">Points</span> <span class="pre">of</span> <span class="pre">Use</span></tt> to see all the points of use of <tt class="literal"><span class="pre">exit_status</span></tt>.</p> </div> <div class="section"> <h3 class="title-3">Python Shell Example</h3> <p>Similarly, I can import a module in the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and jump to the point of definition of symbols in the module. Here I'm using this technique to bring up the source code for numpy's <tt class="literal"><span class="pre">ndarray</span></tt>:</p> <img src="https://wingware.com/images/blog/goto-definition-in-shells/python-shell.gif" alt="/images/blog/goto-definition-in-shells/python-shell.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>In this case, I'm pressing <tt class="literal"><span class="pre">F4</span></tt> to go to the definition, rather than using the right-click context menu.</p> </div> <div class="section"> <h3 class="title-3">Traversing Visit History</h3> <p>To get back from the point of definition to the previously displayed code in the editor, use the browser-like forward/back arrow buttons in the top left of the editor:</p> <img src="https://wingware.com/images/blog/goto-definition-in-shells/back-arrows.png" alt="/images/blog/goto-definition-in-shells/back-arrows.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="321px" /><p>Pressing <tt class="literal"><span class="pre">Alt-Left</span></tt> or using any other key binding for the command <tt class="literal"><span class="pre">visit-history-previous</span></tt> also goes back in the editor's visit history.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/goto-definition-in-shellsWed, 11 Mar 2020 01:00:00 GMTUsing Anaconda Environments with Wing Python IDEhttps://wingware.com/hints/anaconda-envs<p>Wing version 7.2 <a class="reference" href="https://wingware.com/news/2020-01-20">has been released</a>, and we've been looking at the new features in this version. So far we've covered <a class="reference" href="https://wingware.com/hints/reformatting">reformatting with Black and YAPF</a>, Wing 7.2's <a class="reference" href="https://wingware.com/hints/virtualenv">expanded support for virtualenv</a>, and <a class="reference" href="https://wingware.com/hints/python-m">using python -m with Wing</a>.</p> <p>This time we'll take a look at what Wing 7.2 provides for people that are using Anaconda environments created with <tt class="literal"><span class="pre">conda</span> <span class="pre">create</span></tt> as an alternative to virtualenv.</p> <div class="section"> <h3 class="title-3">What Wing 7.2 Adds</h3> <p>Wing 7.2 supports creating new Wing projects that use an existing Anaconda environment, so that the environment is automatically activated whenever the project is open. Debug processes, unit tests, the integrated Python Shell, and OS Commands all run in the activated environment.</p> <p>Wing 7.2 also added the ability to create and configure a new Anaconda environment while creating a new Wing project.</p> </div> <div class="section"> <h3 class="title-3">Using an Existing Anaconda Environment</h3> <p>Wing tries to discover existing Anaconda environments and lists them in the drop down menu next to the <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> option under <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> and the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog, which are both in the <tt class="literal"><span class="pre">Project</span></tt> menu:</p> <img src="https://wingware.com/images/blog/anaconda-envs/discovered-envs.png" alt="/images/blog/anaconda-envs/discovered-envs.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="606px" /><p>Selecting one of the listed Anaconda environments configures the project to automatically activate that environment whenever the project is open:</p> <img src="https://wingware.com/images/blog/anaconda-envs/selected-env.png" alt="/images/blog/anaconda-envs/selected-env.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="606px" /><p>If Wing cannot find your Anaconda environment automatically, you can instead manually enter the command that activates it.</p> </div> <div class="section"> <h3 class="title-3">Creating New Projects</h3> <p>Wing can also create a new Anaconda environment at the same time that a new Wing project is created. This is done by selected <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 choosing <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Anaconda</span> <span class="pre">Environment</span></tt> as the project type:</p> <img src="https://wingware.com/images/blog/anaconda-envs/new-project.png" alt="/images/blog/anaconda-envs/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="600px" /><p>Wing will create the new environment, install packages, and then configure and save a project file. You can immediately start working in your new environment, which Wing automatically activates for you whenever you have the project open.</p> <p>That's all there is to it!</p> <p>For some additional details, see <a class="reference" href="https://wingware.com/doc/howtos/anaconda">Using Wing with Anaconda</a>.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/anaconda-envsWed, 26 Feb 2020 01:00:00 GMTUsing "python -m" in Wing 7.2https://wingware.com/hints/python-m<p>Wing version 7.2 <a class="reference" href="https://wingware.com/news/2020-01-20">has been released</a>, and the next couple <a class="reference" href="https://wingware.com/hints">Wing Tips</a> look at some of its new features. We've already looked at <a class="reference" href="https://wingware.com/hints/reformatting">reformatting with Black and YAPF</a> and Wing 7.2's <a class="reference" href="https://wingware.com/hints/virtualenv">expanded support for virtualenv</a>.</p> <p>Now let's look at how to set up debugging modules that need to be launched with <tt class="literal"><span class="pre">python</span> <span class="pre">-m</span></tt>. This command line option for Python allows searching the Python Path for the name of a module or package, and then loading and executing it. This capability was introduced way back in Python 2.4, and then extended in Python 2.5 through <a class="reference" href="https://www.python.org/dev/peps/pep-0338/">PEP 338</a> . However, it only came into widespread use relatively recently, for example to launch <tt class="literal"><span class="pre">venv</span></tt>, <tt class="literal"><span class="pre">black</span></tt>, or other command line tools that are shipped as Python packages.</p> <div class="section"> <h3 class="title-3">Launching Modules</h3> <p>To configure Wing to launch a module by name with <tt class="literal"><span class="pre">python</span> <span class="pre">-m</span></tt>, create a <tt class="literal"><span class="pre">Named</span> <span class="pre">Entry</span> <span class="pre">Point</span></tt> from the <tt class="literal"><span class="pre">Debug</span></tt> menu, select <tt class="literal"><span class="pre">Named</span> <span class="pre">Module</span></tt>, and enter the module or package name and any run arguments:</p> <img src="https://wingware.com/images/blog/python-m/named-entry-point-module.png" alt="/images/blog/python-m/named-entry-point-module.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="472px" /><p>The above is equivalent to this command line:</p> <pre class="literal-block"> python -m mymodule one two </pre> <p>The named entry point can be set as the main entry point for your project under the <tt class="literal"><span class="pre">Debug/Execute</span></tt> tab of <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:</p> <img src="https://wingware.com/images/blog/python-m/main-entry-point.png" alt="/images/blog/python-m/main-entry-point.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="585px" /><p>Or it can be launched from the <tt class="literal"><span class="pre">Debug</span> <span class="pre">&gt;</span> <span class="pre">Debug</span> <span class="pre">Named</span> <span class="pre">Entry</span> <span class="pre">Point</span></tt> menu or by assigning a key binding to it in the named entry point manager dialog.</p> </div> <div class="section"> <h3 class="title-3">Launching Packages</h3> <p>Packages can also be launched in this way, if they include a file named <tt class="literal"><span class="pre">__main__.py</span></tt> to define the package's main entry point:</p> <img src="https://wingware.com/images/blog/python-m/named-entry-point.png" alt="/images/blog/python-m/named-entry-point.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="472px" /></div> <div class="section"> <h3 class="title-3">Setting Python Path</h3> <p>Whether launching a module or package, the name has to be found on the <tt class="literal"><span class="pre">Python</span> <span class="pre">Path</span></tt> that you've configured for your project. If Wing fails to find the module, add its parent directory to <tt class="literal"><span class="pre">Python</span> <span class="pre">Path</span></tt> under the <tt class="literal"><span class="pre">Environment</span></tt> tab in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>:</p> <img src="https://wingware.com/images/blog/python-m/python-path.png" alt="/images/blog/python-m/python-path.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="578px" /><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/python-mTue, 18 Feb 2020 01:00:00 GMTUsing virtualenv with Wing Python IDEhttps://wingware.com/hints/virtualenv<p>Wing version 7.2 <a class="reference" href="https://wingware.com/news/2020-01-20">has been released</a>, and the next couple <a class="reference" href="https://wingware.com/hints">Wing Tips</a> look at some of its new features. <a class="reference" href="https://wingware.com/hints/reformatting">Last time</a> at code reformatting with Black and YAPF. Now let's investigate Wing 7.2's expanded support for virtualenv.</p> <div class="section"> <h3 class="title-3">What Wing 7.2 Adds</h3> <p>Wing 7.2 improves support for virtualenv by allowing the command that activates the environment to be entered in the Python Executable in Project Properties, Launch Configurations, and when creating new projects. This is an easier and more natural way to configure virtualenvs than the old approach of finding and using the virtualenv's Python executable.</p> <p>The New Project dialog now also includes the option to create a new virtualenv along with a new project, optionally specifying packages to install. This makes it much easier to get started on a new code base that uses virtualenv.</p> </div> <div class="section"> <h3 class="title-3">Using an Activated Env</h3> <p>Wing has always supported virtualenv by allowing the <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> to be set to the virtualenv's Python, which both activates the env and runs Python. In Wing 7.2 it is possible to instead set the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to the command that activates the virtualenv. When this is done, Wing activates the environment and runs <tt class="literal"><span class="pre">python</span></tt> in it.</p> <p>To use this approach, select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> for the <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> and enter the activation command:</p> <img src="https://wingware.com/images/blog/virtualenv/properties.png" alt="/images/blog/virtualenv/properties.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="758px" /><p>The drop down menu next to the entry area lists discovered environments and those which have been used recently:</p> <img src="https://wingware.com/images/blog/virtualenv/recent-envs.png" alt="/images/blog/virtualenv/recent-envs.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="446px" /><p>Activated virtualenvs can be used in the same way in other settings where a <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> can be specified, for example for Launch Configurations and in a Remote Host configuration.</p> </div> <div class="section"> <h3 class="title-3">Creating New Projects</h3> <p>There are two options available for virtualenv, when creating a new project from the <tt class="literal"><span class="pre">Project</span></tt> menu: (1) Creating a new virtualenv and new Wing project at the same time, or (2) Creating a new Wing project that uses an existing virtualenv.</p> <div class="section"> <h4 class="title-4">Creating a New virtualenv</h4> <p>To create a new virtualenv along with your project, 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 set the project type to <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Virtualenv</span></tt>. You will then need to enter the name for the virtualenv, select a parent directory where the virtualenv's directory will be written, and optionally specify packages to install and/or the base <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to use. For example:</p> <img src="https://wingware.com/images/blog/virtualenv/new-project-new.png" alt="/images/blog/virtualenv/new-project-new.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="579px" /><p>Wing will create the virtualenv, install packages, and then configure and save a project file. You can immediately start working in your new virtualenv, which Wing automatically activates for you whenever you have the project open.</p> </div> <div class="section"> <h4 class="title-4">Using an Existing virtualenv</h4> <p>To use an existing virtualenv, 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, set the project type to <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Virtualenv</span></tt>, and then enter the activation command:</p> <img src="https://wingware.com/images/blog/virtualenv/new-project-existing.png" alt="/images/blog/virtualenv/new-project-existing.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="573px" /><p>After the new project is created, use <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 to add your source code directories to the project, and then save the project to disk.</p> <p>For some additional details, see <a class="reference" href="https://wingware.com/doc/howtos/virtualenv">Using Wing with virtual</a>.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> </div> https://wingware.com/hints/virtualenvWed, 05 Feb 2020 01:00:00 GMTUsing Black and YAPF Code Reformatting in Wing Python IDEhttps://wingware.com/hints/reformatting<p>Wing version 7.2 <a class="reference" href="https://wingware.com/news/2020-01-20">has been released</a>, so in the next couple <a class="reference" href="https://wingware.com/hints">Wing Tips</a> we'll take a look at some of its new features.</p> <p>Wing 7.2 expands the options for automatic code reformatting to include also <a class="reference" href="https://github.com/psf/black">Black</a> and <a class="reference" href="https://github.com/google/yapf">YAPF</a>, in addition to the previously supported <a class="reference" href="https://github.com/hhatto/autopep8">autopep8</a>. Using one of these allows you to develop nicely formatted uniform-looking code without spending time manually adjusting the layout of code.</p> <p>There are two ways to go about reformatting code in Wing with any of these: (1) You can reformat whole files or the current selection on request at any time, or (2) you can reformat automatically as you edit lines of code or save edited files to disk.</p> <p><strong>Installing Reformatters</strong></p> <p>Wing uses its own copy of autopep8 for PEP 8 style formatting. If you plan to use Black or YAPF formatting instead, then you must first install the selected formatter into the Python that you are using with your code. For example:</p> <pre class="literal-block"> pip install black pip install yapf </pre> <p>Or if you are using Anaconda:</p> <pre class="literal-block"> conda install black conda install yapf </pre> <p>After this is done, running Python on the command line with arguments <tt class="literal"><span class="pre">-m</span> <span class="pre">black</span></tt> or <tt class="literal"><span class="pre">-m</span> <span class="pre">yapf</span></tt> should invoke the reformatter.</p> <p><strong>Manual Reformatting</strong></p> <p>The <tt class="literal"><span class="pre">Source</span> <span class="pre">&gt;</span> <span class="pre">Reformatting</span></tt> menu contains items for reformatting the current file or selection for PEP 8, Black or YAPF:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-menu.png" alt="/images/blog/reformatting/reformat-menu.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="736px" /><p>The result of the above operation (reformatting the selection with Black) looks like this:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-menu-result.png" alt="/images/blog/reformatting/reformat-menu-result.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="643px" /><p>A single <tt class="literal"><span class="pre">Undo</span></tt> will undo the reformatting operation.</p> <p><strong>Automatic Reformatting</strong></p> <p>Wing can also auto-format edited lines after the caret leaves the line, or whole files as they are saved to disk. This is enabled with the <tt class="literal"><span class="pre">Auto-Reformat</span></tt> property under the <tt class="literal"><span class="pre">Options</span></tt> tab in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>, or with the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-formatting</span> <span class="pre">&gt;</span> <span class="pre">Auto-Reformat</span></tt> preference:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-automatic.png" alt="/images/blog/reformatting/reformat-automatic.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="362px" /><p>When this is set to <tt class="literal"><span class="pre">Lines</span> <span class="pre">After</span> <span class="pre">Edit</span></tt>, Wing only reformats lines that you have edited, as the editor caret leaves that line or before the file is saved. For example, using yapf as the formatter:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-auto-line.gif" alt="/images/blog/reformatting/reformat-auto-line.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Notice that reformatting applies to whole logical lines which, as in this case, may span more than one physical line.</p> <p>If <tt class="literal"><span class="pre">Whole</span> <span class="pre">Files</span> <span class="pre">Before</span> <span class="pre">Save</span></tt> auto-reformatting is used instead, then the whole file is reformatted before saving it to disk. For example, using Black as the formatter:</p> <img src="https://wingware.com/images/blog/reformatting/reformat-auto-file.gif" alt="/images/blog/reformatting/reformat-auto-file.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Note that Wing implements some timeouts for reformatting, so that very large files do not hang up saving or other operations, and there are some options available to control the details of formatting. See <a class="reference" href="/doc/edit/auto-reformatting">Auto-Reformatting</a> for more information.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> https://wingware.com/hints/reformattingWed, 22 Jan 2020 01:00:00 GMTNavigating Python Code with Wing Pro 7 (part 3 of 3)https://wingware.com/hints/code-navigation-3<p><a class="reference" href="/hints/code-navigation-2">Last week</a> and the <a class="reference" href="/hints/code-navigation-1">week before</a>, we looked at some of the code navigation features in Wing, including goto-definition, find uses, and project-wide search, code index menus, and the Source Browser.</p> <p>This week we'll finish up this mini-series by looking at how to quickly and easily find and open files or visit symbols in Python code by typing a name fragment.</p> <div class="section"> <h3 class="title-3">Project Configuration</h3> <p>The features described here assume that you have used <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 to add your source code to your project. Typically the project should contain the code you are actively working on. Packages that your code uses can be left out of the project, unless you anticipate often wanting to open or search files in them. Wing will still be able to find them through the Python Path, as needed for auto-completion, code warnings, and other purposes.</p> </div> <div class="section"> <h3 class="title-3">Open From Project</h3> <p><tt class="literal"><span class="pre">Open</span> <span class="pre">from</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">File</span></tt> menu is typically the easiest way to navigate to a file by name. This displays a dialog that lists the project files whose names match a fragment:</p> <img src="https://wingware.com/images/blog/code-navigation/open-from-project.png" alt="/images/blog/code-navigation/open-from-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="500px" /><p>Fragments can be abbreviations of the file name and may match enclosing directory names if they contain <tt class="literal"><span class="pre">/</span></tt> or <tt class="literal"><span class="pre">\</span></tt>. The arrow keys navigate the list and pressing <tt class="literal"><span class="pre">Enter</span></tt> opens the selected file.</p> </div> <div class="section"> <h3 class="title-3">Find Symbol</h3> <p>A similar interface is available to find Python code symbols by name. For the current file, this is <tt class="literal"><span class="pre">Find</span> <span class="pre">Symbol</span></tt> in the <tt class="literal"><span class="pre">Source</span></tt> menu. For all project files, use <tt class="literal"><span class="pre">Find</span> <span class="pre">Symbol</span> <span class="pre">in</span> <span class="pre">Project</span></tt> instead:</p> <img src="https://wingware.com/images/blog/code-navigation/find-symbol-in-project.png" alt="/images/blog/code-navigation/find-symbol-in-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="515px" /><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/code-navigation-3Thu, 28 Nov 2019 01:00:00 GMTNavigating Python Code with Wing Pro 7 (part 2 of 3)https://wingware.com/hints/code-navigation-2<p><a class="reference" href="/hints/code-navigation-1">Last week</a> we looked at goto-definition, find uses, and project-wide search as tools for navigating Python code in Wing 7. This time, we'll take a look at the code indices that Wing provides.</p> <div class="section"> <h3 class="title-3">Code Index Menus</h3> <p>A quick way to navigate code in the current Python file is to use the source index menus shown at the top of the editor:</p> <img src="https://wingware.com/images/blog/code-navigation/index-menus.png" alt="/images/blog/code-navigation/index-menus.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="713px" /><p>Depending on the location of the caret in the editor, Wing may show multiple menus, as in the above example: One for the contents of the top level of the file, one for the contents of the current top-level scope, and additional menus for each sub-scope. Clicking on any of these provides an index and selecting an item jumps to that place in the source code.</p> </div> <div class="section"> <h3 class="title-3">Source Browser</h3> <p>In Wing Pro only, the <tt class="literal"><span class="pre">Source</span> <span class="pre">Browser</span></tt> in the <tt class="literal"><span class="pre">Tools</span></tt> menu provides another way to view an index of your source code, either for the current module, all project modules, or all classes:</p> <img src="https://wingware.com/images/blog/code-navigation/source-browser.png" alt="/images/blog/code-navigation/source-browser.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="357px" /><p>The scope being browsed and the types of symbols shown may be selected by clicking on the menus at the top of the tool. Double-clicking on items displays them in the editor.</p> <p>Browsing all project modules or classes assume that you have used <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 to add your source code to your project. Typically the project should contain the code you are actively working on. Packages that your code uses can be left out of the project, unless you anticipate often wanting to open or search files in them. Wing will still be able to find them through the Python Path configured by Python or in Wing's <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>.</p> <br> <br><p>That's it for now! We'll be back next week to conclude this <a class="reference" href="/hints">Wing Tips</a> mini-series on navigating Python code with Wing.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/code-navigation-2Thu, 21 Nov 2019 01:00:00 GMTNavigating Python Code with Wing Pro 7 (part 1 of 3)https://wingware.com/hints/code-navigation-1<p>Wing Python IDE includes a boatload of features aimed at making it easier to navigate and understand the structure of Python code. Some of these allow for quick navigation between the definition and uses of a symbol. Others provide a convenient index into source code. And still others quickly find and open files or navigate to symbols matching a name fragment.</p> <p>In the this and the next two <a class="reference" href="/hints">Wing Tips</a>, we'll take a look at each of these in turn.</p> <div class="section"> <h3 class="title-3">Goto Definition</h3> <p>To get from any use of a symbol in Python code to its definition, use <tt class="literal"><span class="pre">Goto</span> <span class="pre">Selected</span> <span class="pre">Symbol</span> <span class="pre">Defn</span></tt> in the <tt class="literal"><span class="pre">Source</span></tt> menu. This jumps to the <tt class="literal"><span class="pre">def</span></tt>, <tt class="literal"><span class="pre">class</span></tt>, or the point at which a variable or attribute was first defined.</p> <p>Another way to do this is to right-click on the symbol in the editor and select <tt class="literal"><span class="pre">Goto</span> <span class="pre">Definition</span></tt> or <tt class="literal"><span class="pre">Goto</span> <span class="pre">Definition</span> <span class="pre">in</span> <span class="pre">Other</span> <span class="pre">Split</span></tt>:</p> <img src="https://wingware.com/images/blog/code-navigation/goto-definition.gif" alt="/images/blog/code-navigation/goto-definition.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" width="702px" /><p>The menus also give the key bindings for the commands, or you can bind your own key to the command <tt class="literal"><span class="pre">goto-selected-symbol-defn</span></tt> with the <tt class="literal"><span class="pre">User</span> <span class="pre">Interface</span> <span class="pre">&gt;</span> <span class="pre">Keyboard</span> <span class="pre">&gt;</span> <span class="pre">Custom</span> <span class="pre">Key</span> <span class="pre">Bindings</span></tt> preference.</p> <p>In some cases, jumping to a definition successfully depends on resolving imported modules correctly using the Python Path configured by Python. In most cases you will not need to add to this configuration, but doing so is possible with <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> from Wing's <tt class="literal"><span class="pre">Project</span></tt> menu.</p> </div> <div class="section"> <h3 class="title-3">Navigation History</h3> <p>For this and all the other code navigation options, the <img src="https://wingware.com/images/doc/en/icons/wingide-back.png" alt="history-back" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> button at the top left of the editor may be used to return to the previous file or focus. Or move forward again in your navigation history with the <img src="https://wingware.com/images/doc/en/icons/wingide-forward.png" alt="history-forward" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> button.</p> </div> <div class="section"> <h3 class="title-3">Find Uses</h3> <p>In Wing Pro only, <tt class="literal"><span class="pre">Find</span> <span class="pre">Points</span> <span class="pre">of</span> <span class="pre">Use</span></tt> in the <tt class="literal"><span class="pre">Source</span></tt> menu or the editor's right-click context menu finds all points of use of a symbol in Python code:</p> <img src="https://wingware.com/images/blog/code-navigation/find-uses.png" alt="/images/blog/code-navigation/find-uses.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="702px" /><p>This search distinguishes between different but like-named symbols and will cover all project files and other files Wing finds on the configured Python Path. The tool's <tt class="literal"><span class="pre">Options</span></tt> menu provides control over which files are searched and what types of matches are shown.</p> </div> <div class="section"> <h3 class="title-3">Search in Files</h3> <p>To find all occurrences of other strings in Python files or in project files of any type, use the <tt class="literal"><span class="pre">Search</span> <span class="pre">in</span> <span class="pre">Files</span></tt> tool from the <tt class="literal"><span class="pre">Tools</span></tt> menu with <tt class="literal"><span class="pre">Look</span> <span class="pre">in</span></tt> set to <tt class="literal"><span class="pre">Project</span> <span class="pre">Files</span></tt> and <tt class="literal"><span class="pre">Filter</span></tt> set to the narrowest filter that includes the files that you wish to search:</p> <img src="https://wingware.com/images/blog/code-navigation/search-in-files.png" alt="/images/blog/code-navigation/search-in-files.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="699px" /><p>This tool supports text matching, wildcard, and regular expression searching and automatically updates the search results as files change.</p> <p>Searching on <tt class="literal"><span class="pre">Project</span> <span class="pre">Files</span></tt> assumes that you have used <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 to add your source code to your project. Typically the project should contain the code you are actively working on. Packages that your code uses can be left out of the project, unless you anticipate often wanting to search them with <tt class="literal"><span class="pre">Search</span> <span class="pre">in</span> <span class="pre">Files</span></tt>.</p> <br> <br><p>That's it for now! We'll be back next week to continue this <a class="reference" href="/hints">Wing Tips</a> mini-series on navigating Python code with Wing.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/code-navigation-1Thu, 14 Nov 2019 01:00:00 GMTEfficient Flask Web Development with Wing 7https://wingware.com/hints/flask<p>Wing can develop and debug Python code running under <a class="reference" href="https://palletsprojects.com/p/flask/">Flask</a>, a web framework that is quick to get started with and easy to extend as your web application grows.</p> <p>To create a new project, use <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in Wing's <tt class="literal"><span class="pre">Project</span></tt> menu and select the project type <tt class="literal"><span class="pre">Flask</span></tt>. If Flask is not installed into your default Python, you may also need to set <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to the full path of the <tt class="literal"><span class="pre">python</span></tt> or <tt class="literal"><span class="pre">python.exe</span></tt> you want to use. This is 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 desired Python installation or virtualenv.</p> <p>Next, add your files 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.</p> <div class="section"> <h3 class="title-3">Debugging Flask in Wing</h3> <p>To debug Flask in Wing you need to turn off Flask's built-in debugger, so that Wing's debugger can take over reporting exceptions. This is done by setting the <tt class="literal"><span class="pre">debug</span></tt> attribute on the Flask application to <tt class="literal"><span class="pre">False</span></tt>:</p> <div class="python-highlight"><pre><span class="n">app</span><span class="o">.</span><span class="n">debug</span> <span class="o">=</span> <span class="bp">False</span> </pre></div> <p>Then use <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">Entry</span> <span class="pre">Point</span></tt> in the <tt class="literal"><span class="pre">Debug</span></tt> menu to set your main entry point, so you can start debugging from the IDE even if the main entry point file is not visible in the editor.</p> <p>Once debug is started, you can load pages from a browser to reach breakpoints or exceptions in your code. Output from the Flask process is shown in Wing's <tt class="literal"><span class="pre">Debug</span> <span class="pre">I/O</span></tt> tool.</p> </div> <div class="section"> <h3 class="title-3">Example</h3> <p>Here's an example of a complete &quot;Hello World&quot; Flask application that can be debugged with Wing:</p> <div class="python-highlight"><pre><span class="kn">import</span> <span class="nn">os</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">Flask</span> <span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span> <span class="nd">@app.route</span><span class="p">(</span><span class="s">&quot;/&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">hello</span><span class="p">():</span> <span class="k">return</span> <span class="s">&quot;&lt;h3&gt;Hello World!&lt;/h3&gt;&lt;p&gt;Your app is working.&lt;/p&gt;&quot;</span> <span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span> <span class="k">if</span> <span class="s">&#39;WINGDB_ACTIVE&#39;</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">:</span> <span class="n">app</span><span class="o">.</span><span class="n">debug</span> <span class="o">=</span> <span class="bp">False</span> <span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">()</span> </pre></div> <p>To try it, start debugging it in Wing and use the URL printed to the <tt class="literal"><span class="pre">Debug</span> <span class="pre">I/O</span></tt> tool to load the page in a web browser. Setting a breakpoint on the <tt class="literal"><span class="pre">return</span></tt> statement will stop there whenever the page is reloaded in the browser.</p> </div> <div class="section"> <h3 class="title-3">Setting up Auto-Reload with Wing Pro</h3> <p>With the above configuration, you will need to restart Flask whenever you make a change to your code, either with <tt class="literal"><span class="pre">Restart</span> <span class="pre">Debugging</span></tt> in the <tt class="literal"><span class="pre">Debug</span></tt> menu or with the <img src="https://wingware.com/images/doc/en/icons/wingide-debug-restart.png" alt="restart" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> toolbar icon.</p> <p>If you have Wing Pro, you can avoid the need to restart Flask by telling it to auto-restart when code changes on disk, and configuring Wing to automatically debug the restarted process.</p> <p>Flask is configured by adding a keyword argument to your <tt class="literal"><span class="pre">app.run()</span></tt> line:</p> <div class="python-highlight"><pre><span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">use_reloader</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> </pre></div> <p>Wing is configured by enabling <tt class="literal"><span class="pre">Debug</span> <span class="pre">Child</span> <span class="pre">Processes</span></tt> under the <tt class="literal"><span class="pre">Debug/Execute</span></tt> tab 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. This tells Wing Pro to debug also child processes created by Flask, including the reloader process.</p> <p>Now Flask will automatically restart on its own whenever you save an already-loaded source file to disk, and Wing will debug the restarted process. You can add additional files for Flask to watch as follows:</p> <div class="python-highlight"><pre><span class="n">watch_files</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;/path/to/file1&#39;</span><span class="p">,</span> <span class="s">&#39;/path/to/file2&#39;</span><span class="p">]</span> <span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">use_reloader</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">extra_files</span><span class="o">=</span><span class="n">watch_files</span><span class="p">)</span> </pre></div> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/flaskThu, 31 Oct 2019 01:00:00 GMTUsing Matplotlib with Wing 7https://wingware.com/hints/matplotlib<p>Wing supports interactive development and debugging of Python code designed for the Matplotlib numerical and scientific plotting library, so plots can be shown and updated from the command line. For example, two plots could be shown in succession by typing the following into Wing's <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>, one line at a time:</p> <div class="python-highlight"><pre><span class="kn">from</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">import</span> <span class="n">plot</span><span class="p">,</span> <span class="n">show</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="n">show</span><span class="p">()</span> <span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">4</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span> <span class="n">plot</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> </pre></div> <p>Wing sets up the environment so that <tt class="literal"><span class="pre">show()</span></tt> runs to completion and immediately returns you to the prompt, rather than waiting until the plot is closed. In addition, Wing calls Matplotlib's main loop to keep plots windows interactive and updating while you are at the prompt. This allows plots to be added or changed without restarting a process or interrupting your work flow:</p> <img src="https://wingware.com/images/blog/matplotlib/interactive-shell.gif" alt="/images/blog/matplotlib/interactive-shell.gif" backrefs="" caption="Working interactively with Matplotlib from Wing's Python Shell" class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Working interactively with Matplotlib from Wing's Python Shell</i></p><p><strong>Evaluating Files and Selections</strong></p> <p>Code from the editor can be executed in the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> with the <tt class="literal"><span class="pre">Evaluate</span> <span class="pre">...</span> <span class="pre">in</span> <span class="pre">Python</span> <span class="pre">Shell</span></tt> items in the <tt class="literal"><span class="pre">Source</span></tt> menu and in the editor's right-click context menu. By default the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> restarts automatically before evaluating a whole file, but this can be disabled in its <tt class="literal"><span class="pre">Options</span></tt> menu.</p> <p><strong>Active Ranges</strong></p> <p>Wing also allows you to set a selected range of lines in the editor as the &quot;active range&quot; for the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> by clicking the <img src="https://wingware.com/images/doc/en/icons/wingide-active-range-set.png" alt="setactive" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> icon in the top right of the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> tool:</p> <img src="https://wingware.com/images/blog/matplotlib/active-range.png" alt="/images/blog/matplotlib/active-range.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="570px" /><p>Wing highlights and maintains the active range as you edit it in the editor, and it can be re-evaluated easily with the <img src="https://wingware.com/images/doc/en/icons/wingide-execute.png" alt="runactive" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> icon that appears in the top right of the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> once an active range has been set into it.</p> <p>Use the <img src="https://wingware.com/images/doc/en/icons/wingide-active-range-clear.png" alt="clearactive" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> icon to clear the active range from the editor and shell.</p> <p><strong>Supported Backends</strong></p> <p>Interactive development is supported for the <tt class="literal"><span class="pre">TkAgg</span></tt>, <tt class="literal"><span class="pre">GTKAgg</span></tt>, <tt class="literal"><span class="pre">GtkCairo</span></tt>, <tt class="literal"><span class="pre">WXAgg</span></tt> (for wxPython 2.5+), <tt class="literal"><span class="pre">Qt5Agg</span></tt>, <tt class="literal"><span class="pre">Qt4Agg</span></tt>, <tt class="literal"><span class="pre">MacOSX</span></tt>, and <tt class="literal"><span class="pre">WebAgg</span></tt> backends. It will not work with other backends.</p> <div class="section"> <h3 class="title-3">Debugging</h3> <p>Code can be debugged either by launching a file with <img src="https://wingware.com/images/doc/en/icons/wingide-debug-continue.png" alt="startdebug" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> in the toolbar (or <tt class="literal"><span class="pre">Start/Continue</span></tt> the <tt class="literal"><span class="pre">Debug</span></tt> menu) or by enabling debug in the integrated <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and working from there. In either case, Wing can be used to reach breakpoints or exceptions, step through code, and view the program's data. For general information on using Wing's debugger see the <a class="reference" href="/debug/quick-start">Debugger Quick Start</a>.</p> <p>When executing code that includes <tt class="literal"><span class="pre">show()</span></tt> in the debugger, Wing will block within the <tt class="literal"><span class="pre">show()</span></tt> call just as Python would if launched on the same file. This is by design, since the debugger seeks to replicate as closely as possible how Python normally runs.</p> <p>However, interactive development from a breakpoint or exception is still possible, as described below. This capability can be used to load setup code before interacting with Matplotlib, or to try out a fix when an exception has been reached.</p> <p><strong>Interactive Debugging from the Debug Console (Wing Pro only)</strong></p> <p>Whenever the debugger is stopped at a breakpoint or exception, Wing Pro's <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> provides a command prompt that may be used to inspect and interact with the paused debug process. Commands entered here run in the context of the currently selected debug stack frame:</p> <img src="https://wingware.com/images/blog/matplotlib/debug-console.png" alt="/images/blog/matplotlib/debug-console.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="673px" /><p>The tool implements the same support for interactive development provided by the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>, so plots may be shown and modified interactively whenever Wing's debugger is paused. Once the debug process is continued, Wing switches off interactive mode and returns to behaving in the same way that Python would when running the code outside of the debugger.</p> <div class="note"> Interactive development from the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> requires that you have already imported <tt class="literal"><span class="pre">matplotlib</span></tt> in the code that you are debugging or in a previous command entered in the console. Otherwise <tt class="literal"><span class="pre">show()</span></tt> may block and plots won't be updated.</div> <p><strong>Interactive Debugging from the Python Shell</strong></p> <p>Another way to combine the debugger with interactive development is to turn on both <tt class="literal"><span class="pre">Enable</span> <span class="pre">Debugging</span></tt> and <tt class="literal"><span class="pre">Enable</span> <span class="pre">Recursive</span> <span class="pre">Prompt</span></tt> in the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>'s <tt class="literal"><span class="pre">Options</span></tt> menu:</p> <img src="https://wingware.com/images/blog/matplotlib/shell-options.png" alt="/images/blog/matplotlib/shell-options.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="305px" /><p>This causes Wing to add a breakpoint margin to the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and to stop in the debugger if an exception or breakpoint is reached, either in code in the editor or code that was entered into the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>.</p> <p>The option <tt class="literal"><span class="pre">Enable</span> <span class="pre">Recursive</span> <span class="pre">Prompt</span></tt> causes Wing to show a new recursive prompt in the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> whenever the debugger is paused, rather than waiting for completion of the original command before showing another prompt. Showing or updating plots from recursive prompts works interactively in the same way as described earlier.</p> <p>If another exception or breakpoint is reached, Wing stops at those as well, recursively to any depth. Continuing the debug process from a recursive prompt completes the innermost invocation and returns to the previous recursive prompt, unless another exception or breakpoint is reached first.</p> </div> <div class="section"> <h3 class="title-3">Trouble-shooting</h3> <p>If <tt class="literal"><span class="pre">show()</span></tt> blocks when typed into the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>, if plots fail to update, or if you run into other event loop problems while working with Matplotlib, then the following may help solve the problem:</p> <p>(1) When working in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>, evaluate the imports that set up Matplotlib first, so that Wing can initialize its event loop support before <tt class="literal"><span class="pre">show()</span></tt> is called. Evaluating a whole file at once in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> (but not the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt>) will cause <tt class="literal"><span class="pre">show()</span></tt> to block if Matplotlib was not previously imported.</p> <p>(2) In case there is a problem with the specific Matplotlib backend that you are using, try the following as a way to switch to another backend before issuing any other commands:</p> <div class="python-highlight"><pre><span class="kn">import</span> <span class="nn">matplotlib</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">use</span><span class="p">(</span><span class="s">&#39;TkAgg&#39;</span><span class="p">)</span> </pre></div> <p>Instead of <tt class="literal"><span class="pre">TkAgg</span></tt> you may also try other supported backends, including <tt class="literal"><span class="pre">Qt5Agg</span></tt> (which requires that Qt5 is installed) or <tt class="literal"><span class="pre">WebAgg</span></tt> (which uses a web browser for plot display).</p> <p>As always, please email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems that you cannot resolve.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> </div> https://wingware.com/hints/matplotlibThu, 17 Oct 2019 01:00:00 GMTPython Code Warnings in Wing Pro 7https://wingware.com/hints/code-warnings<p>Wing Pro 7 introduced an improved code warnings system that flags likely errors as you work on Python code, using both Wing's built-in static analysis system and (optionally) external code checkers like Pylint, pep8, and mypy. Likely problems are indicated on the editor and listed in the <tt class="literal"><span class="pre">Code</span> <span class="pre">Warnings</span></tt> tool:</p> <img src="https://wingware.com/images/blog/code-warnings/overview.png" alt="/images/blog/code-warnings/overview.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="893px" /><p>Examples of warnings that Wing might flag include syntax errors, indentation problems, uses of an undefined variable, imports that cannot be resolved, or variables that are set but never used.</p> <p>Code warnings save development time because they help to identify errors before code is even run. New code is checked as you work, although Wing will wait until you have finished typing so that it doesn't warn about code that is still being entered.</p> <div class="section"> <h3 class="title-3">Navigating Warnings</h3> <p>Clicking on warnings in the <tt class="literal"><span class="pre">Code</span> <span class="pre">Warnings</span></tt> tool or pressing the <tt class="literal"><span class="pre">Enter</span></tt> key in the list navigates to that warning in the editor, highlighting it briefly with a callout, as configured from the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Callouts</span></tt> preferences group.</p> <p>The <img src="https://wingware.com/images/doc/en/icons/wingide-warnings.png" alt="warning" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> code warnings icon appears in the top right of any editor that has some code warnings. This can be clicked in order to jump to selected warnings in the file.</p> <p>When code warnings are displayed on the editor, hovering the mouse cursor over the indicator will display details for that warning in a tooltip, as shown above.</p> </div> <div class="section"> <h3 class="title-3">Configuration</h3> <p>The types of code warnings that Wing shows can be configured from the <tt class="literal"><span class="pre">Configuration:</span> <span class="pre">Defaults</span></tt> page in the drop-down menu at the top of the <tt class="literal"><span class="pre">Code</span> <span class="pre">Warnings</span></tt> tool. All the warnings Wing supports are documented in <a class="reference" href="/doc/warnings/warning-types">Warning Types</a>. Some of these offer configuration options to control which variants of that type of warning will be shown:</p> <img src="https://wingware.com/images/blog/code-warnings/config.png" alt="/images/blog/code-warnings/config.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="417px" /><p>Incorporating warnings found by external checkers like Pylint, pep8, and mypy is also done from this configuration page, as described previously in <a class="reference" href="/hints/external-checkers">Using External Code Quality Checkers with Wing Pro 7</a></p> </div> <div class="section"> <h3 class="title-3">Disabling Warnings</h3> <p>Since all code checkers have only a limited understanding of what happens when code is actually run, they may show incorrect warnings. Wing allows you to disable warnings either for a single case, for an entire file, or for all files.</p> <p>The quickest way to disable a warning is to press the red <tt class="literal"><span class="pre">X</span></tt> icon that appears in the tooltips shown in the editor or in the currently selected item in the <tt class="literal"><span class="pre">Code</span> <span class="pre">Warnings</span></tt> tool:</p> <img src="https://wingware.com/images/blog/code-warnings/x-icon.png" alt="/images/blog/code-warnings/x-icon.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="333px" /><p>Wing disables most individual warnings only for the scope it appears in, so an identical problem in another scope will still be flagged. However, undefined attribute warnings are always disabled in all files where that attribute appears.</p> <p><strong>How it Works</strong></p> <p>When a warning is disabled, Wing adds a rule to the <tt class="literal"><span class="pre">Configuration:</span> <span class="pre">Disabled</span> <span class="pre">Warnings</span></tt> page in the drop-down menu at the top of the <tt class="literal"><span class="pre">Code</span> <span class="pre">Warnings</span></tt> tool:</p> <img src="https://wingware.com/images/blog/code-warnings/disabled.png" alt="/images/blog/code-warnings/disabled.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="396px" /><p>Rules can be removed from here to reenable a warning, dragged between sections to control how widely the warning is being ignored, or edited by right-clicking in order to fine-tune the scope and nature of the rule.</p> <p>For external checkers like Pylint, pep8, and mypy, warnings are disabled globally by the type of warning, making it relatively easy to develop a custom filter according to coding style and individual preference.</p> <p><strong>Resolving Imports</strong></p> <p>One thing to note here is that all the error checkers need some knowledge of your <tt class="literal"><span class="pre">PYTHONPATH</span></tt> to trace down imports correctly. Often, no additional configuration is needed, but in cases where imports cannot be resolved you may need to add to the <tt class="literal"><span class="pre">Python</span> <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.</p> </div> <div class="section"> <h3 class="title-3">Sharing Code Warnings Configurations</h3> <p>The current code warnings configuration, including all the warnings you have disabled, may be exported to the user settings area, or to a selected file from the <tt class="literal"><span class="pre">Options</span></tt> menu in the <tt class="literal"><span class="pre">Code</span> <span class="pre">Warnings</span></tt> tool. Projects may then share the configuration through the <tt class="literal"><span class="pre">Use</span> <span class="pre">Configuration</span> <span class="pre">From</span></tt> item in the <tt class="literal"><span class="pre">Code</span> <span class="pre">Warnings</span></tt> tool's <tt class="literal"><span class="pre">Options</span></tt> menu:</p> <img src="https://wingware.com/images/blog/code-warnings/options-menu.png" alt="/images/blog/code-warnings/options-menu.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="416px" /><p>The shared configuration file may be checked into revision control, so it can also be used by other developers working on your project.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> </div> https://wingware.com/hints/code-warningsThu, 10 Oct 2019 01:00:00 GMTDebugging Python Code Running in Docker Containers with Wing 7https://wingware.com/hints/docker<p><a class="reference" href="https://www.docker.com/">Docker</a> is a containerization system that uses a relatively light-weight form of virtualization to package and isolate application components from the host system, making it easier to spin up uniformly configured virtual machines for use in application development, testing, and deployment.</p> <p>Wing 7 can be used to develop and debug Python code running inside of Docker containers. This is accomplished by setting up a mapping of local (host-side) directories into the container, and then configuring Wing so it can accept debug connections from the container.</p> <div class="section"> <h3 class="title-3">Prerequisites</h3> <p>Before you can work with Docker you will need to download and install it.</p> <p><strong>On Windows and macOS</strong>, downloading Docker Desktop from the <a class="reference" href="https://www.docker.com/">Docker</a> website is the easiest way to install it. Be sure to launch the Docker Desktop after you install it, so the daemon is started.</p> <p><strong>On most Linux distributions</strong>, Docker CE (the free community edition) can be installed with the <tt class="literal"><span class="pre">docker-engine</span></tt> package as <a class="reference" href="https://runnable.com/docker/install-docker-on-linux">described here</a>.</p> <p>You should also install <a class="reference" href="https://wingware.com/downloads/wing-pro">Wing Pro</a> if you don't already have it.</p> </div> <div class="section"> <h3 class="title-3">Create a Working Example</h3> <p>Next set up a small real world example by creating a directory <tt class="literal"><span class="pre">docker</span></tt> and placing the following files into it.</p> <p><strong>Dockerfile</strong>:</p> <pre class="literal-block"> FROM python:3.7 WORKDIR /app RUN pip install --trusted-host pypi.python.org Flask EXPOSE 80 CMD [&quot;python&quot;, &quot;app.py&quot;] </pre> <p><strong>app.py:</strong></p> <div class="python-highlight"><pre><span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">Flask</span> <span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span> <span class="nd">@app.route</span><span class="p">(</span><span class="s">&quot;/&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">hello</span><span class="p">():</span> <span class="k">return</span> <span class="s">&quot;&lt;h3&gt;Hello World!&lt;/h3&gt;Your app is working.&lt;br/&gt;&lt;/br/&gt;&quot;</span> <span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span> <span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">host</span><span class="o">=</span><span class="s">&#39;0.0.0.0&#39;</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">80</span><span class="p">,</span> <span class="n">use_reloader</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> </pre></div> <p>Then build the Docker container by typing the following in the <tt class="literal"><span class="pre">docker</span></tt> directory:</p> <pre class="literal-block"> docker build --tag=myapp . </pre> <p>You can now run your container like this:</p> <pre class="literal-block"> docker run -v &quot;/path/to/docker&quot;:/app -p 4000:80 myapp </pre> <p>You will need to substitute <tt class="literal"><span class="pre">/path/to/docker</span></tt> with the path to the <tt class="literal"><span class="pre">docker</span></tt> directory you created above; the quotes make it work if the path has spaces in it.</p> <p>You can now try this tiny Flask- web app by pointing a browser running on your host system at it:</p> <p><strong>If you are using Docker Desktop</strong>, then use <a class="reference" href="http://localhost:4000/">http://localhost:4000/</a></p> <p><strong>If you are using Docker CE</strong>, you will need to determine the IP address of your container and use that instead of <tt class="literal"><span class="pre">localhost</span></tt>. One way to do this is to type <tt class="literal"><span class="pre">docker</span> <span class="pre">ps</span></tt> to find the Container ID for your container and then use it in the following in place of <tt class="literal"><span class="pre">c052478b0f8a</span></tt>:</p> <pre class="literal-block"> docker inspect -f &quot;{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}&quot; c052478b0f8a </pre> <p>Notice that if you make a change to <tt class="literal"><span class="pre">app.py</span></tt> in Wing, then the change will be reflected in your browser when you reload the page. This is due to using both the <tt class="literal"><span class="pre">-v</span></tt> argument for <tt class="literal"><span class="pre">docker</span> <span class="pre">run</span></tt> to mount a volume in the container, and the fact that <tt class="literal"><span class="pre">app.run()</span></tt> for Flask is being passed <tt class="literal"><span class="pre">use_reloader=True</span></tt>.</p> </div> <div class="section"> <h3 class="title-3">Configure Debugging</h3> <p>In order to debug <tt class="literal"><span class="pre">app.py</span></tt> in Wing, you will need to copy in and configure some additional files that allow invocation of Wing's debugger and connection to the IDE.</p> <p><strong>(1) Install the debugger</strong></p> <p>To access Wing's debugger on the container, add another <tt class="literal"><span class="pre">-v</span></tt> mapping to your <tt class="literal"><span class="pre">docker</span> <span class="pre">run</span></tt> command line, so the Wing installation on the host is made available to the container. For example on Windows:</p> <pre class="literal-block"> docker run -v &quot;C:/Program Files (x86)/Wing Pro 7.2&quot;:/wingpro7 -v C:/Users/test/docker:/app myapp </pre> <p>Or on Linux:</p> <pre class="literal-block"> docker run -v /usr/lib/wingpro7:/wingpro7 -v /home/test/docker:/app myapp </pre> <p>Or for macOS:</p> <pre class="literal-block"> docker run -v /Applications/WingPro.app/Contents/Resources:/wingpro7 -v /Users/test/docker:/app myapp </pre> <p>You will need to substitute the correct installation location for Wing on your host, which can be seen in Wing's <tt class="literal"><span class="pre">About</span></tt> box, and the full path to the <tt class="literal"><span class="pre">docker</span></tt> directory you created earlier.</p> <p>Mapping the Wing installation across OSes (for example from Windows host to Linux container) works because Wing's installation has all the files necessary files for debugging on every supported OS.</p> <p><strong>(2) Copy and configure wingdbstub.py</strong></p> <p>Debugging is initiated on the Docker side by importing Wing's <tt class="literal"><span class="pre">wingdbstub</span></tt> module. To use this, copy <tt class="literal"><span class="pre">wingdbstub.py</span></tt> from your Wing installation to your mapped directory on the host. For example on a Windows host:</p> <pre class="literal-block"> copy &quot;C:/Program Files (x86)/Wing Pro 7.2/wingdbstub.py&quot; C:/Users/test/docker </pre> <p>Or on a Linux host:</p> <pre class="literal-block"> cp /usr/lib/wingpro7/wingdbstub.py /home/test/docker </pre> <p>Or a macOS host:</p> <pre class="literal-block"> cp /Applications/WingPro.app/Contents/Resources/wingdbstub.py /Users/test/docker </pre> <p>After copying, you will need to edit the file to change <tt class="literal"><span class="pre">kWingHostPost</span></tt> from <tt class="literal"><span class="pre">localhost:50005</span></tt> to a value that uses the IP address or name of the host computer, for example if your host's IP address is <tt class="literal"><span class="pre">192.168.1.50</span></tt>:</p> <div class="python-highlight"><pre><span class="n">kWingHostPort</span> <span class="o">=</span> <span class="s">&#39;192.168.1.50:50005&#39;</span> </pre></div> <p>You will also need to set <tt class="literal"><span class="pre">WINGHOME</span></tt> to the location where you have mapped your Wing installation on the container:</p> <div class="python-highlight"><pre><span class="n">WINGHOME</span> <span class="o">=</span> <span class="s">&#39;/wingpro7&#39;</span> </pre></div> <p><strong>(3) Enable access</strong></p> <p>Next you need to copy the authentication token file <tt class="literal"><span class="pre">wingdebugpw</span></tt> from the <tt class="literal"><span class="pre">Settings</span> <span class="pre">Directory</span></tt> listed in Wing's <tt class="literal"><span class="pre">About</span></tt> box to the same directory as your copy of <tt class="literal"><span class="pre">wingdbstub.py</span></tt>, in this case the <tt class="literal"><span class="pre">docker</span></tt> directory on the host system.</p> <p>Then add to the <tt class="literal"><span class="pre">Debugger</span> <span class="pre">&gt;</span> <span class="pre">Advanced</span> <span class="pre">&gt;</span> <span class="pre">Allowed</span> <span class="pre">Hosts</span></tt> preference either the host's IP address (if using Docker Desktop) or the container's IP address determined with <tt class="literal"><span class="pre">docker</span> <span class="pre">inspect</span></tt> as described above (if using Docker CE). The host IP is used for Docker Desktop because of how it configures networking for containers; there is access from container to host but no access in the other direction, so the host thinks it is receiving a connection from one of its own network interfaces.</p> <p>You will also need to tell Wing to listen for debug connections initiated from the outside by clicking on the bug icon in the lower left of Wing's window and enabling <tt class="literal"><span class="pre">Accept</span> <span class="pre">Debug</span> <span class="pre">Connections</span></tt>.</p> <p><strong>(4) Establish a file mapping</strong></p> <p>If the <tt class="literal"><span class="pre">docker</span></tt> directory you mapped with the <tt class="literal"><span class="pre">-v</span></tt> option for <tt class="literal"><span class="pre">docker</span> <span class="pre">run</span></tt> does not appear on the same path on the host and container then you will need to communicate the mapping to Wing as well, with the <tt class="literal"><span class="pre">Debugger</span> <span class="pre">&gt;</span> <span class="pre">Advanced</span> <span class="pre">&gt;</span> <span class="pre">Location</span> <span class="pre">Map</span></tt> preference.</p> <p>For the <tt class="literal"><span class="pre">docker</span> <span class="pre">run</span></tt> example above and container IP address of <tt class="literal"><span class="pre">172.17.0.2</span></tt> you would add an entry as follows:</p> <b>Remote IP Address:</b> 172.17.0.2<br/> <b>File Mappings:</b><br/> &nbsp;&nbsp;&nbsp;&nbsp;&#x1f518;&nbsp;<b>Specify Mapping</b><br/> &nbsp;&nbsp;&nbsp;&nbsp;<b>Remote:</b> /app<br/> &nbsp;&nbsp;&nbsp;&nbsp;<b>Local:</b> C:/Users/test/docker<br/> <br><p>This step could be skipped entirely if the location of files on the container and the host are the same (for example using <tt class="literal"><span class="pre">/app</span></tt> also on the host instead of creating a directory named <tt class="literal"><span class="pre">docker</span></tt>).</p> <p>Also, if using Docker Desktop where the container IP is the same as the hosts's, it is important to choose a location for the container side of the mapping that either (a) does not exist on the host, or (b) is the same as the location on the host. If the directory exists on the host but has different Python files in it, the <tt class="literal"><span class="pre">Location</span> <span class="pre">Map</span></tt> will be incorrectly applied to them if you try to debug them.</p> <p><strong>(5) Initiate debug</strong></p> <p>Once these steps are complete, you can initiate debug from Python code running in the container by importing the module <tt class="literal"><span class="pre">wingdbstub.py</span></tt> as follows:</p> <div class="python-highlight"><pre><span class="kn">import</span> <span class="nn">wingdbstub</span> </pre></div> <p>This can be added as the first line of <tt class="literal"><span class="pre">app.py</span></tt>. After saving the file, Flask should auto-reload it, which will initiate debug and connect to the IDE so that the bug icon in the lower left of Wing's Window turns green and the toolbar changes to its debug configuration. The application keeps running until it reaches a breakpoint or exception.</p> <p>Next set a breakpoint by clicking leftmost margin to the left of the <tt class="literal"><span class="pre">return</span></tt> statement in <tt class="literal"><span class="pre">app.py</span></tt> and then trigger it by reloading the page in your browser. Now you can use Wing to step through and inspect the data being used in the debug process.</p> <p>To learn more about Wing's debugger, take a look at the <tt class="literal"><span class="pre">Tutorial</span></tt> in Wing's Help menu or the <tt class="literal"><span class="pre">Debugging</span> <span class="pre">Code</span></tt> section of the <a class="reference" href="/doc/howtos/quickstart">Quick Start Guide</a>.</p> </div> <div class="section"> <h3 class="title-3">Trouble-Shooting</h3> <p>If your configuration does not work, try setting <tt class="literal"><span class="pre">kLogFile</span></tt> in your copy of <tt class="literal"><span class="pre">wingdbstub.py</span></tt> to see whether the debugger is reporting errors. Also, looking at the end of <tt class="literal"><span class="pre">ide.log</span></tt> in the <tt class="literal"><span class="pre">Settings</span> <span class="pre">Directory</span></tt> listed in Wing's <tt class="literal"><span class="pre">About</span></tt> box may reveal why a connection is failing, if it is being refused by the IDE.</p> <p>Setting <tt class="literal"><span class="pre">kExitOnFailure</span></tt> in your copy of <tt class="literal"><span class="pre">wingdbstub.py</span></tt> is another way to see why debug or the connection to the IDE is failing. In this case, when you restart the container it will fail to start and print a message indicating the error encountered during <tt class="literal"><span class="pre">import</span> <span class="pre">wingdbstub</span></tt>.</p> <p>If the debug connection is established but breakpoints are not reached, the <tt class="literal"><span class="pre">Location</span> <span class="pre">Map</span></tt> preference is likely incorrect. One way to diagnose this is to add <tt class="literal"><span class="pre">assert</span> <span class="pre">0</span></tt> to your code. Wing will always stop on that and will report the file it thinks it should be opening in the <tt class="literal"><span class="pre">Exceptions</span></tt> tool.</p> <p>And, as always, don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> for help.</p> </div> <div class="section"> <h3 class="title-3">Notes</h3> <p>Docker CE (but not Docker Desktop) is sometimes used to host a more complete installation of Linux, acting more like a stand-alone system that includes the ability to <tt class="literal"><span class="pre">ssh</span></tt> from the host system into the container. In this case, Wing Pro's <a class="reference" href="https://wingware.com/doc/proj/remote-hosts">Remote Development</a> capability can be used, with much less manual configuration, to debug code running under Docker. For more information, see <a class="reference" href="/doc/howtos/remote-development">Remote Python Development</a> (if the debug process can be launched from the IDE) or <a class="reference" href="/doc/howtos/debugging-web-remote">Remote Web Development</a> (if the debug process is launched from outside of the IDE).</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> </div> https://wingware.com/hints/dockerTue, 24 Sep 2019 01:00:00 GMTViewing Arrays and Data Frames in Wing Pro 7https://wingware.com/hints/array-viewer<p>Wing Pro 7 introduced an array and data frame viewer that can be used to inspect data objects in the debugger. Values are transferred to the IDE according to what portion of the data is visible on the screen, so working with large data sets won't slow down the IDE.</p> <p>The array viewer works with Pandas, numpy, sqlite3, xarray, Python's builtin lists, tuples, and dicts, and other classes that emulate lists, tuples, or dicts.</p> <p>To use the array viewer, right-click on a value in the <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> tool in Wing Pro and select <tt class="literal"><span class="pre">Show</span> <span class="pre">Value</span> <span class="pre">as</span> <span class="pre">Array</span></tt>:</p> <img src="https://wingware.com/images/blog/array-viewer/menu.png" alt="/images/blog/array-viewer/menu.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="1018px" /><p>This reveals the array viewer and displays the selected item from the <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> tree, in this case the global variable <tt class="literal"><span class="pre">pandas_df</span></tt>:</p> <img src="https://wingware.com/images/blog/array-viewer/array.png" alt="/images/blog/array-viewer/array.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="1019px" /><p>Wing fetches data for display as you move the scroll bars. The <tt class="literal"><span class="pre">Filter</span></tt> can be used to display only matching rows:</p> <img src="https://wingware.com/images/blog/array-viewer/filter.png" alt="/images/blog/array-viewer/filter.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="582px" /><p>The drop down next to the <tt class="literal"><span class="pre">Filter</span></tt> field may be used to select plain text, wildcard, or regular expression searching, to control whether searches are case sensitive, and to select whether to search on all columns or only the visible columns.</p> <p>If more space is needed to view data, the <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> tool's tab can be dragged out of the window, to create a separate window for it.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> https://wingware.com/hints/array-viewerThu, 19 Sep 2019 01:00:00 GMTPresentation Mode in Wing 7https://wingware.com/hints/presentation-mode<p>Presentation Mode, added in Wing 7, temporarily applies a selected magnification to the entire user interface, so the screen can be read more easily during meetings or talks.</p> <p>To activate this mode, check on <tt class="literal"><span class="pre">Presentation</span> <span class="pre">Mode</span></tt> in the high-level configuration menu accessed with the <img src="https://wingware.com/images/blog/dark-mode/menu.png" alt="menuicon" backrefs="" class="inline-image" dupnames="" ids="" names="" /> icon at the top right of Wing's window:</p> <img src="https://wingware.com/images/blog/presentation-mode/menu.png" alt="/images/blog/presentation-mode/menu.png" backrefs="" class="doc-image" dupnames="" height="320px" ids="" names="" width="275px" /><p>You will be presented with a confirmation dialog that also provides a link to the preference that controls the level of magnification:</p> <img src="https://wingware.com/images/blog/presentation-mode/dialog.png" alt="/images/blog/presentation-mode/dialog.png" backrefs="" class="doc-image" dupnames="" height="118px" ids="" names="" width="672px" /><p>To apply the mode change, Wing restarts and reloads the current project in the same state as you left it, but with the contents of the window magnified.</p> <div class="section"> <h3 class="title-3">Before</h3> <img src="https://wingware.com/images/blog/presentation-mode/window-1.0.png" alt="/images/blog/presentation-mode/window-1.0.png" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">After</h3> <img src="https://wingware.com/images/blog/presentation-mode/window-1.5.png" alt="/images/blog/presentation-mode/window-1.5.png" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>To disable Presentation Mode, uncheck the high-level configuration menu item again.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> </div> https://wingware.com/hints/presentation-modeWed, 11 Sep 2019 01:00:00 GMT