Skip to content

Commit

Permalink
Merge pull request #27 from sodul/user/stephane/isort-add-imports
Browse files Browse the repository at this point in the history
Add support for isort add-imports and remove-imports features.
  • Loading branch information
dizballanze authored Apr 28, 2024
2 parents db68d94 + 87d6c58 commit 7c1becc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gray/formatters/isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def __init__(self, arguments: Namespace):
)
if arguments.isort_skip_gitignore:
self._settings["skip_gitignore"] = arguments.isort_skip_gitignore
if arguments.isort_add_imports:
self._settings["add_imports"] = arguments.isort_add_imports
if arguments.isort_remove_imports:
self._settings["remove_imports"] = arguments.isort_remove_imports

def process(self, file_path: Path):
"""Process the given file through isort."""
Expand Down
13 changes: 12 additions & 1 deletion gray/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_parser() -> configargparse.ArgumentParser:
group.add_argument(
"--isort-known-first-party",
help="Force isort to recognize a module as being part of the current"
" python project.",
" python project.",
type=parse_frozenset,
)
group.add_argument(
Expand Down Expand Up @@ -218,6 +218,17 @@ def get_parser() -> configargparse.ArgumentParser:
type=parse_bool,
default=False,
)
group.add_argument(
"--isort-add-imports",
help="Adds the specified import lines to all files,"
" automatically determining correct placement.",
type=parse_frozenset,
)
group.add_argument(
"--isort-remove-imports",
help="Removes the specified imports from all files.",
type=parse_frozenset,
)

group = parser.add_argument_group("autoflake options")
group.add_argument(
Expand Down

0 comments on commit 7c1becc

Please sign in to comment.