|
| 1 | +# Contributing |
| 2 | + |
| 3 | +First, you might want to see the basic ways to [help Asyncer and get help](help.md){.internal-link target=_blank}. |
| 4 | + |
| 5 | +## Developing |
| 6 | + |
| 7 | +If you already cloned the <a href="https://github.com/fastapi/asyncer" class="external-link" target="_blank">asyncer repository</a> and you want to deep dive in the code, here are some guidelines to set up your environment. |
| 8 | + |
| 9 | +### Virtual Environment |
| 10 | + |
| 11 | +Follow the instructions to create and activate a virtual environment as described in the <a href="https://fastapi.tiangolo.com/virtual-environments/" class="external-link" target="_blank">FastAPI page on Virtual Environments</a> for the internal code of `asyncer`. |
| 12 | + |
| 13 | +### Install Requirements Using `pip` |
| 14 | + |
| 15 | +After activating the environment, install the required packages: |
| 16 | + |
| 17 | +<div class="termy"> |
| 18 | + |
| 19 | +```console |
| 20 | +$ pip install -r requirements.txt |
| 21 | + |
| 22 | +---> 100% |
| 23 | +``` |
| 24 | + |
| 25 | +</div> |
| 26 | + |
| 27 | +It will install all the dependencies and your local Asyncer in your local environment. |
| 28 | + |
| 29 | +### Using your Local Asyncer |
| 30 | + |
| 31 | +If you create a Python file that imports and uses Asyncer, and run it with the Python from your local environment, it will use your cloned local Asyncer source code. |
| 32 | + |
| 33 | +And if you update that local Asyncer source code when you run that Python file again, it will use the fresh version of Asyncer you just edited. |
| 34 | + |
| 35 | +That way, you don't have to "install" your local version to be able to test every change. |
| 36 | + |
| 37 | +/// note | "Technical Details" |
| 38 | + |
| 39 | +This only happens when you install using this included `requirements.txt` instead of running `pip install asyncer` directly. |
| 40 | + |
| 41 | +That is because inside the `requirements.txt` file, the local version of Asyncer is marked to be installed in "editable" mode, with the `-e` option. |
| 42 | + |
| 43 | +/// |
| 44 | + |
| 45 | +### Format |
| 46 | + |
| 47 | +There is a script that you can run that will format and clean all your code: |
| 48 | + |
| 49 | +<div class="termy"> |
| 50 | + |
| 51 | +```console |
| 52 | +$ bash scripts/format.sh |
| 53 | +``` |
| 54 | + |
| 55 | +</div> |
| 56 | + |
| 57 | +It will also auto-sort all your imports. |
| 58 | + |
| 59 | +## Tests |
| 60 | + |
| 61 | +There is a script that you can run locally to test all the code and generate coverage reports in HTML: |
| 62 | + |
| 63 | +<div class="termy"> |
| 64 | + |
| 65 | +```console |
| 66 | +$ bash scripts/test.sh |
| 67 | +``` |
| 68 | + |
| 69 | +</div> |
| 70 | + |
| 71 | +This command generates a directory `./htmlcov/`, if you open the file `./htmlcov/index.html` in your browser, you can explore interactively the regions of code that are covered by the tests, and notice if there is any region missing. |
| 72 | + |
| 73 | +## Docs |
| 74 | + |
| 75 | +First, make sure you set up your environment as described above, that will install all the requirements. |
| 76 | + |
| 77 | +### Docs Live |
| 78 | + |
| 79 | +During local development, there is a script that builds the site and checks for any changes, live-reloading: |
| 80 | + |
| 81 | +<div class="termy"> |
| 82 | + |
| 83 | +```console |
| 84 | +$ python ./scripts/docs.py live |
| 85 | + |
| 86 | +<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
| 87 | +<span style="color: green;">[INFO]</span> Start watching changes |
| 88 | +<span style="color: green;">[INFO]</span> Start detecting changes |
| 89 | +``` |
| 90 | + |
| 91 | +</div> |
| 92 | + |
| 93 | +It will serve the documentation on `http://127.0.0.1:8008`. |
| 94 | + |
| 95 | +That way, you can edit the documentation/source files and see the changes live. |
| 96 | + |
| 97 | +/// tip |
| 98 | + |
| 99 | +Alternatively, you can perform the same steps that scripts does manually. |
| 100 | + |
| 101 | +Go into the docs director at `docs/`: |
| 102 | + |
| 103 | +```console |
| 104 | +$ cd docs/ |
| 105 | +``` |
| 106 | + |
| 107 | +Then run `mkdocs` in that directory: |
| 108 | + |
| 109 | +```console |
| 110 | +$ mkdocs serve --dev-addr 8008 |
| 111 | +``` |
| 112 | + |
| 113 | +/// |
| 114 | + |
| 115 | +#### Typer CLI (Optional) |
| 116 | + |
| 117 | +The instructions here show you how to use the script at `./scripts/docs.py` with the `python` program directly. |
| 118 | + |
| 119 | +But you can also use <a href="https://typer.tiangolo.com/typer-cli/" class="external-link" target="_blank">Typer CLI</a>, and you will get autocompletion in your terminal for the commands after installing completion. |
| 120 | + |
| 121 | +If you install Typer CLI, you can install completion with: |
| 122 | + |
| 123 | +<div class="termy"> |
| 124 | + |
| 125 | +```console |
| 126 | +$ typer --install-completion |
| 127 | + |
| 128 | +zsh completion installed in /home/user/.bashrc. |
| 129 | +Completion will take effect once you restart the terminal. |
| 130 | +``` |
| 131 | + |
| 132 | +</div> |
| 133 | + |
| 134 | +### Docs Structure |
| 135 | + |
| 136 | +The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a>. |
| 137 | + |
| 138 | +And there are extra tools/scripts in place in `./scripts/docs.py`. |
| 139 | + |
| 140 | +/// tip |
| 141 | + |
| 142 | +You don't need to see the code in `./scripts/docs.py`, you just use it in the command line. |
| 143 | + |
| 144 | +/// |
| 145 | + |
| 146 | +All the documentation is in Markdown format in the directory `./docs`. |
| 147 | + |
| 148 | +Many of the tutorials have blocks of code. |
| 149 | + |
| 150 | +In most of the cases, these blocks of code are actual complete applications that can be run as is. |
| 151 | + |
| 152 | +In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs_src/` directory. |
| 153 | + |
| 154 | +And those Python files are included/injected in the documentation when generating the site. |
| 155 | + |
| 156 | +### Docs for Tests |
| 157 | + |
| 158 | +Most of the tests actually run against the example source files in the documentation. |
| 159 | + |
| 160 | +This helps to make sure that: |
| 161 | + |
| 162 | +* The documentation is up-to-date. |
| 163 | +* The documentation examples can be run as is. |
| 164 | +* Most of the features are covered by the documentation, ensured by test coverage. |
0 commit comments