|
| 1 | +# Developer Guide |
| 2 | + |
| 3 | +This page explains the technical and practical requirements and processes |
| 4 | +needed to contribute to PyScript. |
| 5 | + |
| 6 | +!!! info |
| 7 | + |
| 8 | + In the following instructions, we assume familiarity with `git`, |
| 9 | + [GitHub](https://github.com/pyscript/pyscript), the command line and other |
| 10 | + common development concepts, tools and practices. |
| 11 | + |
| 12 | + For those who come from a non-Pythonic technical background (for example, |
| 13 | + you're a JavaScript developer), we will explain Python-isms as we go along |
| 14 | + so you're contributing with confidence. |
| 15 | + |
| 16 | + If you're unsure, or encounter problems, please ask for help on our |
| 17 | + [discord server](https://discord.gg/HxvBtukrg2). |
| 18 | + |
| 19 | +## Welcome |
| 20 | + |
| 21 | +We are a diverse, inclusive coding community and welcome contributions from |
| 22 | +_anyone_ irrespective of their background. If you're thinking, "but they don't |
| 23 | +mean me", _then we especially mean YOU_. Our diversity means _you will meet |
| 24 | +folks in our community who are different to yourself_. Therefore, thoughtful |
| 25 | +contributions made in good faith, and engagement with respect, care and |
| 26 | +compassion wins every time. |
| 27 | + |
| 28 | +* If you're from a background which isn't well-represented in most geeky |
| 29 | + groups, get involved - _we want to help you make a difference_. |
| 30 | +* If you're from a background which **is** well-represented in most geeky |
| 31 | + groups, get involved - _we want your help making a difference_. |
| 32 | +* If you're worried about not being technical enough, get involved - _your |
| 33 | + fresh perspective will be invaluable_. |
| 34 | +* If you need help with anything, get involved - _we welcome questions asked |
| 35 | + in good faith, and will move mountains to help_. |
| 36 | +* If you're unsure where to start, get involved - _we have [many ways to |
| 37 | + contribute](/contributing)_. |
| 38 | + |
| 39 | +All contributors are expected to follow our [code of conduct](/conduct/). |
| 40 | + |
| 41 | +## Setup |
| 42 | + |
| 43 | +**You must have recent versions of [Python](https://python.org/), |
| 44 | +[node.js](https://nodejs.org/en) and [npm](https://www.npmjs.com/) already |
| 45 | +installed on your system.** |
| 46 | + |
| 47 | +The following steps create a working development environment for PyScript. It |
| 48 | +is through this environment that you contribute to PyScript. |
| 49 | + |
| 50 | +!!! danger |
| 51 | + |
| 52 | + The following commands work on Unix like operating systems (like MacOS or |
| 53 | + Linux). **If you are a Microsoft Windows user please use the |
| 54 | + [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/about) |
| 55 | + with the following instructions.** |
| 56 | + |
| 57 | +### Create a virtual environment |
| 58 | + |
| 59 | +* A Python [virtual environment](https://docs.python.org/3/library/venv.html) |
| 60 | + is a computing "sandbox" that safely isolates your work. PyScript's |
| 61 | + development makes use of various Python based tools, so both |
| 62 | + [Python](https://python.org) and a virtual environment is needed. There are |
| 63 | + many tools to help manage these environments, but the standard way to create |
| 64 | + a virtual environment is to use this command in your terminal: |
| 65 | + |
| 66 | + ```sh |
| 67 | + python3 -m venv my_pyscript_dev_venv |
| 68 | + ``` |
| 69 | + |
| 70 | + !!! warning |
| 71 | + |
| 72 | + Replace `my_pyscript_dev_venv` with a meaningful name for the |
| 73 | + virtual environment, that works for you. |
| 74 | + |
| 75 | +* A `my_pyscript_dev_venv` directory containing the virtual environment's |
| 76 | + "stuff" is created as a subdirectory of your current directory. Next, |
| 77 | + activate the virtual environment to ensure your development activities happen |
| 78 | + within the context of the sandbox: |
| 79 | +
|
| 80 | + ```sh |
| 81 | + source my_pyscript_dev_venv/bin/activate |
| 82 | + ``` |
| 83 | +
|
| 84 | +* The prompt in your terminal will change to include the name of your virtual |
| 85 | + environment indicating the sandbox is active. To deactivate the virtual |
| 86 | + environment just type the following into your terminal: |
| 87 | +
|
| 88 | + ```sh |
| 89 | + deactivate |
| 90 | + ``` |
| 91 | +
|
| 92 | +!!! info |
| 93 | +
|
| 94 | + The rest of the instructions on this page assume you are working in **an |
| 95 | + activated virtual environment** for developing PyScript. |
| 96 | +
|
| 97 | +### Prepare your repository |
| 98 | +
|
| 99 | +* Create a [fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) |
| 100 | + of the |
| 101 | + [PyScript github repository](https://github.com/pyscript/pyscript/fork) to |
| 102 | + your own GitHub account. |
| 103 | +* [Clone](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) |
| 104 | + your newly forked version of the PyScript repository onto your |
| 105 | + local development machine. For example, use this command in your terminal: |
| 106 | +
|
| 107 | + ```sh |
| 108 | + git clone https://github.com/<YOUR USERNAME>/pyscript |
| 109 | + ``` |
| 110 | +
|
| 111 | + !!! warning |
| 112 | +
|
| 113 | + In the URL for the forked PyScript repository, remember to replace |
| 114 | + `<YOUR USERNAME>` with your actual GitHub username. |
| 115 | +
|
| 116 | + !!! tip |
| 117 | +
|
| 118 | + To help explain steps, we will use `git` commands to be typed into your |
| 119 | + terminal / command line. |
| 120 | +
|
| 121 | + The equivalent of these commands could be achieved through other means |
| 122 | + (such as [GitHub's desktop client](https://desktop.github.com/)). How |
| 123 | + these alternatives work is beyond the scope of this document. |
| 124 | + |
| 125 | +* Change into the root directory of your newly cloned `pyscript` repository: |
| 126 | + |
| 127 | + ```sh |
| 128 | + cd pyscript |
| 129 | + ``` |
| 130 | + |
| 131 | +* Add the original PyScript repository as your `upstream` to allow you to keep |
| 132 | + your own fork up-to-date with the latest changes: |
| 133 | + |
| 134 | + ```sh |
| 135 | + git remote add upstream https://github.com/pyscript/pyscript.git |
| 136 | + ``` |
| 137 | + |
| 138 | +* If the above fails, try this alternative: |
| 139 | + |
| 140 | + ```sh |
| 141 | + git remote remove upstream |
| 142 | + git remote add upstream [email protected]:pyscript/pyscript.git |
| 143 | + ``` |
| 144 | + |
| 145 | +* Pull in the latest changes from the main `upstream` PyScript repository: |
| 146 | + |
| 147 | + ```sh |
| 148 | + git pull upstream main |
| 149 | + ``` |
| 150 | + |
| 151 | +* Pyscript uses a `Makefile` to automate the most common development tasks. In |
| 152 | + your terminal, type `make` to see what it can do. You should see something |
| 153 | + like this: |
| 154 | + |
| 155 | + ```sh |
| 156 | + There is no default Makefile target right now. Try: |
| 157 | +
|
| 158 | + make setup - check your environment and install the dependencies. |
| 159 | + make clean - clean up auto-generated assets. |
| 160 | + make build - build PyScript. |
| 161 | + make precommit-check - run the precommit checks (run eslint). |
| 162 | + make test-integration - run all integration tests sequentially. |
| 163 | + make fmt - format the code. |
| 164 | + make fmt-check - check the code formatting. |
| 165 | + ``` |
| 166 | + |
| 167 | +### Install dependencies |
| 168 | + |
| 169 | +* To install the required software dependencies for working on PyScript, in |
| 170 | + your terminal type: |
| 171 | + |
| 172 | + ```sh |
| 173 | + make setup |
| 174 | + ``` |
| 175 | + |
| 176 | +* Updates from `npm` and then `pip` will scroll past telling you about |
| 177 | + their progress installing the required packages. |
| 178 | + |
| 179 | + !!! warning |
| 180 | + |
| 181 | + The `setup` process checks the versions of Python, node |
| 182 | + and npm. If you encounter a failure at this point, it's probably |
| 183 | + because one of these pre-requisits is out of date on your system. |
| 184 | + Please update! |
| 185 | +
|
| 186 | +## Check code |
| 187 | +
|
| 188 | +* To ensure consistency of code layout we use tools to both reformat and check |
| 189 | + the code. |
| 190 | +
|
| 191 | +* To ensure your code is formatted correctly: |
| 192 | +
|
| 193 | + ```sh |
| 194 | + make fmt |
| 195 | + ``` |
| 196 | +
|
| 197 | +* To check your code is formatted correctly: |
| 198 | +
|
| 199 | + ```sh |
| 200 | + make fmt-check |
| 201 | + ``` |
| 202 | +
|
| 203 | +* Finally, as part of the automated workflow for contributing |
| 204 | + [pull requests](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) |
| 205 | + pre-commit checks the source code. If this fails revise your PR. To run |
| 206 | + pre-commit checks locally (before creating the PR): |
| 207 | +
|
| 208 | + ```sh |
| 209 | + make precommit-check |
| 210 | + ``` |
| 211 | +
|
| 212 | + This may also revise your code formatting. Re-run `make precommit-check` to |
| 213 | + ensure this is the case. |
| 214 | +
|
| 215 | +## Build PyScript |
| 216 | +
|
| 217 | +* To turn the JavaScript source code found in the `pyscript.core` directory |
| 218 | + into a bundled up module ready for the browser, type: |
| 219 | +
|
| 220 | + ```sh |
| 221 | + make build |
| 222 | + ``` |
| 223 | +
|
| 224 | + The resulting assets will be in the `pyscript.core/dist` directory. |
| 225 | +
|
| 226 | +## Run the tests |
| 227 | +
|
| 228 | +* The integration tests for PyScript are started with: |
| 229 | +
|
| 230 | + ```sh |
| 231 | + make test-integration |
| 232 | + ``` |
| 233 | +
|
| 234 | +## Documentation |
| 235 | +
|
| 236 | +* Documentation for PyScript (i.e. what you're reading right now), is found |
| 237 | + in a separate repository: |
| 238 | + [https://github.com/pyscript/docs](https://github.com/pyscript/docs) |
| 239 | + |
| 240 | +* The documentation's `README` file contains instructions for setting up a |
| 241 | + development environment and contributing. |
| 242 | +
|
| 243 | +## Contributing |
| 244 | +
|
| 245 | +* We have [suggestions for how to contribute to PyScript](/contributing). Take |
| 246 | + a read and dive in. |
| 247 | +
|
| 248 | +* Please make sure you discuss potential contributions *before* you put in |
| 249 | + work. We don#t want folks to waste their time or re-invent the wheel. |
| 250 | +
|
| 251 | +* Technical discussions happen [on our discord server](https://discord.gg/HxvBtukrg2) |
| 252 | + and in the |
| 253 | + [discussions section](https://github.com/pyscript/pyscript/discussions) of |
| 254 | + our GitHub repository. |
| 255 | +
|
| 256 | +* Every Tusday is a community video call, the details of which are posted onto |
| 257 | + the discord server. Face to face technical discussions happen here. |
| 258 | +
|
| 259 | +* Every two weeks, on a Thursday, is a PyScript FUN call, the details of which |
| 260 | + are also posted to discord. Project show-and-tells, cool hacks, new features |
| 261 | + and a generally humorous and creative time is had by all. |
0 commit comments