:memo: Add contributing guide (#61)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by GitHub · parent 51e272a · Browse files · 1 file·+88 added−47 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+88 added−47 removed
- other:+88 added−47 removed
Provenance
- Commit
dd72411- Tree
53304c9- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
51e272a
1 file changed+88 added−47 removed
modified:docs/contributing.md+88 added-47 removed
1233456567810910121112131414151516171819202122232418252620212728293031322533343536273738394041304243443245463447483649505138395253544255565758594560614762634964655166676869707172737475767778798081828384858687888990915859929394959697649899666710010110210310410571106107731081091101111121131141151161171181191201212 unmodified lines1241251261271281298687130131132133134135941361371381399899140141142143102144145146147106148149108150151110111152153154155114156157158159117160161119162163121122164165166124125First, you might want to see the basic ways to [help Typer and get help](help-typer.md){.internal-link target=_blank}.
Coming soon...## Developing
<!-- ## Developing
If you already cloned the repository and you know that you need to deep dive in the code, here are some guidelines to set up your environment.
### Virtual environment with `venv`
### PipenvYou can create a virtual environment in a directory using Python's `venv` module:
If you are using <a href="https://pipenv.readthedocs.io/en/latest/" target="_blank">Pipenv</a>, you can create a virtual environment and install the packages with:```console$ python -m venv env```
```bashpipenv install --devThat will create a directory `./env/` with the Python binaries and then you will be able to install packages for that isolated environment.
### Activate the environment
Activate the new environment with:
```console$ source ./env/bin/activate```
Then you can activate that virtual environment with:Or in Windows' PowerShell:
```bashpipenv shell```console$ .\env\Scripts\Activate.ps1```
Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):
### No Pipenv```console$ source ./env/Scripts/activate```
If you are not using Pipenv, you can create a virtual environment with your preferred tool, and install the packages listed in the file `Pipfile`.To check it worked, use:
```console$ which pip
### Flitsome/directory/typer/env/bin/pip```
**FastAPI** uses <a href="https://flit.readthedocs.io/en/latest/index.html" target="_blank">Flit</a> to build, package and publish the project.If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉
If you installed the development dependencies with one of the methods above, you already have the `flit` command.Or in Windows PowerShell:
To install your local version of FastAPI as a package in your local environment, run:```console$ Get-Command pip
```bashflit install --symlinksome/directory/typer/env/bin/pip```
It will install your local FastAPI in your local environment.!!! tip Every time you install a new package with `pip` under that environment, activate the environment again.
This makes sure that if you use a terminal program installed by that package (like `flit`), you use the one from your local environment and not any other that could be installed globally.
#### Using your local FastAPI### Flit
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.**Typer** uses <a href="https://flit.readthedocs.io/en/latest/index.html" class="external-link" target="_blank">Flit</a> to build, package and publish the project.
And if you update that local FastAPI source code, as it is installed with `--symlink`, when you run that Python file again, it will use the fresh version of FastAPI you just edited.After activating the environment as described above, install `flit`:
That way, you don't have to "install" your local version to be able to test every change.```console$ pip install flit```
Now re-activate the environment to make sure you are using the `flit` you just installed (and not a global one).
And now use `flit` to install the development dependencies:
```console$ flit install --deps develop --symlink```
It will install all the dependencies and your local Typer in your local environment.
#### Using your local Typer
If you create a Python file that imports and uses Typer, and run it with the Python from your local environment, it will use your local Typer source code.
And if you update that local Typer source code, as it is installed with `--symlink`, when you run that Python file again, it will use the fresh version of Typer you just edited.
That way, you don't have to "install" your local version to be able to test every change.
### Format
There is a script that you can run that will format and clean all your code:
```bashbash scripts/lint.sh```console$ bash scripts/format.sh```
It will also auto-sort all your imports.
For it to sort them correctly, you need to have FastAPI installed locally in your environment, with the command in the section above:For it to sort them correctly, you need to have Typer installed locally in your environment, with the command in the section above:
```bashflit install --symlink```console$ flit install --symlink```
### Format imports
### DocsThere is another script that formats all the imports and makes sure you don't have unused imports:
The documentation uses <a href="https://www.mkdocs.org/" target="_blank">MkDocs</a>.```console$ bash scripts/format-imports.sh```
As it runs one command after the other and modifies and reverts many files, it takes a bit longer to run, so it might be easier to use `scripts/format.sh` frequently and `scripts/format-imports.sh` only before committing.
## Docs
The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a>.
All the documentation is in Markdown format in the directory `./docs`.
Many of the tutorials have blocks of code.
2 unmodified linesIn fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs/src/` directory.
And those Python files are included/injected in the documentation when generating the site.
### Docs for tests
#### Docs for tests
Most of the tests actually run against the example source files in the documentation.
This helps making sure that:
* The documentation is up to date.* The documentation examples can be run as is.* Most of the features are covered by the documentation, ensured by the coverage tests.* Most of the features are covered by the documentation, ensured by test coverage.
During local development, there is a script that builds the site and checks for any changes, live-reloading:
```bashbash scripts/docs-live.sh```console$ bash scripts/docs-live.sh```
It will serve the documentation on `http://0.0.0.0:8008`.It will serve the documentation on `http://127.0.0.1:8008`.
That way, you can edit the documentation/source files and see the changes live.
#### Apps and docs at the same time## Tests
And if you run the examples with, e.g.:There is a script that you can run locally to test all the code and generate coverage reports in HTML:
```bashuvicorn tutorial001:app --reload```console$ bash scripts/test-cov-html.sh```
as Uvicorn by default will use the port `8000`, the documentation on port `8008` won't clash.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.
### Tests in your editor
### TestsIf you want to use the integrated tests in your editor add `./docs/src` to your `PYTHONPATH` variable.
There is a script that you can run locally to test all the code and generate coverage reports in HTML:For example, in VS Code you can create a file `.env` with:
```bashbash scripts/test-cov-html.sh```envPYTHONPATH=./docs/src```
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. -->