🔧 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
Provenance
- Commit
a1ee411- Tree
a9caf57- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
27bd56d
23 files changed+89 added−40 removed
modified:.github/actions/comment-docs-preview-in-pr/app/main.py+1 added-3 removed
46 unmodified lines47 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 linesmodified:.github/ISSUE_TEMPLATE/feature-request.yml+4 added-4 removed
6 unmodified lines7891011111213131415161718192021212223242519 unmodified lines45464748494950515253126 unmodified linesExpand all6 unmodified lines value: | 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.
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. 🤓 - type: checkboxes19 unmodified lines attributes: 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.
126 unmodified linesExpand allmodified:.github/ISSUE_TEMPLATE/question.yml+4 added-4 removed
6 unmodified lines7 value: |8 Thanks for your interest in Typer! 🚀9 10 Please follow these instructions, fill every question, and do every step. 🙏11- 11+12 I'm asking this because answering questions and solving problems in GitHub issues is what consumes most of the time.13- 13+14 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.15 16 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.17 18 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 😅).19 20 By asking questions in a structured way (following this) it will be much easier to help you.21- 21+22 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. 😎23 24 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: checkboxes19 unmodified lines45 attributes:46 label: Commit to Help47 description: |48 After submitting this, I commit to one of:49- 49+50 * 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 linesmodified:.github/workflows/build-docs.yml+1 added-1 removed
6 unmodified lines7 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: false14 jobs:15 build-docs:57 unmodified linesmodified:.github/workflows/latest-changes.yml+1 added-1 removed
10 unmodified lines11 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: false18 19 jobs:19 unmodified linesmodified:.github/workflows/preview-docs.yml+1 added-1 removed
1 unmodified line2 on:3 workflow_run:4 workflows:5 - Build Docs6- types: 6+ types:7 - completed8 9 jobs:10 preview-docs:31 unmodified linesmodified:.github/workflows/test.yml+1 added-1 removed
13 unmodified lines14 matrix:15 python-version: [3.6, 3.7, 3.8, 3.9]16 click-7: [true, false]17 fail-fast: false18- 18+19 steps:20 - uses: actions/checkout@v221 - name: Set up Python22 uses: actions/setup-python@v216 unmodified linesmodified: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 lines71 /**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;84 85 this.container.setAttribute('data-termynal', '');86 this.container.innerHTML = '';50 unmodified lines137 restart.setAttribute('data-terminal-control', '')138 restart.innerHTML = "restart ↻"139 return restart140 }141- 141+142 generateFinish() {143 const finish = document.createElement('a')144 finish.onclick = (e) => {145 e.preventDefault()68 unmodified lines214 }215 216 /**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 lines230 }231 232 /**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 linesmodified:docs/overrides/main.html+3 added-3 removed
10 unmodified lines11 });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 linesmodified:docs/tutorial/options/name.md+1 added-1 removed
32 unmodified lines33 Here you are passing the string `"--name"` as the second positional argument to `typer.Option()`.34 35 !!! 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- 37+38 For example `show_default=True` is a keyword argument. "`show_default`" is the keyword.39 40 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 linesmodified:docs/tutorial/options/password.md+2 added-2 removed
40 unmodified lines41 ```console42 $ python main.py Camila43 44 // It prompts for the password, but doesn't show anything when you type45-# Password: $ 46-# Repeat for confirmation: $ 45+# Password: $46+# Repeat for confirmation: $47 48 // Let's imagine the password typed was "typerrocks"49 Hello Camila. Doing something very secure with password.50 ...just kidding, here it is, very insecure: typerrocks3 unmodified linesmodified:docs/tutorial/parameter-types/bool.md+1 added-1 removed
149 unmodified lines150 ```151 152 !!! tip153 Have in mind that it's a string with a preceding space and then a `/`.154- 154+155 So, it's `" /-S"` not `"/-S"`.156 157 Check it:158 32 unmodified linesmodified:docs/tutorial/parameter-types/number.md+1 added-1 removed
146 unmodified lines147 148 Verbose level is 3149 ```150 151-</div>151+</div>modified:docs/tutorial/parameter-types/uuid.md+2 added-2 removed
6 unmodified lines7 8 ```9 d48edaa6-871a-4082-a196-4daab372d4a110 ```11- 11+12 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.13 14 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- 15+16 This wouldn't be true if you just used `int`s as identifiers, as most databases do.17 18 19 29 unmodified linesmodified:docs/tutorial/subcommands/callback-override.md+1 added-1 removed
99 unmodified lines100 I have the high land! Running users command101 Creating user: Camila102 ```103 104-</div>104+</div>modified:docs/tutorial/first-steps.md+1 added-1 removed
400 unmodified lines401 402 It's quite technical... and somewhat pedantic.403 404 One refers to the variable name in a function *declaration*. Like:405- 405+406 ```407 def bring_person(name: str, lastname: str = ""):408 pass409 ```82 unmodified linesmodified:docs/tutorial/launch.md+1 added-1 removed
28 unmodified lines29 ```30 31 !!! tip32 The rest of the code in this example is just making sure the app directory exists and creating the config file.33- 33+34 But the most important part is the `typer.launch(config_file_str, locate=True)` with the argument `locate=True`.35 36 Check it:37 11 unmodified linesmodified:docs/tutorial/terminating.md+1 added-1 removed
42 unmodified lines43 !!! tip44 Even though you are rasing an exception, it doesn't necessarily mean there's an error.45 46 This is done with an exception because it works as an "error" and stops all execution.47- 47+48 But then **Typer** (actually Click) catches it and just terminates the program normally.49 50 ## Exit with an error51 67 unmodified linesmodified:docs/features.md+1 added-1 removed
57 unmodified lines58 * `--install-completion`: Install completion for the current shell.59 * `--show-completion`: Show completion for the current shell, to copy it or customize the installation.60 61 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- 62+63 * `--install-completion bash`.64 * `--show-completion powershell`.65 66 Then you can tell the user to install completion after installing your CLI program and the rest will just work.19 unmodified linesmodified:typer/testing.py+2 added-2 removed
1-from typing import IO, Any, Mapping, Optional, Sequence, Text, Union1+from typing import IO, Any, Mapping, Optional, Sequence, Union2 3 from click.testing import CliRunner as ClickCliRunner # noqa4 from click.testing import Result5 from typer.main import Typer4 unmodified lines10 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 linesadded:.pre-commit-config.yaml+50 added
1+# See https://pre-commit.com for more information2+# See https://pre-commit.com/hooks.html for more hooks3+repos: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: blackmodified:pyproject.toml+1 added
53 unmodified lines54 ]55 dev = [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 ]60 all = [61 "colorama >=0.4.3,<0.5.0",62 "shellingham >=1.3.0,<2.0.0"10 unmodified lines