Skip to content

Commit 85c1018

Browse files
authored
Merge pull request #130 from gschaffner/no-skip-gitignore
Add option to allow overriding isort's skip_gitignore option
2 parents 65c1a59 + 0bacb49 commit 85c1018

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

CHANGES.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
Changelog
44
=========
55

6-
5.0.4 (unreleased)
6+
5.1.0 (unreleased)
77
------------------
88

99
- Drop isort 4.x support.
1010
[gforcada]
1111

12+
- Add `--isort-no-skip-gitignore` option to allow temporarily overriding the set
13+
value of isort's `skip_gitignore` option with `False`. This can cause
14+
flake8-isort to run significantly faster at the cost of making flake8-isort's
15+
behavior differ slightly from the behavior of `isort --check`. [gschaffner]
16+
1217
5.0.3 (2022-11-20)
1318
------------------
1419

README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Configuration
2929
-------------
3030
If using the `select` `option from flake8`_ be sure to enable the `I` category as well, see below for the specific error codes reported by `flake8-isort`.
3131

32+
See ``flake8 --help`` for available flake8-isort options.
33+
3234
Error codes
3335
-----------
3436
+------------+-----------------------------------------------------------+

flake8_isort.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Flake8IsortBase:
2525
isort_add_unexp = 'I005 isort found an unexpected missing import'
2626

2727
show_traceback = False
28+
no_skip_gitignore = False
2829
stdin_display_name = None
2930
search_current = True
3031

@@ -40,11 +41,23 @@ def add_options(option_manager):
4041
parse_from_config=True,
4142
help='Show full traceback with diff from isort',
4243
)
44+
option_manager.add_option(
45+
'--isort-no-skip-gitignore',
46+
action='store_true',
47+
parse_from_config=True,
48+
help=(
49+
"Temporarily override the set value of isort's `skip_gitignore` option "
50+
'with `False`. This can cause flake8-isort to run significantly faster '
51+
"at the cost of making flake8-isort's behavior differ slightly from "
52+
'the behavior of `isort --check`.'
53+
),
54+
)
4355

4456
@classmethod
4557
def parse_options(cls, option_manager, options, args):
4658
cls.stdin_display_name = options.stdin_display_name
4759
cls.show_traceback = options.isort_show_traceback
60+
cls.no_skip_gitignore = options.isort_no_skip_gitignore
4861

4962

5063
class Flake8Isort5(Flake8IsortBase):
@@ -53,10 +66,16 @@ class Flake8Isort5(Flake8IsortBase):
5366
def run(self):
5467
if self.filename is not self.stdin_display_name:
5568
file_path = Path(self.filename)
56-
isort_config = isort.settings.Config(settings_path=file_path.parent)
69+
settings_path = file_path.parent
5770
else:
5871
file_path = None
59-
isort_config = isort.settings.Config(settings_path=Path.cwd())
72+
settings_path = Path.cwd()
73+
if self.no_skip_gitignore:
74+
isort_config = isort.settings.Config(
75+
settings_path=settings_path, skip_gitignore=False
76+
)
77+
else:
78+
isort_config = isort.settings.Config(settings_path=settings_path)
6079
input_string = ''.join(self.lines)
6180
traceback = ''
6281
isort_changed = False

run_tests.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,21 @@ def test_isort_formatted_output(tmpdir):
212212
from sys import pid
213213
"""
214214
options = collections.namedtuple(
215-
'Options', ['no_isort_config', 'isort_show_traceback', 'stdin_display_name']
215+
'Options',
216+
[
217+
'no_isort_config',
218+
'isort_show_traceback',
219+
'stdin_display_name',
220+
'isort_no_skip_gitignore',
221+
],
216222
)
217223

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

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

222228
checker = Flake8Isort(None, file_path, lines)
223-
checker.parse_options(None, options(None, True, 'stdin'), None)
229+
checker.parse_options(None, options(None, True, 'stdin', None), None)
224230
ret = list(checker.run())
225231
assert len(ret) == 1
226232
assert ret[0][0] == 3

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def read_file(filename):
1717

1818
setup(
1919
name='flake8-isort',
20-
version='5.0.4.dev0',
20+
version='5.1.0.dev0',
2121
description=short_description,
2222
long_description=long_description,
2323
# Get more from https://pypi.org/classifiers/

0 commit comments

Comments
 (0)