summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2020-09-30 21:40:28 -0700
committerTimothy Crosley <timothy.crosley@gmail.com>2020-09-30 21:40:28 -0700
commita5df07f146bab07da2df7d581b44d0942add362c (patch)
tree2a583a5b1ed53bab5d31b5954b78d36cdbc15741
parentc2473cf30fa37d72bb8918bb365b0fae281a451f (diff)
downloadisort-issue/1511/show-files-via-cli-support.tar.gz
Implemented #1511: Support for easily seeing all files isort will be ran againstissue/1511/show-files-via-cli-support
-rw-r--r--CHANGELOG.md1
-rw-r--r--isort/main.py16
-rw-r--r--tests/unit/test_main.py24
3 files changed, 37 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87baa08a..712e554d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/
- Implemented #1433: Provide helpful feedback in case a custom config file is specified without a configuration.
- Implemented #1494: Default to sorting imports within `.pxd` files.
- Implemented #1502: Improved float-to-top behavior when there is an existing import section present at top-of-file.
+ - Implemented #1511: Support for easily seeing all files isort will be ran against using `isort . --show-files`.
- Improved handling of unsupported configuration option errors (see #1475).
- Fixed #1463: Better interactive documentation for future option.
- Fixed #1461: Quiet config option not respected by file API in some circumstances.
diff --git a/isort/main.py b/isort/main.py
index fb5f3200..c518a92d 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -639,6 +639,12 @@ def _build_arg_parser() -> argparse.ArgumentParser:
help="See isort's determined config, as well as sources of config options.",
)
parser.add_argument(
+ "--show-files",
+ dest="show_files",
+ action="store_true",
+ help="See the files isort will be ran against with the current config options.",
+ )
+ parser.add_argument(
"--honor-noqa",
dest="honor_noqa",
action="store_true",
@@ -805,6 +811,9 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
return
show_config: bool = arguments.pop("show_config", False)
+ show_files: bool = arguments.pop("show_files", False)
+ if show_config and show_files:
+ sys.exit("Error: either specify show-config or show-files not both.")
if "settings_path" in arguments:
if os.path.isfile(arguments["settings_path"]):
@@ -854,6 +863,9 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
print(json.dumps(config.__dict__, indent=4, separators=(",", ": "), default=_preconvert))
return
elif file_names == ["-"]:
+ if show_files:
+ sys.exit("Error: can't show files for streaming input.")
+
if check:
incorrectly_sorted = not api.check_stream(
input_stream=sys.stdin if stdin is None else stdin,
@@ -883,6 +895,10 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
file_names = filtered_files
file_names = iter_source_code(file_names, config, skipped, broken)
+ if show_files:
+ for file_name in file_names:
+ print(file_name)
+ return
num_skipped = 0
num_broken = 0
if config.verbose:
diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py
index ddca98dd..ef837b61 100644
--- a/tests/unit/test_main.py
+++ b/tests/unit/test_main.py
@@ -13,9 +13,6 @@ from isort.exceptions import InvalidSettingsPath
from isort.settings import DEFAULT_CONFIG, Config
from isort.wrap_modes import WrapModes
-# This test code was written by the `hypothesis.extra.ghostwriter` module
-# and is provided under the Creative Commons Zero public domain dedication.
-
@given(
file_name=st.text(),
@@ -104,6 +101,26 @@ def test_preconvert():
main._preconvert(datetime.now())
+def test_show_files(capsys, tmpdir):
+ tmpdir.join("a.py").write("import a")
+ tmpdir.join("b.py").write("import b")
+
+ # show files should list the files isort would sort
+ main.main([str(tmpdir), "--show-files"])
+ out, error = capsys.readouterr()
+ assert "a.py" in out
+ assert "b.py" in out
+ assert not error
+
+ # can not be used for stream
+ with pytest.raises(SystemExit):
+ main.main(["-", "--show-files"])
+
+ # can not be used with show-config
+ with pytest.raises(SystemExit):
+ main.main([str(tmpdir), "--show-files", "--show-config"])
+
+
def test_main(capsys, tmpdir):
base_args = [
"-sp",
@@ -661,7 +678,6 @@ from a import b, e, c
)
# ensures that isort warns with deprecated flags with stdin
-
input_content = TextIOWrapper(
BytesIO(
b"""