Skip to content

Commit

Permalink
Fix issue #1582: Provide a flag for not following links
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Oct 28, 2020
1 parent 13a96af commit 35a2205
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def iter_source_code(

for path in paths:
if os.path.isdir(path):
for dirpath, dirnames, filenames in os.walk(path, topdown=True, followlinks=True):
for dirpath, dirnames, filenames in os.walk(path, topdown=True, followlinks=config.follow_links):
base_path = Path(dirpath)
for dirname in list(dirnames):
full_path = base_path / dirname
Expand Down Expand Up @@ -741,7 +741,6 @@ def _build_arg_parser() -> argparse.ArgumentParser:
help="Tells isort to only show an identical custom import heading comment once, even if"
" there are multiple sections with the comment set.",
)

parser.add_argument(
"--only-sections",
"--os",
Expand All @@ -750,15 +749,13 @@ def _build_arg_parser() -> argparse.ArgumentParser:
help="Causes imports to be sorted only based on their sections like STDLIB,THIRDPARTY etc. "
"Imports are unaltered and keep their relative positions within the different sections.",
)

parser.add_argument(
"--only-modified",
"--om",
dest="only_modified",
action="store_true",
help="Suppresses verbose output for non-modified files.",
)

parser.add_argument(
"--combine-straight-imports",
"--csi",
Expand All @@ -767,6 +764,11 @@ def _build_arg_parser() -> argparse.ArgumentParser:
help="Combines all the bare straight imports of the same section in a single line. "
"Won't work with sections which have 'as' imports",
)
parser.add_argument(
"--dont-follow-links",
dest="dont_follow_links",
action="store_true"
)

# deprecated options
parser.add_argument(
Expand Down Expand Up @@ -823,6 +825,8 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]:
if "dont_order_by_type" in arguments:
arguments["order_by_type"] = False
del arguments["dont_order_by_type"]
if "dont_follow_links" in arguments:
arguments["follow_links"] = False
multi_line_output = arguments.get("multi_line_output", None)
if multi_line_output:
if multi_line_output.isdigit():
Expand Down
1 change: 1 addition & 0 deletions isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class _Config:
combine_straight_imports: bool = False
auto_identify_namespace_packages: bool = True
namespace_packages: FrozenSet[str] = frozenset()
follow_links: bool = True

def __post_init__(self):
py_version = self.py_version
Expand Down

0 comments on commit 35a2205

Please sign in to comment.