🔧 Add pre-commit config and formatting (#392)

This commit is contained in:
Sebastián Ramírez 2022-05-11 19:59:56 -05:00 committed by GitHub
parent 27bd56dce1
commit a1ee41186f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 89 additions and 40 deletions

View file

@ -8,9 +8,9 @@ body:
Thanks for your interest in Typer! 🚀
Please follow these instructions, fill every question, and do every step. 🙏
I'm asking this because answering questions and solving problems in GitHub issues is what consumes most of the time.
I end up not being able to add new features, fix bugs, review pull requests, etc. as fast as I wish because I have to spend too much time handling issues.
All that, on top of all the incredible help provided by a bunch of community members that give a lot of their time to come here and help others.
@ -18,7 +18,7 @@ body:
If more Typer users came to help others like them just a little bit more, it would be much less effort for them (and you and me 😅).
By asking questions in a structured way (following this) it will be much easier to help you.
And there's a high chance that you will find the solution along the way and you won't even have to submit it and wait for an answer. 😎
As there are too many issues with questions, I'll have to close the incomplete ones. That will allow me (and others) to focus on helping people like you that follow the whole process and help us help you. 🤓
@ -46,7 +46,7 @@ body:
label: Commit to Help
description: |
After submitting this, I commit to one of:
* Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
* I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
* Implement a Pull Request for a confirmed bug.

View file

@ -8,9 +8,9 @@ body:
Thanks for your interest in Typer! 🚀
Please follow these instructions, fill every question, and do every step. 🙏
I'm asking this because answering questions and solving problems in GitHub issues is what consumes most of the time.
I end up not being able to add new features, fix bugs, review pull requests, etc. as fast as I wish because I have to spend too much time handling issues.
All that, on top of all the incredible help provided by a bunch of community members that give a lot of their time to come here and help others.
@ -18,7 +18,7 @@ body:
If more Typer users came to help others like them just a little bit more, it would be much less effort for them (and you and me 😅).
By asking questions in a structured way (following this) it will be much easier to help you.
And there's a high chance that you will find the solution along the way and you won't even have to submit it and wait for an answer. 😎
As there are too many issues with questions, I'll have to close the incomplete ones. That will allow me (and others) to focus on helping people like you that follow the whole process and help us help you. 🤓
@ -46,7 +46,7 @@ body:
label: Commit to Help
description: |
After submitting this, I commit to one of:
* Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
* I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
* Implement a Pull Request for a confirmed bug.

View file

@ -48,9 +48,7 @@ if __name__ == "__main__":
use_pr = pr
break
if not use_pr:
logging.error(
f"No PR found for hash: {event.workflow_run.head_commit.id}"
)
logging.error(f"No PR found for hash: {event.workflow_run.head_commit.id}")
sys.exit(0)
github_headers = {
"Authorization": f"token {settings.input_token.get_secret_value()}"

View file

@ -8,7 +8,7 @@ on:
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
jobs:

View file

@ -12,7 +12,7 @@ on:
description: PR number
required: true
debug_enabled:
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false

View file

@ -3,7 +3,7 @@ on:
workflow_run:
workflows:
- Build Docs
types:
types:
- completed
jobs:

View file

@ -15,7 +15,7 @@ jobs:
python-version: [3.6, 3.7, 3.8, 3.9]
click-7: [true, false]
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Set up Python

50
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,50 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-added-large-files
- id: check-toml
- id: check-yaml
args:
- --unsafe
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
hooks:
- id: pyupgrade
args:
- --py3-plus
- --keep-runtime-typing
# This file is more readable without yield from
exclude: ^docs_src/progressbar/tutorial002\.py
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args:
- --recursive
- --in-place
- --remove-all-unused-imports
- --remove-unused-variables
- --expand-star-imports
- --exclude
- __init__.py
- --remove-duplicate-keys
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black

View file

@ -59,7 +59,7 @@ The resulting CLI apps created with **Typer** have the nice features of many "pr
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
If you didn't add `shellingham` those *CLI options* take a value with the name of the shell to install completion for, e.g.:
* `--install-completion bash`.
* `--show-completion powershell`.

View file

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M21 3.01H3c-1.1 0-2 .9-2 2V9h2V4.99h18v14.03H3V15H1v4.01c0 1.1.9 1.98 2 1.98h18c1.1 0 2-.88 2-1.98v-14c0-1.11-.9-2-2-2zM11 16l4-4-4-4v3H1v2h10v3z"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M21 3.01H3c-1.1 0-2 .9-2 2V9h2V4.99h18v14.03H3V15H1v4.01c0 1.1.9 1.98 2 1.98h18c1.1 0 2-.88 2-1.98v-14c0-1.11-.9-2-2-2zM11 16l4-4-4-4v3H1v2h10v3z"/></svg>

Before

Width:  |  Height:  |  Size: 283 B

After

Width:  |  Height:  |  Size: 284 B

View file

@ -72,14 +72,14 @@ class Termynal {
* Initialise the widget, get lines, clear container and start animation.
*/
init() {
/**
/**
* Calculates width and height of Termynal container.
* If container is empty and lines are dynamically loaded, defaults to browser `auto` or CSS.
*/
*/
const containerStyle = getComputedStyle(this.container);
this.container.style.width = containerStyle.width !== '0px' ?
this.container.style.width = containerStyle.width !== '0px' ?
containerStyle.width : undefined;
this.container.style.minHeight = containerStyle.height !== '0px' ?
this.container.style.minHeight = containerStyle.height !== '0px' ?
containerStyle.height : undefined;
this.container.setAttribute('data-termynal', '');
@ -138,7 +138,7 @@ class Termynal {
restart.innerHTML = "restart ↻"
return restart
}
generateFinish() {
const finish = document.createElement('a')
finish.onclick = (e) => {
@ -215,7 +215,7 @@ class Termynal {
/**
* Converts line data objects into line elements.
*
*
* @param {Object[]} lineData - Dynamically loaded lines.
* @param {Object} line - Line data object.
* @returns {Element[]} - Array of line elements.
@ -231,7 +231,7 @@ class Termynal {
/**
* Helper function for generating attributes string.
*
*
* @param {Object} line - Line data object.
* @returns {string} - String of attributes.
*/

View file

@ -12,9 +12,9 @@
});
});
</script>
<qa-bot
server="https://tiangolo-typer.docsqa.jina.ai"
theme="infer"
<qa-bot
server="https://tiangolo-typer.docsqa.jina.ai"
theme="infer"
title="Typer Bot"
description="Typer, build great CLIs. Easy to code. Based on Python type hints."
style="font-size: 0.8rem"

View file

@ -402,7 +402,7 @@ are called "Python function parameters" or "Python function arguments".
It's quite technical... and somewhat pedantic.
One refers to the variable name in a function *declaration*. Like:
```
def bring_person(name: str, lastname: str = ""):
pass

View file

@ -30,7 +30,7 @@ You can also make the operating system open the file browser indicating where a
!!! tip
The rest of the code in this example is just making sure the app directory exists and creating the config file.
But the most important part is the `typer.launch(config_file_str, locate=True)` with the argument `locate=True`.
Check it:

View file

@ -34,7 +34,7 @@ Here you are passing the string `"--name"` as the second positional argument to
!!! info
"<a href="https://docs.python.org/3.8/glossary.html#term-argument" class="external-link" target="_blank">Positional</a>" means that it's not a function argument with a keyword name.
For example `show_default=True` is a keyword argument. "`show_default`" is the keyword.
But in `"--name"` there's no `option_name="--name"` or something similar, it's just the string value `"--name"` that goes in `typer.Option()` after the `...` value passed in the first position.

View file

@ -42,8 +42,8 @@ Check it:
$ python main.py Camila
// It prompts for the password, but doesn't show anything when you type
# Password: $
# Repeat for confirmation: $
# Password: $
# Repeat for confirmation: $
// Let's imagine the password typed was "typerrocks"
Hello Camila. Doing something very secure with password.

View file

@ -151,7 +151,7 @@ To do that, use a space and a single `/` and pass the negative name after:
!!! tip
Have in mind that it's a string with a preceding space and then a `/`.
So, it's `" /-S"` not `"/-S"`.
Check it:

View file

@ -148,4 +148,4 @@ $ python main.py -vvv
Verbose level is 3
```
</div>
</div>

View file

@ -8,11 +8,11 @@
```
d48edaa6-871a-4082-a196-4daab372d4a1
```
The way they are generated makes them sufficiently long and random that you could assume that every UUID generated is unique. Even if it was generated by a different application, database, or system.
So, if your system uses UUIDs to identify your data, you could mix it with the data from some other system that also uses UUIDs with some confidence that their IDs (UUIDs) won't clash with yours.
This wouldn't be true if you just used `int`s as identifiers, as most databases do.

View file

@ -101,4 +101,4 @@ I have the high land! Running users command
Creating user: Camila
```
</div>
</div>

View file

@ -44,7 +44,7 @@ The user already exists
Even though you are rasing an exception, it doesn't necessarily mean there's an error.
This is done with an exception because it works as an "error" and stops all execution.
But then **Typer** (actually Click) catches it and just terminates the program normally.
## Exit with an error

View file

@ -55,6 +55,7 @@ doc = [
dev = [
"autoflake >=1.3.1,<2.0.0",
"flake8 >=3.8.3,<4.0.0",
"pre-commit >=2.17.0,<3.0.0",
]
all = [
"colorama >=0.4.3,<0.5.0",

View file

@ -1,4 +1,4 @@
from typing import IO, Any, Mapping, Optional, Sequence, Text, Union
from typing import IO, Any, Mapping, Optional, Sequence, Union
from click.testing import CliRunner as ClickCliRunner # noqa
from click.testing import Result
@ -11,7 +11,7 @@ class CliRunner(ClickCliRunner):
self,
app: Typer,
args: Optional[Union[str, Sequence[str]]] = None,
input: Optional[Union[bytes, Text, IO[Any]]] = None,
input: Optional[Union[bytes, str, IO[Any]]] = None,
env: Optional[Mapping[str, str]] = None,
catch_exceptions: bool = True,
color: bool = False,