From 51db36d29597b736169211b6f55e5a6ad477affb Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 31 Jul 2020 22:14:54 -0700 Subject: [PATCH] Improved handling of deprecated single line variables for usage with Visual Studio Code (issue #1363) --- CHANGELOG.md | 1 + isort/main.py | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/test_main.py | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa41fcf80..18ac1a36b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ NOTE: isort follows the [semver](https://semver.org/) versioning standard. ### 5.3.0 TBD - Implemented ability to treat all or select comments as code (issue #1357) + - Improved handling of deprecated single line variables for usage with Visual Studio Code (issue #1363) ### 5.2.2 July 30, 2020 - Fixed #1356: return status when arguments are passed in without files or a content stream. diff --git a/isort/main.py b/isort/main.py index 8ba5dba06..e26a56262 100644 --- a/isort/main.py +++ b/isort/main.py @@ -23,6 +23,35 @@ pass shebang_re = re.compile(br"^#!.*\bpython[23w]?\b") +DEPRECATED_SINGLE_DASH_ARGS = { + "-ac", + "-af", + "-ca", + "-cs", + "-df", + "-ds", + "-dt", + "-fas", + "-fass", + "-ff", + "-fgw", + "-fss", + "-lai", + "-lbt", + "-le", + "-ls", + "-nis", + "-nlb", + "-ot", + "-rr", + "-sd", + "-sg", + "-sl", + "-sp", + "-tc", + "-wl", + "-ws", +} QUICK_GUIDE = f""" {ASCII_ART} @@ -696,10 +725,24 @@ def _build_arg_parser() -> argparse.ArgumentParser: const="--keep-direct-and-as", help=argparse.SUPPRESS, ) + return parser def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]: + argv = sys.argv[1:] if argv is None else list(argv) + for index, arg in enumerate(argv): + if arg in DEPRECATED_SINGLE_DASH_ARGS: + warn( + f"\n\nThe following deprecated single dash CLI flags was used: {arg}!\n" + f"It is being auto translated to -{arg} to maintain backward compatibility.\n" + f"This behavior will be REMOVED in the 6.x.x release and is not guaranteed across" + f" 5.x.x releases.\n\n" + "Please see the 5.0.0 upgrade guide:\n" + "\thttps://timothycrosley.github.io/isort/docs/upgrade_guides/5.0.0/\n" + ) + argv[index] = f"-{arg}" + parser = _build_arg_parser() arguments = {key: value for key, value in vars(parser.parse_args(argv)).items() if value} if "dont_order_by_type" in arguments: diff --git a/tests/test_main.py b/tests/test_main.py index 1c980c1f0..f88f44deb 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -90,7 +90,7 @@ def test_is_python_file_fifo(tmpdir): def test_main(capsys, tmpdir): base_args = [ - "--settings-path", + "-sp", str(tmpdir), "--virtual-env", str(tmpdir),