|
| 1 | +--- |
| 2 | +title: Local Development |
| 3 | +--- |
| 4 | + |
| 5 | +# Local Development |
| 6 | + |
| 7 | +## Deno |
| 8 | + |
| 9 | +Windmill deno scripts can be run like normal deno scripts. To add testing or |
| 10 | +debugging code, add this snippet to your file: |
| 11 | + |
| 12 | +```ts |
| 13 | +if (import.meta.main) { |
| 14 | + // Add your testing & debugging code here. |
| 15 | +} |
| 16 | +``` |
| 17 | + |
| 18 | +You can then use your script like normal (for example, |
| 19 | +`deno run -A --watch my_script.ts`), and even write tests inside. |
| 20 | + |
| 21 | +For more information on deno development in general, |
| 22 | +[see the official docs](https://deno.land/manual@v1.30.3/getting_started) |
| 23 | + |
| 24 | +## Python |
| 25 | + |
| 26 | +Windmill python scripts can be run like normal python scripts. To add testing or |
| 27 | +debbug code, add this snippet to your file: |
| 28 | + |
| 29 | +```py |
| 30 | +if __name__ == 'main': |
| 31 | + # Add your testing & debugging code here. |
| 32 | + pass |
| 33 | +``` |
| 34 | + |
| 35 | +You can then use your script like normal (for example, `python my_script.py`), |
| 36 | +and even write tests inside. |
| 37 | + |
| 38 | +For more information on python development in general, |
| 39 | +[see the official docs](https://www.python.org/doc/) |
| 40 | + |
| 41 | +## Interacting with Windmill locally |
| 42 | + |
| 43 | +Often you will need to test a script locally that also interacts with windmill. |
| 44 | +For example to retrieve resources. |
| 45 | + |
| 46 | +To do so you will need to fill out the context variables that will otherwise be |
| 47 | +filled out by the windmill runtime for you. The most important ones are |
| 48 | +`WM_TOKEN` and `BASE_INTERNAL_URL`. Set `BASE_INTERNAL_URL` to the URL of you windmill instance, |
| 49 | +for example `https://app.windmill.dev`, note that you can never include a |
| 50 | +trailing `/`, or the client will fail to connect. Then set `WM_TOKEN` to a |
| 51 | +token, either create this in the UI, or use [wmill, the CLI](../3_cli/index.md) |
| 52 | +using `wmill user create-token`. Below are some examples on how to do this in |
| 53 | +various environments. |
| 54 | + |
| 55 | +### Terminal |
| 56 | + |
| 57 | +On UNIX platforms you can simply do |
| 58 | +`BASE_INTERNAL_URL=https://app.windmill.dev WM_TOKEN=ThisIsAToken deno run -A my_script.ts` |
| 59 | +with the relevant info provided, the same will work for python. |
| 60 | + |
| 61 | +On windows this is not possible, you will have to use |
| 62 | +[set](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/set_1). |
| 63 | +For example: |
| 64 | + |
| 65 | +```cmd |
| 66 | +set "BASE_INTERNAL_URL=https://app.windmill.dev" |
| 67 | +set "WM_TOKEN=ThisIsAToken" |
| 68 | +``` |
| 69 | + |
| 70 | +then simply run the relevant command for your language. |
| 71 | + |
| 72 | +### VSCode |
| 73 | + |
| 74 | +The easiest way to do this is using a launch.json. See how to create one for |
| 75 | +[python](https://code.visualstudio.com/docs/python/debugging) and |
| 76 | +[deno](https://deno.land/manual@v1.9.2/getting_started/debugging_your_code#vscode) |
| 77 | + |
| 78 | +Then add environment files using the "env" section in your configuration. |
| 79 | + |
| 80 | +:::caution |
| 81 | + |
| 82 | +Make sure you are not checking your Token into git. |
| 83 | + |
| 84 | +To easily manage your secrets it may be easier to use a .env file, and add it to |
| 85 | +.gitignore, this is also done below. |
| 86 | + |
| 87 | +::: |
| 88 | + |
| 89 | +For example, for deno: |
| 90 | + |
| 91 | +```json |
| 92 | +{ |
| 93 | + "version": "0.2.0", |
| 94 | + "configurations": [ |
| 95 | + { |
| 96 | + "name": "Deno", |
| 97 | + "type": "pwa-node", |
| 98 | + "request": "launch", |
| 99 | + "cwd": "${workspaceFolder}", |
| 100 | + "runtimeExecutable": "deno", |
| 101 | + "runtimeArgs": ["run", "--inspect-brk", "-A", "${file}"], |
| 102 | + "env" { |
| 103 | + "BASE_INTERNAL_URL": "https://app.windmill.dev", |
| 104 | + "WM_TOKEN": "ThisIsAToken" |
| 105 | + }, |
| 106 | + "envFile": ".env" |
| 107 | + } |
| 108 | + ] |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +The same `env` & `envFile` options are also supported by python. |
| 113 | + |
| 114 | +### JetBrains IDEs |
| 115 | + |
| 116 | +Especially for python you may prefer using a JetBrains IDE. Simply navigate to |
| 117 | +your |
| 118 | +[run config](https://www.jetbrains.com/help/idea/run-debug-configuration-python.html#1) |
| 119 | +and add two lines |
| 120 | + |
| 121 | +``` |
| 122 | +BASE_INTERNAL_URL = https://app.windmill.dev |
| 123 | +WM_TOKEN = ThisIsAToken |
| 124 | +``` |
| 125 | + |
| 126 | +:::caution |
| 127 | + |
| 128 | +Make sure you are not checking your Token into git. |
| 129 | + |
| 130 | +::: |
0 commit comments