Skip to content

Commit

Permalink
Improved handling of deprecated single line variables for usage with …
Browse files Browse the repository at this point in the history
…Visual Studio Code (issue #1363)
  • Loading branch information
timothycrosley committed Aug 1, 2020
1 parent b668b55 commit 51db36d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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.
Expand Down
43 changes: 43 additions & 0 deletions isort/main.py
Expand Up @@ -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}
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Expand Up @@ -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),
Expand Down

0 comments on commit 51db36d

Please sign in to comment.