Skip to content

Commit

Permalink
Merge pull request #1680 from PyCQA/issue/1668
Browse files Browse the repository at this point in the history
Issue/1668
  • Loading branch information
timothycrosley committed Mar 1, 2021
2 parents 3df2ed4 + 3de261f commit c11759d
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 194 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
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
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

0 comments on commit c11759d

Please sign in to comment.