Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/1668 #1680

Merged
merged 4 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/
- Implemented #1648: Export MyPY type hints.
- Implemented #1641: Identified import statements now return runnable code.
- Implemented #1661: Added "wemake" profile.
- implemented #1669: Parallel (`-j`) now defaults to number of CPU cores if no value is provided.
- Implemented #1669: Parallel (`-j`) now defaults to number of CPU cores if no value is provided.
- Implemented #1668: Added a safeguard against accidental usage against /.

### 5.7.0 December 30th 2020
- Fixed #1612: In rare circumstances an extra comma is added after import and before comment.
Expand Down
12 changes: 12 additions & 0 deletions isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ def _build_arg_parser() -> argparse.ArgumentParser:
dest="filename",
help="Provide the filename associated with a stream.",
)
target_group.add_argument(
"--allow-root",
action="store_true",
default=False,
help="Tells isort not to treat / specially, allowing it to be ran against the root dir.",
)

output_group.add_argument(
"-a",
Expand Down Expand Up @@ -1000,6 +1006,7 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
remapped_deprecated_args = config_dict.pop("remapped_deprecated_args", False)
stream_filename = config_dict.pop("filename", None)
ext_format = config_dict.pop("ext_format", None)
allow_root = config_dict.pop("allow_root", None)
wrong_sorted_files = False
all_attempt_broken = False
no_valid_encodings = False
Expand Down Expand Up @@ -1037,6 +1044,11 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
file_path=file_path,
extension=ext_format,
)
elif "/" in file_names and not allow_root:
printer = create_terminal_printer(color=config.color_output)
printer.error("it is dangerous to operate recursively on '/'")
printer.error("use --allow-root to override this failsafe")
sys.exit(1)
else:
if stream_filename:
printer = create_terminal_printer(color=config.color_output)
Expand Down
Loading