Wing Tipshttps://wingware.com/Tips, tricks, and helpful hints for Wingware's Python IDEsMon, 04 Dec 2023 17:10:53 GMTPyRSS2Gen-1.0.0http://www.dalkescientific.com/Python/PyRSS2Gen.htmlUnit Testing in Wing Prohttps://wingware.com/hints/unit-testing<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> introduces the <tt class="literal"><span class="pre">Testing</span></tt> tool in <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a>, which can be used to run and debug unit tests designed for the unittest, pytest, doctest, nose, or Django testing frameworks. Wing can collect code coverage statistics, so you can see if your tests are properly exercising your code, and so that Wing can determine which tests need to be re-run after you make edits to your code.</p> <div class="section"> <h3 class="title-3">Identifying Test Files</h3> <p>You can identify files to run as tests in your project either by setting <tt class="literal"><span class="pre">Test</span> <span class="pre">file</span> <span class="pre">patterns</span></tt> under the <tt class="literal"><span class="pre">Testing</span></tt> tab in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> (accessed from the <tt class="literal"><span class="pre">Project</span></tt> menu) or by adding individual test files with <tt class="literal"><span class="pre">Add</span> <span class="pre">Single</span> <span class="pre">File</span></tt> and <tt class="literal"><span class="pre">Add</span> <span class="pre">Current</span> <span class="pre">File</span></tt> in the <tt class="literal"><span class="pre">Testing</span></tt> menu.</p> </div> <div class="section"> <h3 class="title-3">Running and Debugging Tests</h3> <p>Once you have identified test files, you should see them listed in the <tt class="literal"><span class="pre">Testing</span></tt> tool and can use the <tt class="literal"><span class="pre">Run</span> <span class="pre">Tests</span></tt> button to run them. The <tt class="literal"><span class="pre">Testing</span></tt> tool will update as tests complete, indicating which tests passed and failed. This includes display of any exception encountered and output from the tests.</p> <p>Failed tests may then be debugged by selecting them in the <tt class="literal"><span class="pre">Testing</span></tt> tool and pressing the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Tests</span></tt> button:</p> <img src="https://wingware.com/images/blog/testing/testing.gif" alt="Testing Tool in Wing Pro" backrefs="" caption="Shown above: Running unit tests in Wing Pro, inspecting test results, and debugging one failed test." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Running unit tests in Wing Pro, inspecting test results, and debugging one failed test.</i></p><p>The items in the <tt class="literal"><span class="pre">Testing</span></tt> menu can be used to run or re-run tests selectively, for example only those at the caret in the editor, those that previously failed, or those that have not yet been run.</p> </div> <div class="section"> <h3 class="title-3">Code Coverage</h3> <p>To enable collection of code coverage statistics, make sure you have installed <tt class="literal"><span class="pre">coverage</span></tt> (for example with <tt class="literal"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre">coverage</span></tt>), select <tt class="literal"><span class="pre">Use</span> <span class="pre">Code</span> <span class="pre">Coverage</span></tt> in the <tt class="literal"><span class="pre">Testing</span></tt> tool, and then run some or all of your unit tests. Wing annotates every line of code in editors to indicate whether that line was reached by any of the unit tests that you have run. Hover the mouse cursor over lines marked in green to see which tests reached that line:</p> <img src="https://wingware.com/images/blog/testing/testing-coverage.gif" alt="Code Coverage Annotations" backrefs="" caption="Shown above: Code coverage marks indicate which lines of code have been tested." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Code coverage marks indicate which lines of code have been tested.</i></p><p>When code coverage is enabled, Wing will watch your edits in order to determine which previously run test results are invalidated by those edits. Any tests that reached the edited code will be marked as invalid in the <tt class="literal"><span class="pre">Testing</span></tt> tool by changing the color of the test result icon to yellow:</p> <img src="https://wingware.com/images/blog/testing/testing-invalidated.gif" alt="Invalidated Unit Test Results" backrefs="" caption="Shown above: A unit test result is invalidated by editing code that was reached by that test. All the tests with invalidated test results are then re-run with Run Stale Tests in the Testing menu." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: A unit test result is invalidated by editing code that was reached by that test. All the tests with invalidated test results are then re-run with Run Stale Tests in the Testing menu.</i></p><p>An HTML code coverage report and various code coverage data export options are available in the <tt class="literal"><span class="pre">Testing</span></tt> menu.</p> <p>For more information on unit testing and code coverage in Wing Pro, see the <a class="reference" href="/doc/testing">Unit Testing</a> documentation.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/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/unit-testingThu, 08 Jun 2023 01:00:00 GMTSource Assistant in Wing Prohttps://wingware.com/hints/source-assistant<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> introduces the <tt class="literal"><span class="pre">Source</span> <span class="pre">Assistant</span></tt> tool in <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a>, which provides context-sensitive at-your-fingertips code intelligence and documentation as you navigate through or write Python code.</p> <p>The Source Assistant is where Wing Pro shows details about the type of a symbol, including documentation, call signature, and information about object inheritance and overridden methods. For builtin types and the standard library, this includes also links into Python documentation.</p> <p>The Source Assistant is integrated with every part of Wing IDE, so it shows information for the current selection in the editor, auto-completer, Python Shell, Source Browser, Project manager, and Debug Console. It continuously updates as you move through your code or write new code.</p> <p>Here are some examples of the Source Assistant in action in the editor, auto-completer, and Source Browser:</p> <img src="https://wingware.com/images/blog/source-assistant/source-assistant.gif" alt="Source Assistant in Wing Pro" backrefs="" caption="Shown above: Moving through code in the editor, the auto-completer, and Source Browser to view type signature, documentation, and other code intelligence in Wing Pro's Source Assistant tool." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Moving through code in the editor, the auto-completer, and Source Browser to view type signature, documentation, and other code intelligence in Wing Pro's Source Assistant tool.</i></p><p>See the <a class="reference" href="/doc/edit/source-assistant">Source Assistant</a> documentation for details.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/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/source-assistantThu, 08 Jun 2023 01:00:00 GMTLive Interactive Python Coding in Wing Prohttps://wingware.com/hints/live-coding<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to use the debugger in <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a> to write new Python code with direct access to the runtime state that the code is intended for, so you can immediately try out the code that you write. This is a far more efficient way to write most code, compared with working offline.</p> <p>The key to working interactively in Wing is to run the debugger to a breakpoint in the code that you are working on. Once this is done, the auto-completer and other code intelligence features in Wing use both static analysis and runtime type analysis in code that is active on the debug process stack. The source of a symbol in the completer is indicated with the <img src="https://wingware.com/images/doc/en/icons/wingide-autocomplete-runtime.png" alt="runtime" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="36" /> cog &quot;runtime&quot; icon.</p> <p>In this context, you can immediately try out newly written code, and retry it as often as needed after correcting errors, by executing it in Wing Pro's <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> tool. You do need to be mindful of what the (possibly incorrect) code that you try does to the runtime state and restart the debugger if it becomes invalid. But in most cases it is possible to re-run corrected code and work iteratively without restarting your code.</p> <p>Here is an example of live interactive coding in Wing Pro after running to a breakpoint in the editor:</p> <img src="https://wingware.com/images/blog/conditional-breakpoints/interactive.gif" alt="Interactive Development at a Breakpoint" backrefs="" caption="Shown above: Entering code while the debugger is at a breakpoint, with auto-completion and auto-editing features that inspect the live runtime state of the debug process, then trying out an invocation in the Debug Console." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Entering code while the debugger is at a breakpoint, with auto-completion and auto-editing features that inspect the live runtime state of the debug process, then trying out an invocation in the Debug Console.</i></p><p>Notice that the above example uses a conditional breakpoint, as described in the <a class="reference" href="https://wingware.com/hints/conditional-breakpoints">previous Wing Tip</a>. These are a great way to select the specific runtime case for which you want to write new code, for example to fix a bug that occurs only in a particular scenario.</p> <div class="section"> <h3 class="title-3">Active Ranges</h3> <p>The above example simply copied and pasted code into the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> in order to try it out. In many cases it's easier to select a range of lines that you are working on and mark those as the &quot;active range&quot;, so that they can be executed and re-executed repeatedly as needed.</p> <p>This is done by selecting the lines in the editor and pressing the <img src="https://wingware.com/images/doc/en/icons/wingide-active-range-set.png" alt="active-range" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> active range icon in the top right of the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>. Once an active range is set, the <img src="https://wingware.com/images/doc/en/icons/wingide-execute.png" alt="execute" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> icon in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> will execute it in the current debug stack frame.</p> <p>See the <a class="reference" href="/doc/debug/debug-console">Interactive Debug Console</a> documentation for details.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/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/live-codingThu, 08 Jun 2023 01:00:00 GMTAuto Completion in Wing Prohttps://wingware.com/hints/auto-completion<p>In this issue of <a class="reference" href="/hints">Wing Tips</a> we introduce Wing Pro's auto-completer, which can be used to find and more quickly enter symbols, imports, and snippets into Python code.</p> <p>By default, Wing shows the auto-completer as you type in the editor, populating the completer with whatever code symbols and snippets are relevant to the particular context you are working in. The arrow keys can be used to move up and down the completion list and a completion is selected by pressing <tt class="literal"><span class="pre">Tab</span></tt> or other completion key configured with the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-completion</span> <span class="pre">&gt;</span> <span class="pre">Completion</span> <span class="pre">Keys</span></tt> preference in Wing. The same preferences group lets you specify whether to show the completer immediately or only after a certain number of characters or elapsed time, how to place the completion, and various other options.</p> <p>Here is what the completer looks like in action:</p> <img src="https://wingware.com/images/blog/auto-completion/auto-completer.gif" alt="Auto-Completion in Wing Pro" backrefs="" caption="Shown above: Using the auto-completer to enter new Python code in Wing Pro." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Using the auto-completer to enter new Python code in Wing Pro.</i></p><p>Notice that the auto-completer contains two columns of icons like <img src="https://wingware.com/images/doc/en/icons/wingide-autocomplete-package.png" alt="package" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="36" /> <img src="https://wingware.com/images/doc/en/icons/wingide-autocomplete-method-inherited.png" alt="inherited" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="36" /> and <img src="https://wingware.com/images/doc/en/icons/wingide-autocomplete-function.png" alt="function" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="36" /> that indicate the origin and type of the symbol. These are described in detail in <a class="reference" href="/doc/edit/completion-icons">Auto-completion Icons</a>.</p> <div class="section"> <h3 class="title-3">Auto-Import</h3> <p>In Wing 9.1 and later the auto-completer also contains suggestions for modules you may want to import for the code that you are writing. When these completions are selected, Wing enters the symbol for the selected import at the current position in the editor and also adds the necessary import statement at the top of your file:</p> <img src="https://wingware.com/images/blog/auto-completion/auto-import.gif" alt="Auto-importing in Wing Pro" backrefs="" caption="Shown above: Using the auto-completer to enter code and new import statements simultaneously." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Using the auto-completer to enter code and new import statements simultaneously.</i></p><p>The <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-completion</span> <span class="pre">&gt;</span> <span class="pre">Python</span> <span class="pre">Auto-Imports</span></tt> preference controls whether to always show auto-imports, show them only on request, or to hide them entirely from the completer. See also the <a class="reference" href="/doc/refactoring/imports-tool">Imports</a> tool.</p> </div> <div class="section"> <h3 class="title-3">Snippets</h3> <p>The completer also offers code snippets appropriate for the current context. These are indicated with the <img src="https://wingware.com/images/doc/en/icons/wingide-autocomplete-snippet.png" alt="snippet" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="36" /> scissors icon. The default set of snippets that come with Wing Pro may be viewed and altered in the <tt class="literal"><span class="pre">Snippets</span></tt> tool in the <tt class="literal"><span class="pre">Tools</span></tt> menu.</p> <p>Here is an example of entering snippets with the auto-completer, using the <tt class="literal"><span class="pre">Tab</span></tt> key to move between and fill out fields in the snippets:</p> <img src="https://wingware.com/images/blog/auto-completion/snippets.gif" alt="Auto-completing snippets in Wing Pro" backrefs="" caption="Shown above: Using the auto-completer to enter code snippets for a class, a method, and a nested definition, showing how snippets can take different forms depending on their context in the code." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Using the auto-completer to enter code snippets for a class, a method, and a nested definition, showing how snippets can take different forms depending on their context in the code.</i></p><p>See the <a class="reference" href="/doc/edit/snippets">Code Snippets</a> documentation for more information.</p> <br> <br><p>That's it for now! We'll be back next week with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> </div> https://wingware.com/hints/auto-completionThu, 08 Jun 2023 01:00:00 GMTTurbo Completion Mode in Wing Prohttps://wingware.com/hints/turbo-completion<p>In this issue of <a class="reference" href="/hints">Wing Tips</a> we look at how to use Wing Pro's turbo completion mode for Python. Auto-completion normally requires pressing a completion key, as configured by the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-completion</span> <span class="pre">&gt;</span> <span class="pre">Completion</span> <span class="pre">Keys</span></tt> preference, before a completion is entered into the editor.</p> <p>Wing Pro also provides a <tt class="literal"><span class="pre">Python</span> <span class="pre">Turbo</span> <span class="pre">Mode</span></tt> for auto-completion, where completion occurs on any key that cannot be part of a symbol. This allows you to type just enough of a symbol until it is selected in the completer, then move right on to typing the code that follows that symbol. It takes some getting used to, but it can greatly reduce typing once you become comfortable with it.</p> <p>The following example shows the code that can be produced simply by typing the characters <tt class="literal"><span class="pre">p=x.p.e.P(</span></tt> without pressing any completion keys:</p> <img src="https://wingware.com/images/blog/turbo-completion/turbo-completion.gif" alt="/images/blog/turbo-completion/turbo-completion.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" width="800px" /><p>This particular case requires only a single character to match each symbol in the auto-completer. In a more cluttered name space, it may take more characters to match the desired symbol, but in many cases two or three characters is all that is needed before you can move on to the next part of the expression you are trying to type.</p> <p>Notice that turbo mode distinguishes between contexts where a new symbol may be defined and those where an existing symbol must be used. For example, if you type <tt class="literal"><span class="pre">c</span></tt> followed by <tt class="literal"><span class="pre">=</span></tt> on a new line, Wing knows that the <tt class="literal"><span class="pre">=</span></tt> indicates you may be defining a new symbol and does not place the current selection from the auto-completer. When you do want completion to occur in a defining context, you can press <tt class="literal"><span class="pre">Tab</span></tt> or another completion key.</p> <p>In a context where you are trying to type something other than what is in the completer, you can press <tt class="literal"><span class="pre">Ctrl</span></tt>, <tt class="literal"><span class="pre">Alt</span></tt> or <tt class="literal"><span class="pre">Command</span></tt> briefly by itself to hide the auto-completer and thus disable turbo-completion until you type more symbol characters and the completer is displayed once again.</p> <p>Turbo completion is enabled with the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-completion</span> <span class="pre">&gt;</span> <span class="pre">Python</span> <span class="pre">Turbo</span> <span class="pre">Mode</span></tt> preference in Wing Pro.</p> <br> <br><p>That's it for now! We'll be back next week with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> https://wingware.com/hints/turbo-completionWed, 19 Jan 2022 01:00:00 GMTDebug Python Code Run by Docker Compose with Wing Prohttps://wingware.com/hints/docker-compose<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to configure Docker Compose so that Python code running on selected container services can be debugged with <a class="reference" href="https://wingware.com/downloads/wing-pro">Wing Pro</a>. This makes it easy to develop and debug containerized applications written in Python.</p> <div class="section"> <h3 class="title-3">Getting Started</h3> <p>Before you can work with Docker Compose you will need to download and install it and then create a working test cluster. See <a class="reference" href="https://docs.docker.com/compose/install/">Install Docker Compose</a> for details.</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">Configuration</h3> <p>To configure Wing to use <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. After selecting your source directory, choose <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Python</span></tt> on the second dialog page, and then select <tt class="literal"><span class="pre">Cluster</span></tt>:</p> <img src="https://wingware.com/images/blog/docker-compose/python-executable.png" alt="/images/blog/docker-compose/python-executable.png" backrefs="" class="doc-image" dupnames="" height="246px" ids="" names="" width="686px" /><p>Next create a new cluster configuration by pressing the <tt class="literal"><span class="pre">New</span></tt> button. This displays the cluster configuration dialog. You will need to enter an identifier to use within Wing and point it at the <tt class="literal"><span class="pre">docker-compose.yml</span></tt> file for the cluster. You will also need to select the main service to use as the default place to run your <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and unit test processes:</p> <img src="https://wingware.com/images/blog/docker-compose/cluster-config.png" alt="/images/blog/docker-compose/cluster-config.png" backrefs="" class="doc-image" dupnames="" height="298px" ids="" names="" width="418px" /><p>Once you have created your cluster configuration, submit the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog to complete your project setup.</p> </div> <div class="section"> <h3 class="title-3">Working with the Cluster</h3> <p>You can now control your cluster from Wing's <tt class="literal"><span class="pre">Containers</span></tt> tool, found in the <tt class="literal"><span class="pre">Tools</span></tt> menu. This tool lists the services in your cluster and their status. You can right-click on items here or use the <tt class="literal"><span class="pre">Options</span></tt> menu to build, start, debug, and stop your cluster:</p> <img src="https://wingware.com/images/blog/docker-compose/containers-tool.png" alt="/images/blog/docker-compose/containers-tool.png" backrefs="" class="doc-image" dupnames="" height="389px" ids="" names="" width="467px" /><p>Debug processes, unit tests, Wing's integrated <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and <tt class="literal"><span class="pre">OS</span> <span class="pre">Commands</span></tt> can all be run in context of the cluster, or optionally instead within isolated containers that match the cluster configuration but run without launching the whole cluster.</p> <p>See <a class="reference" href="/doc/howtos/docker-compose">Using Wing Pro with Docker Compose</a> for more information working with clusters in Wing Pro.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/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, have any questions, or have topic suggestions for future Wing Tips!</p> </div> https://wingware.com/hints/docker-composeTue, 21 Sep 2021 01:00:00 GMTUsing Docker with Wing Pro 8https://wingware.com/hints/docker<p>Wing Pro 8 significantly improved support for working with Python code that runs on containers like those provided by <a class="reference" href="https://www.docker.com/">Docker</a>, making it easier to configure projects that use Docker, and adding support for creating new Docker environments during project creation.</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">Project Configuration</h3> <p>You can either create a new Docker container along with a new Wing project or use an existing container configuration.</p> <p>In order to experiment with Docker, the easier of these two options is to create a new Docker container along with your project. To do this, choose <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 or create a source directory, and then on the second dialog screen choose <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Environment</span></tt> with environment type <tt class="literal"><span class="pre">Docker</span></tt> and <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Container</span></tt>. You should be able to use the default values entered for <tt class="literal"><span class="pre">Image</span> <span class="pre">ID</span></tt>, <tt class="literal"><span class="pre">Host-side</span> <span class="pre">Directory</span></tt>, and <tt class="literal"><span class="pre">Container-side</span> <span class="pre">Directory</span></tt> and simply go ahead with the environment and project creation by pressing <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt>:</p> <img src="https://wingware.com/images/blog/docker/create-new.png" alt="/images/blog/docker/create-new.png" backrefs="" class="doc-image" dupnames="" height="425px" ids="" names="" width="694px" /><p>If you want to use an existing Docker container configuration instead, create a new project with <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu, select or create a source directory, and then on the second dialog page select <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Environment</span></tt> with environment type <tt class="literal"><span class="pre">Docker</span></tt> and <tt class="literal"><span class="pre">With</span> <span class="pre">Existing</span> <span class="pre">Container</span></tt>. You will need to enter at least the container image and host-to-container file mapping. In most cases, selecting a <tt class="literal"><span class="pre">Dockerfile</span></tt> is easier than entering and image ID, since this also reads the host to container file mapping from the <tt class="literal"><span class="pre">Dockerfile</span></tt>:</p> <img src="https://wingware.com/images/blog/docker/use-existing.png" alt="/images/blog/docker/use-existing.png" backrefs="" class="doc-image" dupnames="" height="657px" ids="" names="" width="684px" /><p>Both of these options create a new container configuration and set up <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in your new project's <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> to use that container. You can make later changes to your configuration from there.</p> <p>If you created a new Docker container, it will be built in the <tt class="literal"><span class="pre">Containers</span></tt> tool, which is available in Wing's <tt class="literal"><span class="pre">Tools</span></tt> menu. The container won't be ready for use until that process completes. This may take some time if container images are being downloaded.</p> </div> <div class="section"> <h3 class="title-3">How it Works</h3> <p>Once your project setup is complete and the Docker container has been built, Wing will run debug processes, unit tests, and the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> on an instance of the selected container. Filenames are mapped automatically between the local and container-side copy of files. The debugger will display the local file even though the container's copy of the file is being executed.</p> <p>OS Commands can optionally run commands on the container or on the local host. This is controlled by toggling the <tt class="literal"><span class="pre">Run</span> <span class="pre">in</span> <span class="pre">Container</span></tt> option in the <tt class="literal"><span class="pre">OS</span> <span class="pre">Command</span></tt> configuration.</p> <p>Note that each debug process, each unit test run, and each instance of the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> creates its own independent instance of the container.</p> </div> <div class="section"> <h3 class="title-3">Further Reading</h3> <p>For more detailed instructions for setting up Wing Pro with Docker, see <a class="reference" href="/doc/howtos/docker">Using Wing Pro with Docker</a>.</p> <p>For more information on Wing's support for containers in general, see <a class="reference" href="/doc/proj/container-intro">Working with Containers and Clusters</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/dockerMon, 13 Sep 2021 01:00:00 GMTPython Package Management in Wing Python IDEhttps://wingware.com/hints/packages<p>Last time we looked at how to configure and create Python environments from Wing Pro. In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we'll take a look at managing your pip, Poetry, pipenv, or conda Python environment from Wing Pro's <tt class="literal"><span class="pre">Packages</span></tt> tool.</p> <div class="section"> <h3 class="title-3">Prerequisites</h3> <p>Wing Pro's <tt class="literal"><span class="pre">Packages</span></tt> tool (in the <tt class="literal"><span class="pre">Tools</span></tt> menu) can work with Python environments that are managed by pip, Poetry, pipenv, or conda. Regardless of which one is used, Wing assumes that pip is available in your selected Python installation. This is almost always the case in modern Python versions, or use <a class="reference" href="https://github.com/pypa/get-pip">getpip.py</a> to install it.</p> <p>Before trying Wing's package management features, you will want to set up a new project with a new virtualenv, Poetry, pipenv, or conda environment and save the project to the top level of your source directory. This way you can experiment with the <tt class="literal"><span class="pre">Packages</span></tt> tool without altering one of your Python environments unexpectedly.</p> <div class="note"> Conda package management will only work from Wing if the base Anaconda installation can be found. See <a class="reference" href="/doc/packages/conda">Package Management with conda</a> for details.</div> </div> <div class="section"> <h3 class="title-3">Viewing Packages</h3> <p>Once your project is saved, Wing should auto-detect which package manager is in use in the Python environment you selected for the project and determine whether a <tt class="literal"><span class="pre">requirements.txt</span></tt> file is in use. A summary of the found Python environment is shown in the <tt class="literal"><span class="pre">Packages</span></tt> tool, along with a list of packages installed into that environment:</p> <img src="https://wingware.com/images/blog/packages/packages.png" alt="/images/blog/packages/packages.png" backrefs="" class="doc-image" dupnames="" height="534px" ids="" names="" width="622px" /></div> <div class="section"> <h3 class="title-3">Managing Packages</h3> <p>To install new packages into your environment, use <tt class="literal"><span class="pre">Install</span> <span class="pre">New</span> <span class="pre">Packages</span></tt> in the <tt class="literal"><span class="pre">Packages</span></tt> tool's <tt class="literal"><span class="pre">Options</span></tt> menu:</p> <img src="https://wingware.com/images/blog/packages/install.png" alt="/images/blog/packages/install.png" backrefs="" class="doc-image" dupnames="" height="202px" ids="" names="" width="383px" /><p>You can remove, update, or set a specific package version by right-clicking on the packages list:</p> <img src="https://wingware.com/images/blog/packages/right-click.png" alt="/images/blog/packages/right-click.png" backrefs="" class="doc-image" dupnames="" height="298px" ids="" names="" width="509px" /><p>Wing runs the appropriate package management operations, updates the package list, and displays any output from the package management command in a console that may be viewed with <tt class="literal"><span class="pre">Show</span> <span class="pre">Console</span></tt> in the <tt class="literal"><span class="pre">Packages</span></tt> tool's <tt class="literal"><span class="pre">Options</span></tt> menu.</p> </div> <div class="section"> <h3 class="title-3">Updating requirements.txt</h3> <p>If you are using pip or conda, Wing can automatically update a <tt class="literal"><span class="pre">requirements.txt</span></tt> that is located in the same directory as your project file or in the <tt class="literal"><span class="pre">Project</span> <span class="pre">Home</span> <span class="pre">Directory</span></tt> configured under the <tt class="literal"><span class="pre">Options</span></tt> tab of <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>.</p> <p>A new <tt class="literal"><span class="pre">requirements.txt</span></tt> file may be created from your current Python environment with <tt class="literal"><span class="pre">Initialize</span> <span class="pre">requirements.txt</span></tt> from the <tt class="literal"><span class="pre">Options</span></tt> menu and later updated with <tt class="literal"><span class="pre">Freeze</span> <span class="pre">to</span> <span class="pre">requirements.txt</span></tt>. If the <tt class="literal"><span class="pre">Auto-Update</span> <span class="pre">requirements.txt</span></tt> item is checked in the <tt class="literal"><span class="pre">Options</span></tt> menu, then the file will automatically be updated after all package management operations run from Wing:</p> <img src="https://wingware.com/images/blog/packages/auto-update.png" alt="/images/blog/packages/auto-update.png" backrefs="" class="doc-image" dupnames="" height="530px" ids="" names="" width="383px" /><p>From here you can also set up your Python environment based on an existing <tt class="literal"><span class="pre">requirements.txt</span></tt> file, with <tt class="literal"><span class="pre">Install</span> <span class="pre">Missing</span> <span class="pre">Packages</span></tt> and <tt class="literal"><span class="pre">Remove</span> <span class="pre">Unused</span> <span class="pre">Packages</span></tt>. This is useful the first time you check out a code base on a new machine, in order to get your Python environment set up quickly.</p> <div class="section"> <h4 class="title-4">Poetry</h4> <p>If you are using Poetry, Wing defers to Poetry to keep its package management files up to date as you issue package management commands. You can however refresh the <tt class="literal"><span class="pre">Poetry.lock</span></tt> file from the <tt class="literal"><span class="pre">Packages</span></tt> tool's <tt class="literal"><span class="pre">Options</span></tt> menu and <tt class="literal"><span class="pre">Install</span> <span class="pre">Missing</span> <span class="pre">Packages</span></tt> can be used to initialize a Poetry environment from <tt class="literal"><span class="pre">Poetry.lock</span></tt> on a new development machine.</p> </div> <div class="section"> <h4 class="title-4">Pipenv</h4> <p>Similarly, if you are using pipenv, <tt class="literal"><span class="pre">Pipfile</span></tt> and <tt class="literal"><span class="pre">Pipfile.lock</span></tt> are used instead of <tt class="literal"><span class="pre">requirements.txt</span></tt>. Wing defers to pipenv to keep the <tt class="literal"><span class="pre">Pipfile</span></tt> up to date as you issue package management commands. You can however refresh the <tt class="literal"><span class="pre">Pipfile.lock</span></tt> file from the <tt class="literal"><span class="pre">Packages</span></tt> tool's <tt class="literal"><span class="pre">Options</span></tt> menu and <tt class="literal"><span class="pre">Install</span> <span class="pre">Missing</span> <span class="pre">Packages</span></tt> can be used to initialize a pipenv environment from <tt class="literal"><span class="pre">Pipfile.lock</span></tt> on a new development machine.</p> </div> </div> <div class="section"> <h3 class="title-3">Conclusion</h3> <p>In most cases, these are all the package management operations you will need in order to set up and manage your Python environment on each development machine.</p> <p>See the <a class="reference" href="/doc/packages/intro">Package Manager</a> documentation for a detailed description of all the available package management features and options. This also describes the quirks of each package management system, some of which you may need to understand in order to use them successfully with Wing.</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/packagesSun, 12 Sep 2021 01:00:00 GMTUsing virtualenv, Poetry, pipenv, and Anaconda environments with Wing Python IDEhttps://wingware.com/hints/environments<p>Last time we looked at how to create projects in Wing. In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> let's look more closely at how to configure your project to use or create Python environments managed by virtualenv, Poetry, pipenv, or Anaconda.</p> <div class="section"> <h3 class="title-3">Configuring an Existing Project</h3> <p>For an existing Wing project, you can specify an environment as 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> (from the <tt class="literal"><span class="pre">Project</span></tt> menu) in one of two ways:</p> <p><strong>(1)</strong> Select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> and enter the full path to the environments activation script. This is the <tt class="literal"><span class="pre">activate</span></tt> or <tt class="literal"><span class="pre">activate.bat</span></tt> associated with the environment:</p> <img src="https://wingware.com/images/blog/environments/properties.png" alt="/images/blog/environments/properties.png" backrefs="" class="doc-image" dupnames="" height="383px" ids="" names="" width="658px" /><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/environments/recent-envs.png" alt="/images/blog/environments/recent-envs.png" backrefs="" class="doc-image" dupnames="" height="535px" ids="" names="" width="446px" /><p><strong>or (2)</strong> Select <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and enter the full path to the environment's <tt class="literal"><span class="pre">python</span></tt> or <tt class="literal"><span class="pre">python.exe</span></tt>. This executable both activates the env and runs Python, so all the code Wing launches will run in the environment:</p> <img src="https://wingware.com/images/blog/environments/command-line.png" alt="/images/blog/environments/command-line.png" backrefs="" class="doc-image" dupnames="" height="75px" ids="" names="" width="619px" /><p>When in doubt about which path to use, run your environment outside of Wing and inspect 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>. That is the value you want to use.</p> <p>Activated environments 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 a New Project</h3> <p>There are two options available for environments, when starting a new project from the <tt class="literal"><span class="pre">Project</span></tt> menu: (1) Creating a new enviroment and new Wing project at the same time, or (2) Creating a new Wing project that uses an existing environment.</p> <div class="section"> <h4 class="title-4">Creating a New Environment</h4> <p>To create a new environment 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, select or create your source directory, and press <tt class="literal"><span class="pre">Next</span></tt>. On the second screen, choose <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Environment</span></tt> and select the type of environment you wish to create. You will then need to enter the name for the environment, select a parent directory, 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/environments/new-project-new.png" alt="/images/blog/environments/new-project-new.png" backrefs="" class="doc-image" dupnames="" height="432px" ids="" names="" width="600px" /><p>The options to enter vary slightly by type of environment being created. For example, Poetry and pipenv use the selected source directory and does not need environment name and parent directory. Also, Anaconda environments require that you install at least one package.</p> <p>When you press <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt>, Wing will create the 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> </div> <div class="section"> <h4 class="title-4">Using an Existing Environment</h4> <p>To use an existing virtualenv or Anaconda environment, 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, select or create your source directory, and press <tt class="literal"><span class="pre">Next</span></tt>. On the second screen, select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Python</span></tt> and select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> under <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt>. You can then select a recent or found environment from the drop down or manually enter your activation command:</p> <img src="https://wingware.com/images/blog/environments/new-project-existing.png" alt="/images/blog/environments/new-project-existing.png" backrefs="" class="doc-image" dupnames="" height="246px" ids="" names="" width="570px" /><p>To use an existing Poetry or pipenv directory, you instead simply select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> in the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog and Wing will auto-detect that this directory already contains a Poetry or pipenv environment to use with the project:</p> <img src="https://wingware.com/images/blog/environments/new-project-existing-pipenv.png" alt="/images/blog/environments/new-project-existing-pipenv.png" backrefs="" class="doc-image" dupnames="" height="281px" ids="" names="" width="471px" /><p>In this case, Wing immediately displays the <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt> button and will use that environment with your project.</p> </div> </div> <div class="section"> <h3 class="title-3">Notes</h3> <p>Once your project has been set up, you can use the <tt class="literal"><span class="pre">Packages</span></tt> tool in the <tt class="literal"><span class="pre">Tools</span></tt> menu to add, remove, or upgrade packages in your Python environment. We'll describe this in more details the next Wing Tip, or see <a class="reference" href="/doc/packages/intro">Package Manager</a> for details.</p> <p>For some additional details on each type of environment, see <a class="reference" href="/doc/howtos/virtualenv">Using Wing with virtualenv</a>, <a class="reference" href="/doc/howtos/pipenv">Using Wing with pipenv</a>, <a class="reference" href="/doc/howtos/poetry">Using Wing with Poetry</a>, and <a class="reference" href="/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/environmentsSat, 11 Sep 2021 01:00:00 GMTCreating a Project for an Existing Code Basehttps://wingware.com/hints/create-project<p>Wing 8 introduced some improvements and new capabilities for the project creation process. In this <a class="reference" href="/hints">Wing Tip</a>, we'll take a look at the options available during project creation in Wing Pro.</p> <div class="note"> Note that Wing Personal also has the concept of projects, but omits support for remote development, cloning from revision control repositories, creating Python environments with the project, and support for specific third party packages and tools like Django, Flask, Jupyter, Docker, Poetry, pipenv, and others. As a result, many of the options described below are not available in Wing Personal.</div> <div class="section"> <h3 class="title-3">Selecting Directory and Project Type</h3> <p>New projects are created with <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. This displays a dialog that allows you to select the source code to use with the new project and to select or configure the Python environment you plan to use:</p> <img src="https://wingware.com/images/blog/create-project/new-project.png" alt="/images/blog/create-project/new-project.png" backrefs="" class="doc-image" dupnames="" height="279px" ids="" names="" width="525px" /><p>From here it's possible to create an entirely blank project, which you can configure later, or you can set up your project with an existing source directory or create a new source directory along with the project.</p> <p>Note that you can create a project for remote development here, but for now ignore this option and leave <tt class="literal"><span class="pre">Host</span></tt> set to <tt class="literal"><span class="pre">Local</span> <span class="pre">Host</span></tt>. We'll talk about remote development in future Wing Tips.</p> <div class="section"> <h4 class="title-4">Using an Existing Directory</h4> <p>If you already have a Python code base you want to use with Wing, select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> and choose the directory to use:</p> <img src="https://wingware.com/images/blog/create-project/existing-dir.png" alt="/images/blog/create-project/existing-dir.png" backrefs="" class="doc-image" dupnames="" height="370px" ids="" names="" width="525px" /></div> <div class="section"> <h4 class="title-4">Creating a New Directory</h4> <p>If you are starting a new project from scratch, select <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Directory</span></tt> and enter the directory name, parent directory, optionally select a revision control repository to clone into the new directory (for example, by entering a Github repository url), and select the unit testing framework that you plan to use, if any:</p> <img src="https://wingware.com/images/blog/create-project/new-dir.png" alt="/images/blog/create-project/new-dir.png" backrefs="" class="doc-image" dupnames="" height="449px" ids="" names="" width="525px" /></div> <div class="section"> <h4 class="title-4">Project Type</h4> <p>Whether you're using an existing directory or creating a new one, you will be able to specify a <tt class="literal"><span class="pre">Project</span> <span class="pre">Type</span></tt> from this page of the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog. If you are using a Python package listed in the <tt class="literal"><span class="pre">Project</span> <span class="pre">Type</span></tt> drop down, select that also. This tells Wing how to configure your project to work properly with your code:</p> <img src="https://wingware.com/images/blog/create-project/project-type.png" alt="/images/blog/create-project/project-type.png" backrefs="" class="doc-image" dupnames="" height="140px" ids="" names="" width="323px" /><p>If your project type is not listed, leave this value set to <tt class="literal"><span class="pre">Custom</span></tt>. In this case, you can opt to ask Wing to configure your project to allow debug processes to be launched from outside of the IDE, for example by a web server or another app. If this will be the case, check on the <tt class="literal"><span class="pre">Use</span> <span class="pre">wingdbstub</span> <span class="pre">for</span> <span class="pre">Debugging</span></tt> option. If you don't yet know how you will launch debug, leave this unchecked. You can always configure this later.</p> </div> </div> <div class="section"> <h3 class="title-3">Selecting a Python Environment</h3> <p>At this point, if you used an existing source directory, Wing looks in the directory for a Python environment managed by Poetry, pipenv, or virtualenv and pip. If it finds one, it will use that with the new project and you can simply press the <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt> button.</p> <p>Otherwise, press <tt class="literal"><span class="pre">Next</span></tt> to select or configure a Python environment for the project.</p> <p>You can then either use an existing Python environment with your project or create a new one. If you already have a Python environment to use, select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Python</span></tt>:</p> <img src="https://wingware.com/images/blog/create-project/existing-env.png" alt="/images/blog/create-project/existing-env.png" backrefs="" class="doc-image" dupnames="" height="250px" ids="" names="" width="686px" /><p>You can specify the Python to use by selecting the default Python, entering a custom command line that invokes Python, selecting an activated environment, or setting up a container or cluster environment. The latter two options will be described in future Wing Tips.</p> <p>The <tt class="literal"><span class="pre">Use</span> <span class="pre">default</span></tt> option causes Wing to use the Python that is run from the command line or the latest found version if Python is not on the <tt class="literal"><span class="pre">PATH</span></tt>.</p> <p><tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> is used to specify the full path command line that invokes Python. For <tt class="literal"><span class="pre">virtualenv</span></tt>, <tt class="literal"><span class="pre">Poetry</span></tt>, and <tt class="literal"><span class="pre">pipenv</span></tt> this can be the <tt class="literal"><span class="pre">python</span></tt> or <tt class="literal"><span class="pre">python.exe</span></tt> executable that is found in the environment.</p> <p><tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> is used to specify the activation command for an existing Python environment. Wing runs this command and then starts Python within the env.</p> <p>Both the <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> options provide a drop down that lists all the found Python installations and environments Wing was able to find on your system.</p> </div> <div class="section"> <h3 class="title-3">Creating a Python Environment</h3> <p>Another option is to create a new Python environment along with your project. This is done by selecting <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Environment</span></tt> on the second <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> screen and then choosing the type of environment to create:</p> <img src="https://wingware.com/images/blog/create-project/new-env.png" alt="/images/blog/create-project/new-env.png" backrefs="" class="doc-image" dupnames="" height="427px" ids="" names="" width="653px" /><p>Wing can create environments managed by Anaconda, Docker, Poetry, pipenv, and virtualenv with pip. The options entered for each of these differ. We'll describe this in more detail in the next Wing Tip or take a look at these links for more information: <a class="reference" href="/doc/howtos/poetry">Poetry</a> | <a class="reference" href="/doc/howtos/anaconda">Anaconda</a> | <a class="reference" href="/doc/howtos/docker">Docker</a> | <a class="reference" href="/doc/howtos/pipenv">pipenv</a> | <a class="reference" href="/doc/howtos/virtualenv">virtualenv</a></p> </div> <div class="section"> <h3 class="title-3">Finishing Up</h3> <p>Once your Python environment has been selected or configured, press <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt> and Wing will show a progress dialog as it creates and configures everything.</p> <p>As part of this process, Wing saves the project automatically if you created a new source directory. Otherwise, you will need to save the project, which is typically best done to the top level of your project source tree.</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/create-projectFri, 10 Sep 2021 01:00:00 GMTMultiple Selections in Wing Python IDEhttps://wingware.com/hints/multiselection<p>In this issue of <a class="reference" href="/hints">Wing Tips</a> we look at how to use multiple concurrent selections in Wing's editor. These can be used to replace all occurrences of some text or to apply the same edits to any number of selections, for example surround them all with quotes or remove common surrounding characters. Multiple selections can be created from the keyboard, from the mouse, or by using commands that select all occurrences of some text found within a selected code.</p> <div class="section"> <h3 class="title-3">Creating Multiple Selections</h3> <p>The most common way to make multiple selections is to select a range of text in Wing's editor and then add other occurrences of the same text with <tt class="literal"><span class="pre">Add</span> <span class="pre">Selection</span> <span class="pre">for</span> <span class="pre">Next</span> <span class="pre">Occurrence</span></tt> in the <tt class="literal"><span class="pre">Edit</span> <span class="pre">&gt;</span> <span class="pre">Multiple</span> <span class="pre">Selections</span></tt> menu. The default key binding for this is <tt class="literal"><span class="pre">Ctrl-D</span></tt>, or <tt class="literal"><span class="pre">Command-D</span></tt> on macOS, and <tt class="literal"><span class="pre">Ctrl-&gt;</span></tt> in the emacs keyboard personality.</p> <p>Another way to add selections is to click on the multi-selection toolbar item <img src="https://wingware.com/images/doc/en/icons/wingide-multiple-selections.png" alt="toolbaritem" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" />. This menu includes items to select all occurrences in a file, class, function/method, or block of code:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-menu.png" alt="/images/blog/multi-selection/multi-select-menu.png" backrefs="" class="doc-image" dupnames="" height="333px" ids="" names="" width="335px" /></div> <div class="section"> <h3 class="title-3">Editing Selections</h3> <p>Once the selections are made your edits will be applied to all of them in the same way, as in the following example which replaces all occurrences of the word &quot;stocks&quot; with &quot;trades&quot;:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-1.gif" alt="/images/blog/multi-selection/multi-select-1.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Edits applied to all selections may include cursor movement, pasting, and other editing actions. For example selecting a number of commas, pressing the right arrow key, and then <tt class="literal"><span class="pre">Space</span></tt> adds a space after all the commas:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-2.gif" alt="/images/blog/multi-selection/multi-select-2.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">Multi-Selecting with the Mouse</h3> <p>Multiple selections can also be made by clicking or double-clicking the mouse while holding <tt class="literal"><span class="pre">Ctrl-Alt</span></tt> (or <tt class="literal"><span class="pre">Option-Command</span></tt> on macOS). This allows selecting ranges that don't necessarily contain the same text:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-3.gif" alt="/images/blog/multi-selection/multi-select-3.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">Omitting Selections</h3> <p>By default, Wing displays a floating window that enumerates the selection made. You can omit selections from here by moving the mouse over an item and clicking on the red <tt class="literal"><span class="pre">X</span></tt> icon that appears over it. Edits made subsequently are applied only to the selections that remain:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-4.gif" alt="/images/blog/multi-selection/multi-select-4.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">Configuration Options</h3> <p>Whether occurrences used for multi-selection match any text or only whole words, and whether they are case sensitive, may be controlled from the <tt class="literal"><span class="pre">Edit</span> <span class="pre">&gt;</span> <span class="pre">Multiple</span> <span class="pre">Selections</span></tt> menu or the multi-selection toolbar item <img src="https://wingware.com/images/doc/en/icons/wingide-multiple-selections.png" alt="toolbaritem" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" />.</p> <p>The multi-selection popup window can also be entirely enabled or disabled from here, with the <tt class="literal"><span class="pre">Configure</span> <span class="pre">Selections</span> <span class="pre">Window</span></tt> item.</p> <br> <br><p>That's it for now! We'll be back next week with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> </div> https://wingware.com/hints/multiselectionThu, 01 Oct 2020 01:00:00 GMTExtend Microsoft Excel with Python Using Wing and PyXLLhttps://wingware.com/hints/pyxll<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to use Wing and <a class="reference" href="https://www.pyxll.com">PyXLL</a> to develop and debug Microsoft Excel add-ins that are written in Python. PyXLL is a commercial product that embeds Python into Microsoft Excel on Windows. It allows you to expose Python code to Excel as worksheet functions, macros, menus, and ribbon toolbars.</p> <div class="section"> <h3 class="title-3">Install PyXLL</h3> <p>Before getting started you will need to install Microsoft Excel, <a class="reference" href="https://python.org/">Python</a> or <a class="reference" href="https://www.anaconda.com">Anaconda</a>, <a class="reference" href="https://wingware.com/">Wing</a>, and <a class="reference" href="https://www.pyxll.com/download.html">PyXLL</a> if you don't already have them.</p> <p><strong>Important:</strong> Excel, PyXLL and Python all need to be either 32 bit or 64 bit and can't be mixed. To find out what version of Excel you have see <a class="reference" href="https://support.pyxll.com/hc/en-gb/articles/360036821613-Do-I-have-32-bit-or-64-bit-Excel-">Do I have 32 bit or 64 bit Excel?</a> You will also need to match the version of PyXLL that you download to your Python version.</p> <p>To install PyXLL, unzip the download and then edit the included <tt class="literal"><span class="pre">pyxll.cfg</span></tt> and set <tt class="literal"><span class="pre">executable</span></tt> to the full path of your Python executable. This can be a <tt class="literal"><span class="pre">python.exe</span></tt> from a virtualenv or conda env, or a base Python install. For example:</p> <pre class="literal-block"> [PYTHON] executable = C:\Users\joebloggs\Anaconda\envs\py38\python.exe </pre> <p>Next, install the PyXLL add-in into Excel. To do that, open Excel and select the <tt class="literal"><span class="pre">File</span></tt> menu. Navigate to <tt class="literal"><span class="pre">Options</span></tt>, then <tt class="literal"><span class="pre">Add-Ins</span></tt>, and click the <tt class="literal"><span class="pre">Manage</span> <span class="pre">Excel</span> <span class="pre">Add-Ins</span></tt> button. Select <tt class="literal"><span class="pre">Browse</span></tt>, navigate to the folder where you unzipped the PyXLL download, and select the <tt class="literal"><span class="pre">pyxll.xll</span></tt> file. If Excel asks if you want to copy the add-in to your add-ins folder, select <tt class="literal"><span class="pre">No</span></tt> as you want to leave it where it is. The PyXLL add-in should now appear in your list of loaded add-ins.</p> <p>If you're having trouble installing the add-in, check the PyXLL log file located in the <tt class="literal"><span class="pre">logs</span></tt> folder where you unzipped PyXLL. You can change the log level to <tt class="literal"><span class="pre">debug</span></tt> in your <tt class="literal"><span class="pre">pyxll.cfg</span></tt> file to obtain more detailed logging. If you get stuck contact the <a class="reference" href="https://www.pyxll.com/contact.html">PyXLL support team</a> who will help you get started.</p> <p>You can also find more detailed installation instructions in <a class="reference" href="https://www.pyxll.com/docs/userguide/installation.html">Installing the PyXLL Excel Add-In</a>.</p> </div> <div class="section"> <h3 class="title-3">Create a Wing Project</h3> <p>Next create a new project in Wing with <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. Select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> and select the directory where you installed PyXLL and set <tt class="literal"><span class="pre">Project</span> <span class="pre">Type</span></tt> to <tt class="literal"><span class="pre">PyXLL</span></tt>.</p> <p>After pressing <tt class="literal"><span class="pre">Next</span></tt>, select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Python</span></tt>, set <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and enter the same Python used as the <tt class="literal"><span class="pre">executable</span></tt> in <tt class="literal"><span class="pre">pyxll.cfg</span></tt> above:</p> <img src="https://wingware.com/images/blog/pyxll/new-project.png" alt="/images/blog/pyxll/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="650px" /><p>Now you can submit the dialog and Wing will create and configure your new project.</p> </div> <div class="section"> <h3 class="title-3">Write an Excel Function With PyXLL</h3> <p>Before we look at setting up Wing's debugger, let's write an Excel function to debug. This example uses pandas and numpy, so you will need to make sure those are installed into the Python you configured above. If you are using Anaconda, then you should already have them. In other cases, this can be done with pip. For example:</p> <pre class="literal-block"> C:\Users\joebloggs\Anaconda\envs\py38\python.exe -m pip install pandas numpy </pre> <p>Now create a Python module for your Excel function by creating a new directory on disk and placing a Python file into that directory, with the following contents:</p> <div class="python-highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pyxll</span> <span class="kn">import</span> <span class="n">xl_func</span> <span class="kn">import</span> <span class="nn">pandas</span> <span class="kn">as</span> <span class="nn">pd</span> <span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span> <span class="nd">@xl_func</span><span class="p">(</span><span class="s2">&quot;int, int: dataframe&lt;index=True&gt;&quot;</span><span class="p">,</span> <span class="n">auto_resize</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="k">def</span> <span class="nf">random_dataframe</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="p">):</span> <span class="sd">&quot;&quot;&quot;</span> <span class="sd"> Creates a DataFrame of random numbers.</span> <span class="sd"> :param rows: Number of rows to create the DataFrame with.</span> <span class="sd"> :param columns: Number of columns to create the DataFrame with.</span> <span class="sd"> &quot;&quot;&quot;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="p">)</span> <span class="n">column_names</span> <span class="o">=</span> <span class="p">[</span><span class="nb">chr</span><span class="p">(</span><span class="nb">ord</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">columns</span><span class="p">)]</span> <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">column_names</span><span class="p">)</span> <span class="k">return</span> <span class="n">df</span> </pre></div> <p>The directory and filenames can be anything, but in this example we'll use <tt class="literal"><span class="pre">C:\Users\joebloggs\Projects\PyXLL\src</span></tt> for the directory and <tt class="literal"><span class="pre">xlfuncs.py</span></tt> as the file name.</p> <p>Next update the <tt class="literal"><span class="pre">pythonpath</span></tt> and <tt class="literal"><span class="pre">modules</span></tt> setting in the same <tt class="literal"><span class="pre">pyxll.cfg</span></tt> file where you set <tt class="literal"><span class="pre">executable</span></tt> earlier:</p> <pre class="literal-block"> [PYTHON] pythonpath = C:\Users\joebloggs\Projects\PyXLL\src [PYXLL] modules = xlfuncs </pre> <p>Note that the entry under modules omits the <tt class="literal"><span class="pre">.py</span></tt> in the filename.</p> <p>Once this is done, reload the PyXLL add-in via the PyXLL ribbon tool bar or the add-ins menu in Excel, or restart Excel. PyXLL can also be configured to auto-reload after any change made to the Python code. See <a class="reference" href="https://www.pyxll.com/docs/userguide/reloading.html">Reloading</a> in the PyXLL guide for details.</p> <div class="section"> <h4 class="title-4">How it Works</h4> <p>As you may already have figured out, the example Excel function <tt class="literal"><span class="pre">random_dataframe</span></tt> given above creates a pandas <tt class="literal"><span class="pre">DataFrame</span></tt> containing random data, and returns that to Excel as an array function.</p> <p>The <tt class="literal"><span class="pre">&#64;xl_func</span></tt> decorator tells PyXLL to use it as an Excel worksheet function. The first argument to the decorator is an optional function signature. PyXLL uses this to determine how arguments and return values should be converted between the Excel and Python data types. The example here uses the <tt class="literal"><span class="pre">dataframe</span></tt> return type to tell PyXLL to expand the pandas <tt class="literal"><span class="pre">DataFrame</span></tt> to an array of values when returning to Excel, including the index. The <tt class="literal"><span class="pre">auto_resize</span></tt> option tells PyXLL that the Excel formula should be resized automatically to fit the size of the returned array.</p> <div class="note"> <strong>Tip:</strong> In order for Wing to recognise the <tt class="literal"><span class="pre">&#64;xl_func</span></tt> decorator as a valid defined symbol, you will need to install the <tt class="literal"><span class="pre">.whl</span></tt> file included in the PyXLL download using <tt class="literal"><span class="pre">pip</span> <span class="pre">install</span></tt> followed by the full path of the <tt class="literal"><span class="pre">.whl</span></tt> file. You can also invoke pip with the <tt class="literal"><span class="pre">-m</span></tt> command line argument for Python, as shown above for installation of pandas and numpy.</div> </div> </div> <div class="section"> <h3 class="title-3">Invoke the PyXLL Function</h3> <p>Now you should be able to call the <tt class="literal"><span class="pre">random_dataframe</span></tt> function from Excel by entering it as a formula in an Excel worksheet. This is done in the same way as Excel's standard functions by using <tt class="literal"><span class="pre">=</span></tt> followed by the function name, for example <tt class="literal"><span class="pre">=random_dataframe(10,</span> <span class="pre">10)</span></tt>:</p> <img src="https://wingware.com/images/blog/pyxll/random-dataframe.gif" alt="Enter random DataFrame into Excel" backrefs="" caption="Shown Above: Type &quot;=random_dataframe(10,10)&quot; and press Enter to insert a random DataFrame into Excel" class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown Above: Type "=random_dataframe(10,10)" and press Enter to insert a random DataFrame into Excel</i></p><p>For complete instructions on writing Excel worksheet functions in Python with PyXLL, please see <a class="reference" href="https://www.pyxll.com/docs/userguide/udfs/introduction.html">Worksheet Functions</a> in the PyXLL user guide.</p> </div> <div class="section"> <h3 class="title-3">Set up Wing's Debugger</h3> <p>To enable debugging, you need to tell Wing to accept connections from Python code running under Excel and then configure and load the debugger into Excel. To do this from the project you created earlier, click on the bug icon in the lower left of Wing's window, and check <tt class="literal"><span class="pre">Accept</span> <span class="pre">Debug</span> <span class="pre">Connections</span></tt>:</p> <img src="https://wingware.com/images/blog/pyxll/accept-debug-connections.jpg" alt="Accept Debug Connections" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Now hovering your mouse over the bug icon should show that Wing is listening for externally initiated debug connections on the local host:</p> <img src="https://wingware.com/images/blog/pyxll/listening-for-connections.jpg" alt="Listening for Connections" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>If Wing is not listening, it may be that it has not been allowed to do so by Windows. In that case, try restarting Wing so that Windows will prompt you to allow network connections.</p> <p>Next, find the <tt class="literal"><span class="pre">Install</span> <span class="pre">Directory</span></tt> listed in the <tt class="literal"><span class="pre">About</span></tt> box accessed from the <tt class="literal"><span class="pre">Help</span></tt> menu in Wing. Copy <tt class="literal"><span class="pre">wingdbstub.py</span></tt> from that directory to the directory that contains <tt class="literal"><span class="pre">xlfuncs.py</span></tt>.</p> <p>Then open your copy of <tt class="literal"><span class="pre">wingdbstub.py</span></tt> and make the following changes:</p> <blockquote> <div class="ordered-list"><ul><li><span class="bullet"> Make sure <tt class="literal"><span class="pre">WINGHOME</span></tt> is set to the full path of your Wing installation, where you just found <tt class="literal"><span class="pre">wingdbstub.py</span></tt>. This is usually set automatically during installation of the IDE.</span></li> <li><span class="bullet"> Change the value of <tt class="literal"><span class="pre">kEmbedded</span></tt> to <tt class="literal"><span class="pre">1</span></tt>. This alters some aspects of how code is debugged, to match the environment your Python code will be running in.</span></li> </ul></div></blockquote> <p>To get Excel to load Wing's debugger, add <tt class="literal"><span class="pre">wingdbstub</span></tt> to the modules list in your <tt class="literal"><span class="pre">pyxll.cfg</span></tt> file:</p> <pre class="literal-block"> [PYXLL] modules = wingdbstub xlfuncs </pre> <p>Finally, restart Excel or reload the PyXLL add-in. When the <tt class="literal"><span class="pre">wingdbstub</span></tt> module is loaded it will connect to Wing and the bug icon in the lower left of Wing's window will turn green, in order to let you know that the debugger is connected:</p> <img src="https://wingware.com/images/blog/pyxll/connected-to-excel.jpg" alt="Connected to Excel" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">Debugging Python Code Invoked from Excel</h3> <p>You can now step through the Python code running in Excel.</p> <p>To try it out, set a breakpoint in <tt class="literal"><span class="pre">xlfuncs.py</span></tt> by opening it in Wing and clicking on the leftmost margin next to the the line that reads <tt class="literal"><span class="pre">data</span> <span class="pre">=</span> <span class="pre">np.random.rand(rows,</span> <span class="pre">columns)</span></tt> within <tt class="literal"><span class="pre">random_dataframe</span></tt>. When you call the function from Excel, the debugger will stop on the breakpoint:</p> <img src="https://wingware.com/images/blog/pyxll/debugging-excel.gif" alt="Debugging Excel" backrefs="" caption="Shown Above: Enter &quot;random_dataframe(10,10)&quot; into Excel on the left, reach a breakpoint in Wing on the right, and step through code" class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown Above: Enter "random_dataframe(10,10)" into Excel on the left, reach a breakpoint in Wing on the right, and step through code</i></p><p>From here, you can inspect your debug process in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> (Wing Pro only) or <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> in Wing's <tt class="literal"><span class="pre">Tools</span></tt> menu, set other breakpoints or conditional breakpoints (Wing Pro only), step through code, and so forth. For more information on the capabilities of Wing's debugger, see the <a class="reference" href="/doc/howtos/quickstart">Debugger Quick Start</a> or the <tt class="literal"><span class="pre">Tutorial</span></tt> in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/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, have any questions, or have topic suggestions for future Wing Tips!</p> </div> https://wingware.com/hints/pyxllWed, 24 Jun 2020 01:00:00 GMTConfiguring Wing's Python Debugger for Your Code Basehttps://wingware.com/hints/debug-overview<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> provides a roadmap to the configuration options available for <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a>'s debugger, to make it easier to understand the available possibilities and how these can be applied to your development projects.</p> <p><strong>In short:</strong> Wing can develop and debug just about any kind of Python code, regardless of whether is resides locally or on a remote host, on a container or cluster, whether it's launched by the IDE from from the outside, and whether it is asynchronous, threaded, or runs in multiple processes. Read on for the details.</p> <div class="section"> <h3 class="title-3">Configuration Options</h3> <p>Broadly speaking there are six ways to configure Wing's debugger:</p> <p><strong>Local Stand-Alone Code</strong> -- Wing can debug stand-alone scripts and applications that run on your local machine and that are launched on demand from within Wing. This development approach can be used for anything that is convenient to launch from the IDE, including scripts, desktop apps, and most web frameworks. See the <a class="reference" href="/doc/debug/quick-start">Debugger Quick-Start</a> for a quick introduction to this simple case.</p> <p><strong>Remote Stand-Alone Code</strong> -- <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a> can also debug stand-alone code running on a remote host, virtual machine or device, in the same way as it debugs locally running code. Wing uses a remote agent launched by SSH in order to work directly with files stored on the remote host, as if Wing were itself running on that system. For details, see <a class="reference" href="/hints/remote-dev-2">Remote Development with Wing Pro</a>.</p> <p><strong>Container and Cluster Code</strong> -- <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a> can debug code that runs on a container like those hosted by Docker or LXC/LXD, or clusters hosted by Docker Compose. In this case, editing, version control, and search operate files stored on your local disk, but code is transparently executed and debugged in the context of a container instance. For details, see <a class="reference" href="https://wingware.com/doc/proj/container-intro">Working with Containers and Clusters</a>.</p> <p><strong>Local Externally Launched or Embedded Code</strong> -- Wing can debug locally running code that is launched by a web server or framework, embedded Python code that is used to script a larger application, and any other Python code that cannot be directly launched from the IDE. In this case, the code is started from outside of Wing and connects to the IDE by importing Wing's debugger. Debug can be controlled from the IDE and through an API accessible from the debug process. For details, see <a class="reference" href="/doc/debug/debugging-externally-launched-code">Debugging Externally Launched Code</a></p> <p><strong>Remote Externally Launched or Embedded Code</strong> -- <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a> can also debug externally launched or embedded code that is running on a remote system. In this case, Wing uses a remote agent to access the remote host via SSH and the debugged code imports Wing's debugger in order to connect back to the IDE through an automatically established reverse SSH tunnel. See <a class="reference" href="/doc/debug/remote-debugging">Debugging Externally Launched Remote Code</a> for brief instructions or <a class="reference" href="/doc/howtos/debugging-web-remote">Remote Web Development</a> for a more detailed guide.</p> <p><strong>Manually Configured Remote Debugging</strong> -- For remote hosts and devices that are not accessible through SSH, or where Wing's remote agent cannot be run, Wing provides a manual configuration option to make debugging on these systems possible. In this case, the device must be able to connect to the host where Wing is running via TCP/IP, and there must be some file sharing configuration so files are available both locally and on the remote system. In this approach, connectivity, file sharing, and other configuration needed to make debugging possible is accomplished entirely manually, so it can be tailored to unusual custom environments. For details, see <a class="reference" href="/doc/debug/manual-remote-debugging">Manually Configured Remote Debugging</a>.</p> </div> <div class="section"> <h3 class="title-3">VirtualEnv, Poetry, pipenv, and Anaconda Environments</h3> <p>In context of the above , Wing may be used with or without an environment created by <tt class="literal"><span class="pre">virtualenv</span></tt>, <tt class="literal"><span class="pre">Poetry</span></tt>, <tt class="literal"><span class="pre">pipenv</span></tt>, or Anaconda's <tt class="literal"><span class="pre">conda</span> <span class="pre">create</span></tt>.</p> <p>Environments can be created with your Wing project as described in <a class="reference" href="/doc/proj/creating-python-envs">Creating Python Environments</a>.</p> <p>Alternatively, environments may be selected after the fact. For local debugging, this is done by setting 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>. For remote debugging, it is set in the remote host configuration.</p> <p>For <tt class="literal"><span class="pre">virtualenv</span></tt>, <tt class="literal"><span class="pre">Poetry</span></tt>, and <tt class="literal"><span class="pre">pipenv</span></tt>, you can either set the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and enter the full path to the environment's Python, or you can select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> and enter the command that activates the environment. See <a class="reference" href="/doc/howtos/virtualenv">Using Wing with virtualenv</a>, <a class="reference" href="/doc/howtos/poetry">Using Wing with Poetry</a>, and <a class="reference" href="/doc/howtos/pipenv">Using Wing with pipenv</a> for details.</p> <p>For Anaconda environments, you must select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> and then choose the environment from the drop down list to the right of this field. See <a class="reference" href="/doc/howtos/anaconda">Using Wing with Anaconda</a> for details.</p> <div class="note"> If you are working with containers or clusters, Wing uses the environment set up and managed by the container. See <a class="reference" href="/doc/proj/container-intro">Working with Containers and Clusters</a>, <a class="reference" href="/doc/howtos/docker">Using Wing with Docker</a>, and <a class="reference" href="/doc/howtos/lxc">Using Wing with LXC/LXD</a> for details.</div> </div> <div class="section"> <h3 class="title-3">Specific Frameworks and Tools</h3> <p>Some frameworks and tools require some additional custom configuration to make them easy to work with in Wing. In addition to understanding the general options explained above, it is a good idea to seek out configuration details for the frameworks and tools that you use:</p> <div class="bullet-list"><ul><li><span class="bullet"> Wing's documentation contains configuration instructions for specific frameworks and tools such as <a class="reference" href="/doc/howtos/flask">Flask</a>, <a class="reference" href="/doc/howtos/django">Django</a>, <a class="reference" href="/doc/howtos/jupyter">Jupyter</a>, <a class="reference" href="/doc/howtos/wxpython">wxPython</a>, <a class="reference" href="/doc/howtos/pyqt">PyQt</a>, <a class="reference" href="/doc/howtos/blender">Blender</a>, <a class="reference" href="/doc/howtos/maya">Maya</a>, and <a class="reference" href="/doc/howtos">others</a>.</span></li> <li><span class="bullet"> There is also additional information available for specific kinds of remote development for <a class="reference" href="/doc/howtos/aws">AWS</a>, <a class="reference" href="/doc/howtos/docker">Docker</a>, <a class="reference" href="/doc/howtos/vagrant">Vagrant</a>, <a class="reference" href="/doc/howtos/wsl">Windows Subsystem for Linux</a>, <a class="reference" href="/doc/howtos/raspberry">Raspberry Pi</a>, and <a class="reference" href="/doc/howtos">others</a>.</span></li> </ul></div><p>The <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog accessed from the <tt class="literal"><span class="pre">Project</span></tt> menu provides some assistance for setting up new Wing projects for most of these.</p> </div> <div class="section"> <h3 class="title-3">Multi-threaded and Multi-process Debugging</h3> <p>Wing automatically debugs any multi-threaded code without any additional configuration.</p> <p>Multi-process code can also be debugged but requires turning on the <tt class="literal"><span class="pre">Debug/Execute</span> <span class="pre">&gt;</span> <span class="pre">Debug</span> <span class="pre">Child</span> <span class="pre">Processes</span></tt> option in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> before child processes are automatically debugged. In this case, you may also want to configure specific options for how Wing handles and terminates child processes. See <a class="reference" href="/doc/debug/multiprocess">Multi-Process Debugging</a> for details.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/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/debug-overviewThu, 04 Jun 2020 01:00:00 GMTConditional Breakpoints Wing Pro's Python Debuggerhttps://wingware.com/hints/conditional-breakpoints<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to use conditional breakpoints in <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a> to stop in Python code only when certain conditions are true. This is useful for isolating a single case out of many that may be processed by the same code in a particular run, in order to investigate how that case is being handled.</p> <p>Conditional breakpoints are also a great way to select the runtime state for which you want to write new Python code, with the ability to immediately try out what you write.</p> <p>To set a conditional breakpoint, right-click on the breakpoint margin in the editor and select <tt class="literal"><span class="pre">Set</span> <span class="pre">Conditional</span> <span class="pre">Breakpoint</span></tt>:</p> <img src="https://wingware.com/images/blog/conditional-breakpoints/set-conditional.gif" alt="Set Conditional Breakpoint" backrefs="" caption="Shown above: Right-click on the breakpoint margin to set a conditional breakpoint." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Right-click on the breakpoint margin to set a conditional breakpoint.</i></p><p>Then start debug with <tt class="literal"><span class="pre">Start/Continue</span></tt> in the <tt class="literal"><span class="pre">Debug</span></tt> menu, from the toolbar, or as shown here with <tt class="literal"><span class="pre">Debug</span> <span class="pre">Tests</span></tt> in the <tt class="literal"><span class="pre">Testing</span></tt> tool:</p> <img src="https://wingware.com/images/blog/conditional-breakpoints/debug-to-bp.gif" alt="Debug Unit Tests with a Conditional Breakpoint" backrefs="" caption="Shown above: Select a set of unit tests and debug them to reach the conditional breakpoint, then run to the next hit, step over a few lines, and press Shift-Space to view the value of all visible variables." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Select a set of unit tests and debug them to reach the conditional breakpoint, then run to the next hit, step over a few lines, and press Shift-Space to view the value of all visible variables.</i></p><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/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/conditional-breakpointsWed, 20 May 2020 01:00:00 GMTMoving the Program Counter in Wing's Python Debuggerhttps://wingware.com/hints/move-program-counter2<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to move the program counter while debugging Python code in Wing Personal and Wing Pro. This is a good way to go back and re-execute previously visited Python code, in order to trace through to the cause of a bug without having to restart the debug process.</p> <p>To move the program counter, the debugger must be running and paused or stopped at a breakpoint. Then right-click on the target line in the editor and select <tt class="literal"><span class="pre">Move</span> <span class="pre">Program</span> <span class="pre">Counter</span> <span class="pre">Here</span></tt>:</p> <img src="https://wingware.com/images/blog/move-program-counter2/move-program-counter.gif" alt="Move Program Counter" backrefs="" caption="Shown above: Right-click to select Move Program Counter Here, then continue stepping with Step Over and Step Into in the toolbar." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Right-click to select Move Program Counter Here, then continue stepping with Step Over and Step Into in the toolbar.</i></p><p><strong>Limitations:</strong> Due to the way Python is implemented, the program counter can only be moved within the current inner-most stack frame and it may not be moved within an exception handler, after an exception has been raised but not yet handled.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/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/move-program-counter2Tue, 12 May 2020 01:00:00 GMT