Skip to content

Commit

Permalink
Merge pull request #184 from asottile/deprecated
Browse files Browse the repository at this point in the history
deprecate undocumented options
  • Loading branch information
asottile authored Jul 24, 2021
2 parents 72403cc + 3eb476c commit 4c77b43
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
25 changes: 18 additions & 7 deletions reorder_python_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,6 @@ def _fix_file(filename: str, args: argparse.Namespace) -> int:
if args.diff_only:
_report_diff(contents, new_contents, filename)
elif args.print_only:
print('!!! --print-only is deprecated', file=sys.stderr)
print('!!! maybe use `-` instead?', file=sys.stderr)
print(f'==> {filename} <==', file=sys.stderr)
print(new_contents, end='')
else:
Expand Down Expand Up @@ -806,7 +804,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument(
'--diff-only', action='store_true',
help='Show unified diff instead of applying reordering.',
help='(Deprecated) Show unified diff instead of applying reordering.',
)
group.add_argument(
'--print-only', action='store_true',
Expand Down Expand Up @@ -860,23 +858,36 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
parser.add_argument(
'--separate-relative', action='store_true',
help=(
'Separate explicit relative (`from . import ...`) imports into a '
'separate block.'
'(Deprecated) Separate explicit relative (`from . import ...`) '
'imports into a separate block.'
),
)

parser.add_argument(
'--separate-from-import', action='store_true',
help=(
'Separate `from xx import xx` imports from `import xx` imports'
' with a new line.'
'(Deprecated) Separate `from xx import xx` imports from '
'`import xx` imports with a new line.'
),
)

_add_version_options(parser)

args = parser.parse_args(argv)

for option in (
'diff_only',
'print_only',
'separate_relative',
'separate_from_import',
):
if getattr(args, option):
print(
f'warning: --{option.replace("_", "-")} is deprecated '
f'and will be removed',
file=sys.stderr,
)

for k, v in REMOVALS.items():
if args.min_version >= k:
args.remove_import.extend(v)
Expand Down
23 changes: 21 additions & 2 deletions tests/reorder_python_imports_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,7 @@ def test_integration_main_stdout(tmpdir, capsys):
'import reorder_python_imports\n'
)
assert err == (
f'!!! --print-only is deprecated\n'
f'!!! maybe use `-` instead?\n'
'warning: --print-only is deprecated and will be removed\n'
f'==> {f} <==\n'
)

Expand Down Expand Up @@ -1195,3 +1194,23 @@ def test_warning_pythonpath(tmpdir, capsys):
out, err = capsys.readouterr()
assert err == '$PYTHONPATH set, import order may be unexpected\n'
assert out == ''


@pytest.mark.parametrize(
'option',
(
'--diff-only',
'--print-only',
'--separate-relative',
'--separate-from-import',
),
)
def test_deprecated_options(option, tmpdir, capsys):
f = tmpdir.join('f')
f.ensure()

assert not main((str(f), option))

out, err = capsys.readouterr()
assert out == ''
assert err == f'warning: {option} is deprecated and will be removed\n'

0 comments on commit 4c77b43

Please sign in to comment.