From 35a22053c42797f82c293a59502af815230d2c69 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 27 Oct 2020 23:43:49 -0700 Subject: [PATCH 1/3] Fix issue #1582: Provide a flag for not following links --- isort/main.py | 12 ++++++++---- isort/settings.py | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/isort/main.py b/isort/main.py index c8715e10d..7f776e0cd 100644 --- a/isort/main.py +++ b/isort/main.py @@ -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 @@ -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", @@ -750,7 +749,6 @@ 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", @@ -758,7 +756,6 @@ def _build_arg_parser() -> argparse.ArgumentParser: action="store_true", help="Suppresses verbose output for non-modified files.", ) - parser.add_argument( "--combine-straight-imports", "--csi", @@ -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( @@ -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(): diff --git a/isort/settings.py b/isort/settings.py index 8b93e4236..f0bd14b2d 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -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 From 669a6c36309ce89581074ab1e3aaa5bf7785aba7 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 27 Oct 2020 23:44:51 -0700 Subject: [PATCH 2/3] Add help --- isort/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/isort/main.py b/isort/main.py index 7f776e0cd..b1274ef33 100644 --- a/isort/main.py +++ b/isort/main.py @@ -767,7 +767,8 @@ def _build_arg_parser() -> argparse.ArgumentParser: parser.add_argument( "--dont-follow-links", dest="dont_follow_links", - action="store_true" + action="store_true", + help="Tells isort not to follow symlinks that are encountered when running recursively.", ) # deprecated options From 21b509797ba72631a506d333e86d8effe4584791 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 27 Oct 2020 23:49:30 -0700 Subject: [PATCH 3/3] black --- isort/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/isort/main.py b/isort/main.py index b1274ef33..0aeed6994 100644 --- a/isort/main.py +++ b/isort/main.py @@ -147,7 +147,9 @@ def iter_source_code( for path in paths: if os.path.isdir(path): - for dirpath, dirnames, filenames in os.walk(path, topdown=True, followlinks=config.follow_links): + 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