You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/docs/contributing.md
+56-43Lines changed: 56 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@ First, you might want to see the basic ways to [help FastAPI and get help](help-
4
4
5
5
## Developing
6
6
7
-
If you already cloned the repositoryand you know that you need to deep dive in the code, here are some guidelines to set up your environment.
7
+
If you already cloned the [fastapi repository](https://github.com/tiangolo/fastapi){.internal-link target=_blank} and you want to deep dive in the code, here are some guidelines to set up your environment.
8
8
9
9
### Virtual environment with `venv`
10
10
11
-
You can create a virtual environment in a directory using Python's `venv` module:
11
+
You can create an isolated virtual local environment in a directory using Python's `venv` module. Let's do this in the cloned repository (where the `requirements.txt` is):
12
12
13
13
<divclass="termy">
14
14
@@ -18,7 +18,7 @@ $ python -m venv env
18
18
19
19
</div>
20
20
21
-
That will create a directory `./env/` with the Python binaries and then you will be able to install packages for that isolated environment.
21
+
That will create a directory `./env/` with the Python binaries, and then you will be able to install packages for that local environment.
22
22
23
23
### Activate the environment
24
24
@@ -84,7 +84,7 @@ To check it worked, use:
84
84
85
85
If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉
86
86
87
-
Make sure you have the latest pip version on your virtual environment to avoid errors on the next steps:
87
+
Make sure you have the latest pip version on your local environment to avoid errors on the next steps:
This makes sure that if you use a terminal program installed by that package, you use the one from your local environment and not any other that could be installed globally.
103
103
104
-
### pip
104
+
### Install requirements using pip
105
105
106
106
After activating the environment as described above:
It will install all the dependencies and your local FastAPI in your local environment.
119
119
120
-
####Using your local FastAPI
120
+
### Using your local FastAPI
121
121
122
-
If you create a Python file that imports and uses FastAPI, and run it with the Python from your local environment, it will use your local FastAPI source code.
122
+
If you create a Python file that imports and uses FastAPI, and run it with the Python from your local environment, it will use your cloned local FastAPI source code.
123
123
124
124
And if you update that local FastAPI source code when you run that Python file again, it will use the fresh version of FastAPI you just edited.
125
125
126
126
That way, you don't have to "install" your local version to be able to test every change.
127
127
128
128
!!! note "Technical Details"
129
-
This only happens when you install using this included `requirements.txt` instead of installing`pip install fastapi` directly.
129
+
This only happens when you install using this included `requirements.txt` instead of running`pip install fastapi` directly.
130
130
131
-
That is because inside of the `requirements.txt` file, the local version of FastAPI is marked to be installed in "editable" mode, with the `-e` option.
131
+
That is because inside the `requirements.txt` file, the local version of FastAPI is marked to be installed in "editable" mode, with the `-e` option.
132
132
133
-
### Format
133
+
### Format the code
134
134
135
135
There is a script that you can run that will format and clean all your code:
136
136
@@ -171,12 +171,14 @@ And those Python files are included/injected in the documentation when generatin
171
171
172
172
Most of the tests actually run against the example source files in the documentation.
173
173
174
-
This helps making sure that:
174
+
This helps to make sure that:
175
175
176
-
* The documentation is up to date.
176
+
* The documentation is up-to-date.
177
177
* The documentation examples can be run as is.
178
178
* Most of the features are covered by the documentation, ensured by test coverage.
179
179
180
+
#### Live preview
181
+
180
182
During local development, there is a script that builds the site and checks for any changes, live-reloading:
181
183
182
184
<divclass="termy">
@@ -210,41 +212,41 @@ That way, you can edit the documentation/source files and see the changes live.
210
212
$ mkdocs serve --dev-addr 8008
211
213
```
212
214
213
-
#### Typer CLI (optional)
214
-
215
-
The instructions here show you how to use the script at `./scripts/docs.py` with the `python` program directly.
216
-
217
-
But you can also use <ahref="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.
215
+
#### Apps and docs at the same time
218
216
219
-
If you install Typer CLI, you can install completion with:
217
+
If you run the examples with, e.g.:
220
218
221
219
<divclass="termy">
222
220
223
221
```console
224
-
$ typer --install-completion
222
+
$ uvicorn tutorial001:app --reload
225
223
226
-
zsh completion installed in /home/user/.bashrc.
227
-
Completion will take effect once you restart the terminal.
224
+
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
228
225
```
229
226
230
227
</div>
231
228
232
-
### Apps and docs at the same time
229
+
as Uvicorn by default will use the port `8000`, the documentation on port `8008` won't clash.
233
230
234
-
If you run the examples with, e.g.:
231
+
#### Typer CLI (optional)
232
+
233
+
The instructions here show you how to use the script at `./scripts/docs.py` with the `python` program directly.
234
+
235
+
But you can also use <ahref="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.
236
+
237
+
If you install Typer CLI, you can install completion with:
235
238
236
239
<divclass="termy">
237
240
238
241
```console
239
-
$ uvicorn tutorial001:app --reload
242
+
$ typer --install-completion
240
243
241
-
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
244
+
zsh completion installed in /home/user/.bashrc.
245
+
Completion will take effect once you restart the terminal.
242
246
```
243
247
244
248
</div>
245
249
246
-
as Uvicorn by default will use the port `8000`, the documentation on port `8008` won't clash.
247
-
248
250
### Translations
249
251
250
252
Help with translations is VERY MUCH appreciated! And it can't be done without the help from the community. 🌎 🚀
@@ -253,7 +255,9 @@ Here are the steps to help with translations.
253
255
254
256
#### Tips and guidelines
255
257
256
-
* Check the currently <ahref="https://github.com/tiangolo/fastapi/pulls"class="external-link"target="_blank">existing pull requests</a> for your language and add reviews requesting changes or approving them.
258
+
* Check the currently <ahref="https://github.com/tiangolo/fastapi/pulls"class="external-link"target="_blank">existing pull requests</a> for your language. You can filter the pull requests by the ones with the label for your language. For example, for Spanish, the label is <ahref="https://github.com/tiangolo/fastapi/pulls?q=is%3Aopen+sort%3Aupdated-desc+label%3Alang-es+label%3Aawaiting-review"class="external-link"target="_blank">`lang-es`</a>.
259
+
260
+
* Review those pull requests, requesting changes or approving them. For the languages I don't speak, I'll wait for several others to review the translation before merging.
257
261
258
262
!!! tip
259
263
You can <ahref="https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request"class="external-link"target="_blank">add comments with change suggestions</a> to existing pull requests.
@@ -262,19 +266,9 @@ Here are the steps to help with translations.
262
266
263
267
* Check if there's a <ahref="https://github.com/tiangolo/fastapi/discussions/categories/translations"class="external-link"target="_blank">GitHub Discussion</a> to coordinate translations for your language. You can subscribe to it, and when there's a new pull request to review, an automatic comment will be added to the discussion.
264
268
265
-
* Add a single pull request per page translated. That will make it much easier for others to review it.
266
-
267
-
For the languages I don't speak, I'll wait for several others to review the translation before merging.
268
-
269
-
* You can also check if there are translations for your language and add a review to them, that will help me know that the translation is correct and I can merge it.
270
-
* You could check in the <ahref="https://github.com/tiangolo/fastapi/discussions/categories/translations"class="external-link"target="_blank">GitHub Discussions</a> for your language.
271
-
* Or you can filter the existing PRs by the ones with the label for your language, for example, for Spanish, the label is <ahref="https://github.com/tiangolo/fastapi/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc+label%3Alang-es+label%3A%22awaiting+review%22"class="external-link"target="_blank">`lang-es`</a>.
269
+
* If you translate pages, add a single pull request per page translated. That will make it much easier for others to review it.
272
270
273
-
* Use the same Python examples and only translate the text in the docs. You don't have to change anything for this to work.
274
-
275
-
* Use the same images, file names, and links. You don't have to change anything for it to work.
276
-
277
-
* To check the 2-letter code for the language you want to translate you can use the table <ahref="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes"class="external-link"target="_blank">List of ISO 639-1 codes</a>.
271
+
* To check the 2-letter code for the language you want to translate, you can use the table <ahref="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes"class="external-link"target="_blank">List of ISO 639-1 codes</a>.
278
272
279
273
#### Existing language
280
274
@@ -317,7 +311,7 @@ $ python ./scripts/docs.py live es
317
311
318
312
Now you can go to <ahref="http://127.0.0.1:8008"class="external-link"target="_blank">http://127.0.0.1:8008</a> and see your changes live.
319
313
320
-
You will see that every language has all the pages. But some pages are not translated and have a notification about the missing translation.
314
+
You will see that every language has all the pages. But some pages are not translated and have an info box at the top, about the missing translation.
321
315
322
316
Now let's say that you want to add a translation for the section [Features](features.md){.internal-link target=_blank}.
323
317
@@ -336,7 +330,7 @@ docs/es/docs/features.md
336
330
!!! tip
337
331
Notice that the only change in the path and file name is the language code, from `en` to `es`.
338
332
339
-
If you go to your browser you will see that now the docs show your new section. 🎉
333
+
If you go to your browser you will see that now the docs show your new section (the info box at the top is gone). 🎉
340
334
341
335
Now you can translate it all and see how it looks as you save the file.
342
336
@@ -380,7 +374,7 @@ You can make the first pull request with those two files, `docs/ht/mkdocs.yml` a
380
374
381
375
#### Preview the result
382
376
383
-
You can use the `./scripts/docs.py` with the `live` command to preview the results (or `mkdocs serve`).
377
+
As already mentioned above, You can use the `./scripts/docs.py` with the `live` command to preview the results (or `mkdocs serve`).
384
378
385
379
Once you are done, you can also test it all as it would look online, including all the other languages.
* Translate only the Markdown documents (`.md`). Do not translate the code examples at `./docs_src`.
417
+
418
+
* In code blocks within the Markdown document, translate comments (`# a comment`), but leave the rest unchanged.
419
+
420
+
* Do not change anything enclosed in "``" (inline code).
421
+
422
+
* In lines starting with `===` or `!!!`, translate only the ` "... Text ..."` part. Leave the rest unchanged.
423
+
424
+
* You can translate info boxes like `!!! warning` with for example `!!! warning "Achtung"`. But do not change the word immediately after the `!!!`, it determines the color of the info box.
425
+
426
+
* Do not change the paths in links to images, code files, Markdown documents.
427
+
428
+
* However, when a Markdown document is translated, the `#hash-parts` in links to its headings may change. Update these links if possible.
429
+
* Search for such links in the translated document using the regex `#[^# ]`.
430
+
* Search in all documents already translated into your language for `your-translated-document.md`. For example VS Code has an option "Edit" -> "Find in Files".
431
+
* When translating a document, do not "pre-translate" `#hash-parts` that link to headings in untranslated documents.
432
+
420
433
## Tests
421
434
422
435
There is a script that you can run locally to test all the code and generate coverage reports in HTML:
0 commit comments