Skip to content

Commit 4c77b43

Browse files
authored
Merge pull request #184 from asottile/deprecated
deprecate undocumented options
2 parents 72403cc + 3eb476c commit 4c77b43

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

reorder_python_imports.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,6 @@ def _fix_file(filename: str, args: argparse.Namespace) -> int:
491491
if args.diff_only:
492492
_report_diff(contents, new_contents, filename)
493493
elif args.print_only:
494-
print('!!! --print-only is deprecated', file=sys.stderr)
495-
print('!!! maybe use `-` instead?', file=sys.stderr)
496494
print(f'==> {filename} <==', file=sys.stderr)
497495
print(new_contents, end='')
498496
else:
@@ -806,7 +804,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
806804
group = parser.add_mutually_exclusive_group(required=False)
807805
group.add_argument(
808806
'--diff-only', action='store_true',
809-
help='Show unified diff instead of applying reordering.',
807+
help='(Deprecated) Show unified diff instead of applying reordering.',
810808
)
811809
group.add_argument(
812810
'--print-only', action='store_true',
@@ -860,23 +858,36 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
860858
parser.add_argument(
861859
'--separate-relative', action='store_true',
862860
help=(
863-
'Separate explicit relative (`from . import ...`) imports into a '
864-
'separate block.'
861+
'(Deprecated) Separate explicit relative (`from . import ...`) '
862+
'imports into a separate block.'
865863
),
866864
)
867865

868866
parser.add_argument(
869867
'--separate-from-import', action='store_true',
870868
help=(
871-
'Separate `from xx import xx` imports from `import xx` imports'
872-
' with a new line.'
869+
'(Deprecated) Separate `from xx import xx` imports from '
870+
'`import xx` imports with a new line.'
873871
),
874872
)
875873

876874
_add_version_options(parser)
877875

878876
args = parser.parse_args(argv)
879877

878+
for option in (
879+
'diff_only',
880+
'print_only',
881+
'separate_relative',
882+
'separate_from_import',
883+
):
884+
if getattr(args, option):
885+
print(
886+
f'warning: --{option.replace("_", "-")} is deprecated '
887+
f'and will be removed',
888+
file=sys.stderr,
889+
)
890+
880891
for k, v in REMOVALS.items():
881892
if args.min_version >= k:
882893
args.remove_import.extend(v)

tests/reorder_python_imports_test.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,7 @@ def test_integration_main_stdout(tmpdir, capsys):
738738
'import reorder_python_imports\n'
739739
)
740740
assert err == (
741-
f'!!! --print-only is deprecated\n'
742-
f'!!! maybe use `-` instead?\n'
741+
'warning: --print-only is deprecated and will be removed\n'
743742
f'==> {f} <==\n'
744743
)
745744

@@ -1195,3 +1194,23 @@ def test_warning_pythonpath(tmpdir, capsys):
11951194
out, err = capsys.readouterr()
11961195
assert err == '$PYTHONPATH set, import order may be unexpected\n'
11971196
assert out == ''
1197+
1198+
1199+
@pytest.mark.parametrize(
1200+
'option',
1201+
(
1202+
'--diff-only',
1203+
'--print-only',
1204+
'--separate-relative',
1205+
'--separate-from-import',
1206+
),
1207+
)
1208+
def test_deprecated_options(option, tmpdir, capsys):
1209+
f = tmpdir.join('f')
1210+
f.ensure()
1211+
1212+
assert not main((str(f), option))
1213+
1214+
out, err = capsys.readouterr()
1215+
assert out == ''
1216+
assert err == f'warning: {option} is deprecated and will be removed\n'

0 commit comments

Comments
 (0)