:bug: Fix Bash completion install to .bashrc (#81)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* :bug: Fix Bash completion setup to .bashrc * :memo: Update docs and script for Windows development environment
authored by Sebastián Ramírez · committed by GitHub · parent b28f920 · Browse files · 5 files·+74 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+74 added−9 removed
- tests:+2 added−2 removed
- other:+72 added−7 removed
Provenance
- Commit
d90344d- Tree
804aa14- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
b28f920
5 files changed+74 added−9 removed
modified:docs/contributing.md+70 added-5 removed
6 unmodified lines789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081823 unmodified lines86878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281296 unmodified lines1361371381391401411421431441451461471481499815015110010110210315215315415515615715815916016116216316416516616720 unmodified lines1881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232247 unmodified lines6 unmodified lines### Virtual environment with `venv`
You can create a virtual environment in a directory using Python's `venv` module:
<div class="termy">
```console$ python -m venv env```
</div>
That 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:
<div class="termy">
```console$ source ./env/bin/activate```
</div>
Or in Windows' PowerShell:
<div class="termy">
```console$ .\env\Scripts\Activate.ps1```
</div>
Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):
<div class="termy">
```console$ source ./env/Scripts/activate```
</div>
To check it worked, use:
<div class="termy">
```console$ which pip
some/directory/typer/env/bin/pip```
</div>
If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉
Or in Windows PowerShell:
<div class="termy">
```console$ Get-Command pip
some/directory/typer/env/bin/pip```
</div>
!!! 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.3 unmodified lines**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.
After activating the environment as described above, install `flit`:
<div class="termy">
```console$ pip install flit
---> 100%```
</div>
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:
<div class="termy">
```console$ flit install --deps develop --symlink
---> 100%```
</div>
If you are on Windows, use `--pth-file` instead of `--symlink`:
<div class="termy">
```console$ flit install --deps develop --pth-file
---> 100%```
</div>
It will install all the dependencies and your local Typer in your local environment.
#### Using your local Typer
6 unmodified lines### Format
There is a script that you can run that will format and clean all your code:
<div class="termy">
```console$ bash scripts/format.sh```
</div>
It will also auto-sort all your imports.
For it to sort them correctly, you need to have Typer 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 using `--symlink` (or `--pth-file` on Windows).
```console$ flit install --symlink```
### Format imports
There is another script that formats all the imports and makes sure you don't have unused imports:
<div class="termy">
```console$ bash scripts/format-imports.sh```
</div>
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
20 unmodified lines* 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:
<div class="termy">
```console$ bash scripts/docs-live.sh
<span style="color: green;">[INFO]</span> - Building documentation...<span style="color: green;">[INFO]</span> - Cleaning site directory<span style="color: green;">[INFO]</span> - Documentation built in 2.74 seconds<span style="color: green;">[INFO]</span> - Serving on http://127.0.0.1:8008```
</div>
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.
## Tests
There is a script that you can run locally to test all the code and generate coverage reports in HTML:
<div class="termy">
```console$ bash scripts/test-cov-html.sh```
</div>
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
7 unmodified linesmodified:scripts/docs-live.sh+1 added-1 removed
1 #!/usr/bin/env bash2 3 set -e4 5-mkdocs serve --dev-addr 0.0.0.0:80085+mkdocs serve --dev-addr 127.0.0.1:8008modified:tests/test_completion/test_completion_install.py+1 added-1 removed
28 unmodified lines29 assert "Error: --install-completion option requires an argument" in result.stderr30 31 32 def test_completion_install_bash():33- bash_completion_path: Path = Path.home() / ".bash_completion"33+ bash_completion_path: Path = Path.home() / ".bashrc"34 text = ""35 if bash_completion_path.is_file():36 text = bash_completion_path.read_text()37 result = subprocess.run(103 unmodified linesmodified:tests/test_completion/test_completion.py+1 added-1 removed
20 unmodified lines21 assert "_TUTORIAL001.PY_COMPLETE=complete_bash" in result.stdout22 23 24 def test_install_completion():25- bash_completion_path: Path = Path.home() / ".bash_completion"25+ bash_completion_path: Path = Path.home() / ".bashrc"26 text = ""27 if bash_completion_path.is_file(): # pragma: nocover28 text = bash_completion_path.read_text()29 result = subprocess.run(145 unmodified linesmodified:typer/completion.py+1 added-1 removed
164 unmodified lines165 if shell is None and shellingham is not None:166 shell, _ = shellingham.detect_shell()167 mode = None168 if shell == "bash":169- path_obj = Path.home() / ".bash_completion"169+ path_obj = Path.home() / ".bashrc"170 mode = mode or "a"171 elif shell == "zsh":172 path_obj = Path.home() / ".zshrc"173 mode = mode or "a"224 unmodified lines