diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml index 2b7f2d3..faa58a6 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yml +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -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. diff --git a/.github/ISSUE_TEMPLATE/question.yml b/.github/ISSUE_TEMPLATE/question.yml index e947e09..62ea9eb 100644 --- a/.github/ISSUE_TEMPLATE/question.yml +++ b/.github/ISSUE_TEMPLATE/question.yml @@ -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. diff --git a/.github/actions/comment-docs-preview-in-pr/app/main.py b/.github/actions/comment-docs-preview-in-pr/app/main.py index 3b10e0e..c9fb7cb 100644 --- a/.github/actions/comment-docs-preview-in-pr/app/main.py +++ b/.github/actions/comment-docs-preview-in-pr/app/main.py @@ -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()}" diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index a5973f1..a2cbf05 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -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: diff --git a/.github/workflows/latest-changes.yml b/.github/workflows/latest-changes.yml index e22efd8..d7f138f 100644 --- a/.github/workflows/latest-changes.yml +++ b/.github/workflows/latest-changes.yml @@ -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 diff --git a/.github/workflows/preview-docs.yml b/.github/workflows/preview-docs.yml index e335e81..4765679 100644 --- a/.github/workflows/preview-docs.yml +++ b/.github/workflows/preview-docs.yml @@ -3,7 +3,7 @@ on: workflow_run: workflows: - Build Docs - types: + types: - completed jobs: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 783485e..6eec01b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5bcd094 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/docs/features.md b/docs/features.md index b569ab2..6b2bbb2 100644 --- a/docs/features.md +++ b/docs/features.md @@ -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`. diff --git a/docs/img/icon-black.svg b/docs/img/icon-black.svg index 1cba56b..bc987f3 100644 --- a/docs/img/icon-black.svg +++ b/docs/img/icon-black.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/docs/js/termynal.js b/docs/js/termynal.js index 8b0e933..4ac3270 100644 --- a/docs/js/termynal.js +++ b/docs/js/termynal.js @@ -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. */ diff --git a/docs/overrides/main.html b/docs/overrides/main.html index 92574b9..7e501ba 100644 --- a/docs/overrides/main.html +++ b/docs/overrides/main.html @@ -12,9 +12,9 @@ }); }); -Positional" 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. diff --git a/docs/tutorial/options/password.md b/docs/tutorial/options/password.md index 2d5e1de..2d2840f 100644 --- a/docs/tutorial/options/password.md +++ b/docs/tutorial/options/password.md @@ -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. diff --git a/docs/tutorial/parameter-types/bool.md b/docs/tutorial/parameter-types/bool.md index 1d69f47..1f493ec 100644 --- a/docs/tutorial/parameter-types/bool.md +++ b/docs/tutorial/parameter-types/bool.md @@ -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: diff --git a/docs/tutorial/parameter-types/number.md b/docs/tutorial/parameter-types/number.md index 4d29ea3..d41322d 100644 --- a/docs/tutorial/parameter-types/number.md +++ b/docs/tutorial/parameter-types/number.md @@ -148,4 +148,4 @@ $ python main.py -vvv Verbose level is 3 ``` - \ No newline at end of file + diff --git a/docs/tutorial/parameter-types/uuid.md b/docs/tutorial/parameter-types/uuid.md index 242c206..0042f47 100644 --- a/docs/tutorial/parameter-types/uuid.md +++ b/docs/tutorial/parameter-types/uuid.md @@ -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. diff --git a/docs/tutorial/subcommands/callback-override.md b/docs/tutorial/subcommands/callback-override.md index 341de95..6a2683e 100644 --- a/docs/tutorial/subcommands/callback-override.md +++ b/docs/tutorial/subcommands/callback-override.md @@ -101,4 +101,4 @@ I have the high land! Running users command Creating user: Camila ``` - \ No newline at end of file + diff --git a/docs/tutorial/terminating.md b/docs/tutorial/terminating.md index b227ac5..93443d8 100644 --- a/docs/tutorial/terminating.md +++ b/docs/tutorial/terminating.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 1d99888..224a4d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/typer/testing.py b/typer/testing.py index 409a199..720cd81 100644 --- a/typer/testing.py +++ b/typer/testing.py @@ -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,