Skip to content

Commit

Permalink
Merge 2107feb into 4bed554
Browse files Browse the repository at this point in the history
  • Loading branch information
gschaffner committed Dec 8, 2022
2 parents 4bed554 + 2107feb commit 1344cf5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
27 changes: 25 additions & 2 deletions flake8_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,36 @@ def _fixup_sortimports_wrapped(sort_imports):
class Flake8Isort5(Flake8IsortBase):
"""class for isort >=5"""

no_skip_gitignore = False

@classmethod
def add_options(cls, option_manager):
super().add_options(option_manager)
option_manager.add_option(
'--isort-no-skip-gitignore',
action='store_true',
parse_from_config=True,
help="Override the set value of isort's skip_gitignore option with False",
)

@classmethod
def parse_options(cls, option_manager, options, args):
super().parse_options(option_manager, options, args)
cls.no_skip_gitignore = options.isort_no_skip_gitignore

def run(self):
if self.filename is not self.stdin_display_name:
file_path = Path(self.filename)
isort_config = isort.settings.Config(settings_path=file_path.parent)
settings_path = file_path.parent
else:
file_path = None
isort_config = isort.settings.Config(settings_path=Path.cwd())
settings_path = Path.cwd()
if self.no_skip_gitignore:
isort_config = isort.settings.Config(
settings_path=settings_path, skip_gitignore=False
)
else:
isort_config = isort.settings.Config(settings_path=settings_path)
input_string = ''.join(self.lines)
traceback = ''
isort_changed = False
Expand Down
10 changes: 8 additions & 2 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,21 @@ def test_isort_formatted_output(tmpdir):
from sys import pid
"""
options = collections.namedtuple(
'Options', ['no_isort_config', 'isort_show_traceback', 'stdin_display_name']
'Options',
[
'no_isort_config',
'isort_show_traceback',
'stdin_display_name',
'isort_no_skip_gitignore',
],
)

(file_path, lines) = write_python_file(tmpdir, source)

diff = ' from __future__ import division\n+\n import os'

checker = Flake8Isort(None, file_path, lines)
checker.parse_options(None, options(None, True, 'stdin'), None)
checker.parse_options(None, options(None, True, 'stdin', None), None)
ret = list(checker.run())
assert len(ret) == 1
assert ret[0][0] == 3
Expand Down

0 comments on commit 1344cf5

Please sign in to comment.