Skip to content
Myr

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

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 27bd56d · Browse files · 23 files+89 added−40 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

23 files+89 added−40 removed

  • other:+89 added−40 removed

23 files+89 added−40 removed

modified:.github/actions/comment-docs-preview-in-pr/app/main.py+1 added-3 removed
46 unmodified lines
47 if pr.head.sha == event.workflow_run.head_commit.id:48 use_pr = pr49 break50 if not use_pr:51 logging.error(52 f"No PR found for hash: {event.workflow_run.head_commit.id}"53 )51 logging.error(f"No PR found for hash: {event.workflow_run.head_commit.id}")52 sys.exit(0)53 github_headers = {54 "Authorization": f"token {settings.input_token.get_secret_value()}"55 }
13 unmodified lines
modified:.github/ISSUE_TEMPLATE/feature-request.yml+4 added-4 removed
modified:.github/ISSUE_TEMPLATE/question.yml+4 added-4 removed
6 unmodified lines
7 value: |8 Thanks for your interest in Typer! 🚀910 Please follow these instructions, fill every question, and do every step. 🙏11 1112 I'm asking this because answering questions and solving problems in GitHub issues is what consumes most of the time.13 1314 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.1516 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.1718 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 😅).1920 By asking questions in a structured way (following this) it will be much easier to help you.21 2122 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. 😎2324 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. 🤓25 - type: checkboxes
19 unmodified lines
45 attributes:46 label: Commit to Help47 description: |48 After submitting this, I commit to one of:49 4950 * Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.51 * 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.52 * Implement a Pull Request for a confirmed bug.53
92 unmodified lines
modified:.github/workflows/build-docs.yml+1 added-1 removed
6 unmodified lines
7 types: [opened, synchronize]8 workflow_dispatch:9 inputs:10 debug_enabled:11 description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' 11 description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'12 required: false13 default: false14jobs:15 build-docs:
57 unmodified lines
modified:.github/workflows/latest-changes.yml+1 added-1 removed
10 unmodified lines
11 number:12 description: PR number13 required: true14 debug_enabled:15 description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' 15 description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'16 required: false17 default: false1819jobs:
19 unmodified lines
modified:.github/workflows/preview-docs.yml+1 added-1 removed
1 unmodified line
2on:3 workflow_run:4 workflows:5 - Build Docs6 types: 6 types:7 - completed89jobs:10 preview-docs:
31 unmodified lines
modified:.github/workflows/test.yml+1 added-1 removed
13 unmodified lines
14 matrix:15 python-version: [3.6, 3.7, 3.8, 3.9]16 click-7: [true, false]17 fail-fast: false18 1819 steps:20 - uses: actions/checkout@v221 - name: Set up Python22 uses: actions/setup-python@v2
16 unmodified lines
modified:docs/img/icon-black.svg+1 added-1 removed
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>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>
modified:docs/js/termynal.js+7 added-7 removed
70 unmodified lines
71 /**72 * Initialise the widget, get lines, clear container and start animation.73 */74 init() {75 /** 75 /**76 * Calculates width and height of Termynal container.77 * If container is empty and lines are dynamically loaded, defaults to browser `auto` or CSS.78 */ 78 */79 const containerStyle = getComputedStyle(this.container);80 this.container.style.width = containerStyle.width !== '0px' ? 80 this.container.style.width = containerStyle.width !== '0px' ?81 containerStyle.width : undefined;82 this.container.style.minHeight = containerStyle.height !== '0px' ? 82 this.container.style.minHeight = containerStyle.height !== '0px' ?83 containerStyle.height : undefined;8485 this.container.setAttribute('data-termynal', '');86 this.container.innerHTML = '';
50 unmodified lines
137 restart.setAttribute('data-terminal-control', '')138 restart.innerHTML = "restart ↻"139 return restart140 }141 141142 generateFinish() {143 const finish = document.createElement('a')144 finish.onclick = (e) => {145 e.preventDefault()
68 unmodified lines
214 }215216 /**217 * Converts line data objects into line elements.218 * 218 *219 * @param {Object[]} lineData - Dynamically loaded lines.220 * @param {Object} line - Line data object.221 * @returns {Element[]} - Array of line elements.222 */
7 unmodified lines
230 }231232 /**233 * Helper function for generating attributes string.234 * 234 *235 * @param {Object} line - Line data object.236 * @returns {string} - String of attributes.237 */238 _attributes(line) {
26 unmodified lines
modified:docs/overrides/main.html+3 added-3 removed
10 unmodified lines
11 });12 });13 });14</script>15<qa-bot 16 server="https://tiangolo-typer.docsqa.jina.ai" 17 theme="infer" 15<qa-bot16 server="https://tiangolo-typer.docsqa.jina.ai"17 theme="infer"18 title="Typer Bot"19 description="Typer, build great CLIs. Easy to code. Based on Python type hints."20 style="font-size: 0.8rem"21>
8 unmodified lines
modified:docs/tutorial/options/name.md+1 added-1 removed
32 unmodified lines
33Here you are passing the string `"--name"` as the second positional argument to `typer.Option()`.3435!!! info36 "<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.37 3738 For example `show_default=True` is a keyword argument. "`show_default`" is the keyword.3940 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.41
287 unmodified lines
modified:docs/tutorial/options/password.md+2 added-2 removed
40 unmodified lines
41```console42$ python main.py Camila4344// It prompts for the password, but doesn't show anything when you type45# Password: $ 46# Repeat for confirmation: $ 45# Password: $46# Repeat for confirmation: $4748// Let's imagine the password typed was "typerrocks"49Hello Camila. Doing something very secure with password.50...just kidding, here it is, very insecure: typerrocks
3 unmodified lines
modified:docs/tutorial/parameter-types/bool.md+1 added-1 removed
149 unmodified lines
150```151152!!! tip153 Have in mind that it's a string with a preceding space and then a `/`.154 154155 So, it's `" /-S"` not `"/-S"`.156157Check it:158
32 unmodified lines
modified:docs/tutorial/parameter-types/number.md+1 added-1 removed
146 unmodified lines
147148Verbose level is 3149```150151</div>151</div>
modified:docs/tutorial/parameter-types/uuid.md+2 added-2 removed
6 unmodified lines
78 ```9 d48edaa6-871a-4082-a196-4daab372d4a110 ```11 1112 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.1314 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.15 1516 This wouldn't be true if you just used `int`s as identifiers, as most databases do.171819
29 unmodified lines
modified:docs/tutorial/subcommands/callback-override.md+1 added-1 removed
99 unmodified lines
100I have the high land! Running users command101Creating user: Camila102```103104</div>104</div>
modified:docs/tutorial/first-steps.md+1 added-1 removed
400 unmodified lines
401402 It's quite technical... and somewhat pedantic.403404 One refers to the variable name in a function *declaration*. Like:405 405406 ```407 def bring_person(name: str, lastname: str = ""):408 pass409 ```
82 unmodified lines
modified:docs/tutorial/launch.md+1 added-1 removed
28 unmodified lines
29```3031!!! tip32 The rest of the code in this example is just making sure the app directory exists and creating the config file.33 3334 But the most important part is the `typer.launch(config_file_str, locate=True)` with the argument `locate=True`.3536Check it:37
11 unmodified lines
modified:docs/tutorial/terminating.md+1 added-1 removed
42 unmodified lines
43!!! tip44 Even though you are rasing an exception, it doesn't necessarily mean there's an error.4546 This is done with an exception because it works as an "error" and stops all execution.47 4748 But then **Typer** (actually Click) catches it and just terminates the program normally.4950## Exit with an error51
67 unmodified lines
modified:docs/features.md+1 added-1 removed
57 unmodified lines
58 * `--install-completion`: Install completion for the current shell.59 * `--show-completion`: Show completion for the current shell, to copy it or customize the installation.6061 If you didn't add `shellingham` those *CLI options* take a value with the name of the shell to install completion for, e.g.:62 6263 * `--install-completion bash`.64 * `--show-completion powershell`.6566 Then you can tell the user to install completion after installing your CLI program and the rest will just work.
19 unmodified lines
modified:typer/testing.py+2 added-2 removed
1from typing import IO, Any, Mapping, Optional, Sequence, Text, Union1from typing import IO, Any, Mapping, Optional, Sequence, Union23from click.testing import CliRunner as ClickCliRunner # noqa4from click.testing import Result5from typer.main import Typer
4 unmodified lines
10 def invoke( # type: ignore11 self,12 app: Typer,13 args: Optional[Union[str, Sequence[str]]] = None,14 input: Optional[Union[bytes, Text, IO[Any]]] = None,14 input: Optional[Union[bytes, str, IO[Any]]] = None,15 env: Optional[Mapping[str, str]] = None,16 catch_exceptions: bool = True,17 color: bool = False,18 **extra: Any,
11 unmodified lines
added:.pre-commit-config.yaml+50 added
1# See https://pre-commit.com for more information2# See https://pre-commit.com/hooks.html for more hooks3repos:4- repo: https://github.com/pre-commit/pre-commit-hooks5 rev: v4.2.06 hooks:7 - id: check-added-large-files8 - id: check-toml9 - id: check-yaml10 args:11 - --unsafe12 - id: end-of-file-fixer13 - id: trailing-whitespace14- repo: https://github.com/asottile/pyupgrade15 rev: v2.32.116 hooks:17 - id: pyupgrade18 args:19 - --py3-plus20 - --keep-runtime-typing21 # This file is more readable without yield from22 exclude: ^docs_src/progressbar/tutorial002\.py23- repo: https://github.com/myint/autoflake24 rev: v1.425 hooks:26 - id: autoflake27 args:28 - --recursive29 - --in-place30 - --remove-all-unused-imports31 - --remove-unused-variables32 - --expand-star-imports33 - --exclude34 - __init__.py35 - --remove-duplicate-keys36- repo: https://github.com/pycqa/isort37 rev: 5.10.138 hooks:39 - id: isort40 name: isort (python)41 - id: isort42 name: isort (cython)43 types: [cython]44 - id: isort45 name: isort (pyi)46 types: [pyi]47- repo: https://github.com/psf/black48 rev: 22.3.049 hooks:50 - id: black
modified:pyproject.toml+1 added
53 unmodified lines
54]55dev = [56 "autoflake >=1.3.1,<2.0.0",57 "flake8 >=3.8.3,<4.0.0",58 "pre-commit >=2.17.0,<3.0.0",59]60all = [61 "colorama >=0.4.3,<0.5.0",62 "shellingham >=1.3.0,<2.0.0"
10 unmodified lines