From 85454922c11ff6a7746f5d1524eaa1c415c84ae7 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Fri, 9 Sep 2022 09:51:29 -0800 Subject: [PATCH 1/2] build: auto-sort/format imports with isort --- .pre-commit-config.yaml | 5 +++++ pyproject.toml | 5 +++++ setup.cfg | 1 + 3 files changed, 11 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e06bdc..d84af98 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,3 +7,8 @@ repos: rev: 22.8.0 hooks: - id: black + - repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort + name: isort (python) diff --git a/pyproject.toml b/pyproject.toml index ebd8232..907373f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,3 +3,8 @@ requires = ['setuptools', 'wheel'] [tool.pytest.ini_options] testpaths = ["./tests"] + +[tool.isort] +profile = "black" +# Place each import on its own line to reduce merge conflicts +force_single_line = true diff --git a/setup.cfg b/setup.cfg index 100fa0c..0ea611c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,6 +37,7 @@ dev = black build flake8 + isort mypy pre-commit pytest From bcf3fd930bbfc153414b51a8f14d8495f70fa2d0 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Fri, 9 Sep 2022 09:55:10 -0800 Subject: [PATCH 2/2] style: format imports everywhere with isort --- docopt/__init__.py | 13 +++++--- examples/arguments_example.py | 1 - examples/calculator_example.py | 1 - examples/counted_example.py | 1 - examples/git/git.py | 1 - examples/git/git_add.py | 1 - examples/git/git_branch.py | 1 - examples/git/git_checkout.py | 1 - examples/git/git_clone.py | 1 - examples/git/git_commit.py | 1 - examples/git/git_push.py | 1 - examples/git/git_remote.py | 1 - examples/interactive_example.py | 6 ++-- examples/naval_fate.py | 1 - examples/odd_even_example.py | 1 - examples/options_example.py | 1 - examples/options_shortcut_example.py | 1 - examples/quick_example.py | 1 - examples/validation_example.py | 6 +++- tests/conftest.py | 8 +++-- tests/test_docopt.py | 50 ++++++++++++++-------------- tests/test_docopt_ng.py | 12 +++++-- 22 files changed, 57 insertions(+), 54 deletions(-) diff --git a/docopt/__init__.py b/docopt/__init__.py index 0672aea..8f20a57 100644 --- a/docopt/__init__.py +++ b/docopt/__init__.py @@ -23,11 +23,16 @@ """ from __future__ import annotations -import sys -import re import inspect - -from typing import Any, Callable, NamedTuple, cast, Type, Tuple, Union +import re +import sys +from typing import Any +from typing import Callable +from typing import NamedTuple +from typing import Tuple +from typing import Type +from typing import Union +from typing import cast __all__ = ["docopt", "magic_docopt", "magic", "DocoptExit"] __version__ = "0.8.1" diff --git a/examples/arguments_example.py b/examples/arguments_example.py index 696e9fc..2471726 100644 --- a/examples/arguments_example.py +++ b/examples/arguments_example.py @@ -19,7 +19,6 @@ """ from docopt import docopt - if __name__ == "__main__": arguments = docopt(__doc__) print(arguments) diff --git a/examples/calculator_example.py b/examples/calculator_example.py index eb0b066..9a3574b 100644 --- a/examples/calculator_example.py +++ b/examples/calculator_example.py @@ -16,7 +16,6 @@ """ from docopt import docopt - if __name__ == "__main__": arguments = docopt(__doc__) print(arguments) diff --git a/examples/counted_example.py b/examples/counted_example.py index 58ffe5e..b384857 100644 --- a/examples/counted_example.py +++ b/examples/counted_example.py @@ -12,5 +12,4 @@ """ from docopt import docopt - print(docopt(__doc__)) diff --git a/examples/git/git.py b/examples/git/git.py index bc79067..6772c15 100755 --- a/examples/git/git.py +++ b/examples/git/git.py @@ -27,7 +27,6 @@ from docopt import docopt - if __name__ == "__main__": args = docopt(__doc__, version="git version 1.7.4.4", options_first=True) diff --git a/examples/git/git_add.py b/examples/git/git_add.py index a230a55..1e255b9 100644 --- a/examples/git/git_add.py +++ b/examples/git/git_add.py @@ -18,6 +18,5 @@ """ from docopt import docopt - if __name__ == "__main__": print(docopt(__doc__)) diff --git a/examples/git/git_branch.py b/examples/git/git_branch.py index 24d028b..86b8e41 100644 --- a/examples/git/git_branch.py +++ b/examples/git/git_branch.py @@ -28,6 +28,5 @@ """ from docopt import docopt - if __name__ == "__main__": print(docopt(__doc__)) diff --git a/examples/git/git_checkout.py b/examples/git/git_checkout.py index 56a4faa..9ac09cf 100644 --- a/examples/git/git_checkout.py +++ b/examples/git/git_checkout.py @@ -18,6 +18,5 @@ """ from docopt import docopt - if __name__ == "__main__": print(docopt(__doc__)) diff --git a/examples/git/git_clone.py b/examples/git/git_clone.py index 5f99198..0d05035 100644 --- a/examples/git/git_clone.py +++ b/examples/git/git_clone.py @@ -25,6 +25,5 @@ """ from docopt import docopt - if __name__ == "__main__": print(docopt(__doc__)) diff --git a/examples/git/git_commit.py b/examples/git/git_commit.py index 3b3e732..307f5c7 100644 --- a/examples/git/git_commit.py +++ b/examples/git/git_commit.py @@ -45,6 +45,5 @@ """ from docopt import docopt - if __name__ == "__main__": print(docopt(__doc__)) diff --git a/examples/git/git_push.py b/examples/git/git_push.py index 4e00cea..fb0a2a9 100644 --- a/examples/git/git_push.py +++ b/examples/git/git_push.py @@ -22,6 +22,5 @@ """ from docopt import docopt - if __name__ == "__main__": print(docopt(__doc__)) diff --git a/examples/git/git_remote.py b/examples/git/git_remote.py index 7f756e8..d7878cd 100644 --- a/examples/git/git_remote.py +++ b/examples/git/git_remote.py @@ -17,7 +17,6 @@ """ from docopt import docopt - if __name__ == "__main__": arguments = docopt(__doc__) print(arguments) diff --git a/examples/interactive_example.py b/examples/interactive_example.py index 571a4d5..ac36717 100644 --- a/examples/interactive_example.py +++ b/examples/interactive_example.py @@ -15,9 +15,11 @@ --baud= Baudrate [default: 9600] """ -import sys import cmd -from docopt import docopt, DocoptExit +import sys + +from docopt import DocoptExit +from docopt import docopt def docopt_cmd(func): diff --git a/examples/naval_fate.py b/examples/naval_fate.py index 32e1173..31a5c36 100644 --- a/examples/naval_fate.py +++ b/examples/naval_fate.py @@ -18,7 +18,6 @@ """ from docopt import docopt - if __name__ == "__main__": arguments = docopt(__doc__, version="Naval Fate 2.0") print(arguments) diff --git a/examples/odd_even_example.py b/examples/odd_even_example.py index 5b290ca..ac0eb04 100644 --- a/examples/odd_even_example.py +++ b/examples/odd_even_example.py @@ -9,7 +9,6 @@ """ from docopt import docopt - if __name__ == "__main__": arguments = docopt(__doc__) print(arguments) diff --git a/examples/options_example.py b/examples/options_example.py index 1f307b4..1510549 100644 --- a/examples/options_example.py +++ b/examples/options_example.py @@ -33,7 +33,6 @@ """ from docopt import docopt - if __name__ == "__main__": arguments = docopt(__doc__, version="1.0.0rc2") print(arguments) diff --git a/examples/options_shortcut_example.py b/examples/options_shortcut_example.py index 2ebf3ba..797bf24 100644 --- a/examples/options_shortcut_example.py +++ b/examples/options_shortcut_example.py @@ -14,7 +14,6 @@ """ from docopt import docopt - if __name__ == "__main__": arguments = docopt(__doc__, version="1.0.0rc2") print(arguments) diff --git a/examples/quick_example.py b/examples/quick_example.py index 5f9e3da..9fe8022 100644 --- a/examples/quick_example.py +++ b/examples/quick_example.py @@ -6,7 +6,6 @@ """ from docopt import docopt - if __name__ == "__main__": arguments = docopt(__doc__, version="0.1.1rc") print(arguments) diff --git a/examples/validation_example.py b/examples/validation_example.py index 58f3603..3006f9a 100644 --- a/examples/validation_example.py +++ b/examples/validation_example.py @@ -13,7 +13,11 @@ from docopt import docopt try: - from schema import Schema, And, Or, Use, SchemaError + from schema import And + from schema import Or + from schema import Schema + from schema import SchemaError + from schema import Use except ImportError: exit( "This example requires that `schema` data-validation library" diff --git a/tests/conftest.py b/tests/conftest.py index 552f10b..43c2dfc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,12 +1,14 @@ import json -from pathlib import Path import re -from typing import Generator, Sequence +from pathlib import Path +from typing import Generator +from typing import Sequence from unittest import mock -import docopt import pytest +import docopt + def pytest_collect_file(file_path: Path, path, parent): if file_path.suffix == ".docopt" and file_path.stem.startswith("test"): diff --git a/tests/test_docopt.py b/tests/test_docopt.py index e1ecc13..0c7d5f9 100644 --- a/tests/test_docopt.py +++ b/tests/test_docopt.py @@ -1,35 +1,35 @@ from __future__ import annotations -from typing import Sequence + import re from textwrap import dedent +from typing import Sequence -from docopt import ( - ParsedOptions, - docopt, - DocoptExit, - DocoptLanguageError, - Option, - Argument, - Command, - OptionsShortcut, - Required, - NotRequired, - Either, - OneOrMore, - lint_docstring, - parse_argv, - parse_docstring_sections, - parse_longer, - parse_options, - parse_pattern, - parse_shorts, - formal_usage, - Tokens, - transform, -) import pytest from pytest import raises +from docopt import Argument +from docopt import Command +from docopt import DocoptExit +from docopt import DocoptLanguageError +from docopt import Either +from docopt import NotRequired +from docopt import OneOrMore +from docopt import Option +from docopt import OptionsShortcut +from docopt import ParsedOptions +from docopt import Required +from docopt import Tokens +from docopt import docopt +from docopt import formal_usage +from docopt import lint_docstring +from docopt import parse_argv +from docopt import parse_docstring_sections +from docopt import parse_longer +from docopt import parse_options +from docopt import parse_pattern +from docopt import parse_shorts +from docopt import transform + def test_pattern_flat(): assert Required(OneOrMore(Argument("N")), Option("-a"), Argument("M")).flat() == [ diff --git a/tests/test_docopt_ng.py b/tests/test_docopt_ng.py index 43b1cf3..809c482 100644 --- a/tests/test_docopt_ng.py +++ b/tests/test_docopt_ng.py @@ -1,10 +1,16 @@ import pytest -import docopt -from docopt import DocoptExit, DocoptLanguageError, Option, Argument, parse_argv, Tokens from pytest import raises + +import docopt +from docopt import Argument +from docopt import DocoptExit +from docopt import DocoptLanguageError +from docopt import Option +from docopt import Tokens +from docopt import docopt as user_provided_alias_containing_magic from docopt import magic from docopt import magic_docopt -from docopt import docopt as user_provided_alias_containing_magic +from docopt import parse_argv def test_docopt_ng_more_magic_spellcheck_and_expansion():