|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<meta charset="UTF-8"> |
| 5 | +<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | +<title>Python Tools - Commands</title> |
| 7 | +<link rel="stylesheet" href="css/walkthrough.css"> |
| 8 | +</head> |
| 9 | +<body> |
| 10 | + |
| 11 | +<h1>Python Tools</h1> |
| 12 | +<p class="lede">Run Python and Flask projects on the device, straight from the editor toolbar.</p> |
| 13 | + |
| 14 | +<p>Python Tools adds two project templates and four toolbar commands. The commands appear only |
| 15 | +while a Python project is open; in a Java, Kotlin, or Android project the toolbar is left alone. |
| 16 | +Because Gradle plays no part in a Python project, the Gradle actions (Quick Run, Sync, Debug, Run |
| 17 | +Tasks, Launch App) are hidden while you work in one.</p> |
| 18 | + |
| 19 | +<div class="callout"> |
| 20 | +<p>A project counts as Python when its root holds a Python entry point (<code>app.py</code>, |
| 21 | +<code>main.py</code>, <code>manage.py</code>, <code>__main__.py</code>, or <code>wsgi.py</code>), a |
| 22 | +<code>requirements.txt</code>, or any <code>.py</code> file.</p> |
| 23 | +</div> |
| 24 | + |
| 25 | +<h2>Getting Python</h2> |
| 26 | +<p>The first time the plugin activates it checks for a Python interpreter and, when none is found, |
| 27 | +installs one with the bundled Termux package manager (<code>pkg install python</code>). That |
| 28 | +download runs in the background and reports its result as a message; give it a few minutes on a |
| 29 | +fresh device before running anything.</p> |
| 30 | + |
| 31 | +<h2>The commands</h2> |
| 32 | +<table> |
| 33 | + <tr><th>Command</th><th>What it runs</th><th>Stopped after</th></tr> |
| 34 | + <tr><td><a href="#run-app">Run app</a></td><td>the project entry point</td><td>30 minutes</td></tr> |
| 35 | + <tr><td><a href="#run-current-file">Run current file</a></td><td>the open <code>.py</code> file</td><td>30 minutes</td></tr> |
| 36 | + <tr><td><a href="#install-requirements">Install requirements</a></td><td><code>pip install -r requirements.txt</code></td><td>5 minutes</td></tr> |
| 37 | + <tr><td><a href="#run-tests">Run tests</a></td><td><code>python -m pytest -q</code></td><td>10 minutes</td></tr> |
| 38 | +</table> |
| 39 | +<p>Every command streams its output into the <b>Build Output</b> panel at the bottom of the editor, |
| 40 | +and the panel opens itself when a command starts. While a command is running its toolbar button |
| 41 | +turns into a Cancel button: tap it to stop the process.</p> |
| 42 | + |
| 43 | +<h3 id="run-app">Run app</h3> |
| 44 | +<p>Looks for an entry point in the project root and runs the first one it finds:</p> |
| 45 | +<ol> |
| 46 | + <li><code>app.py</code> - a Flask app</li> |
| 47 | + <li><code>main.py</code> - a plain Python project</li> |
| 48 | + <li><code>manage.py</code> - started with <code>runserver</code></li> |
| 49 | + <li><code>__main__.py</code></li> |
| 50 | + <li><code>wsgi.py</code></li> |
| 51 | +</ol> |
| 52 | +<p>When none of those exist the command says so and stops, rather than guessing.</p> |
| 53 | +<p>Output is unbuffered, so <code>print()</code> lines and a Flask request log appear as they |
| 54 | +happen instead of arriving in a block at the end. A Flask app keeps running until you cancel it; |
| 55 | +open the port it prints (<code>5000</code> by default) in a browser on the device to use the app.</p> |
| 56 | +<p>If the run fails because a module is missing and the project has a <code>requirements.txt</code>, |
| 57 | +the plugin installs the dependencies for you, then asks you to tap Run again.</p> |
| 58 | + |
| 59 | +<h3 id="run-current-file">Run current file</h3> |
| 60 | +<p>Appears only while a <code>.py</code> file is open, and runs exactly that file by its full path. |
| 61 | +Use it for a script that is not the project entry point - a data fixture, a one-off check, a |
| 62 | +scratch file.</p> |
| 63 | +<p>Missing dependencies are installed from <code>requirements.txt</code> the same way as Run app.</p> |
| 64 | + |
| 65 | +<h3 id="install-requirements">Install requirements</h3> |
| 66 | +<p>Runs <code>pip install -r requirements.txt</code> in the project root and streams pip's output |
| 67 | +into Build Output.</p> |
| 68 | +<p>The same install runs on its own when a run fails because a module is missing, so reach for this |
| 69 | +button after you edit <code>requirements.txt</code> yourself. When the file is absent, a failed run |
| 70 | +says so instead of installing anything.</p> |
| 71 | + |
| 72 | +<h3 id="run-tests">Run tests</h3> |
| 73 | +<p>Runs <code>python -m pytest -q</code> in the project root. When pytest is not installed yet it |
| 74 | +is fetched with pip before the tests start, so the first run takes longer than later ones.</p> |
| 75 | + |
| 76 | +<h2>The project templates</h2> |
| 77 | +<p>Both templates appear on the New Project screen beside the built-in ones:</p> |
| 78 | +<ul> |
| 79 | + <li><b>Python Flask App</b> - routes, HTML templates, static CSS, a config file, and a 404 page. |
| 80 | + The port is a template parameter and defaults to <code>5000</code>.</li> |
| 81 | + <li><b>Python Starter</b> - a single <code>main.py</code> entry point, a |
| 82 | + <code>requirements.txt</code>, and a <code>.gitignore</code>.</li> |
| 83 | +</ul> |
| 84 | + |
| 85 | +<h2>Stopping a runaway process</h2> |
| 86 | +<p>A Python process started by the plugin is tied to the IDE: if the IDE is killed, the child |
| 87 | +process is killed with it, so a forgotten Flask server cannot keep holding a port after the IDE is |
| 88 | +gone. Each command also has its own time limit, listed in the table above.</p> |
| 89 | + |
| 90 | +<h2>Turning it off</h2> |
| 91 | +<p>Disable Python Tools in the Plugin Manager. The Python commands disappear, the Gradle actions |
| 92 | +come back for every project, and the two templates are removed from the New Project screen. Any |
| 93 | +Python packages already installed on the device stay where they are.</p> |
| 94 | + |
| 95 | +</body> |
| 96 | +</html> |
0 commit comments