Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to allow overriding isort's skip_gitignore option #130

Merged
merged 1 commit into from Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGES.rst
Expand Up @@ -3,12 +3,17 @@
Changelog
=========

5.0.4 (unreleased)
5.1.0 (unreleased)
------------------

- Drop isort 4.x support.
[gforcada]

- Add `--isort-no-skip-gitignore` option to allow temporarily overriding the set
value of isort's `skip_gitignore` option with `False`. This can cause
flake8-isort to run significantly faster at the cost of making flake8-isort's
behavior differ slightly from the behavior of `isort --check`. [gschaffner]

5.0.3 (2022-11-20)
------------------

Expand Down
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -29,6 +29,8 @@ Configuration
-------------
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`.

See ``flake8 --help`` for available flake8-isort options.

Error codes
-----------
+------------+-----------------------------------------------------------+
Expand Down
23 changes: 21 additions & 2 deletions flake8_isort.py
Expand Up @@ -25,6 +25,7 @@ class Flake8IsortBase:
isort_add_unexp = 'I005 isort found an unexpected missing import'

show_traceback = False
no_skip_gitignore = False
stdin_display_name = None
search_current = True

Expand All @@ -40,11 +41,23 @@ def add_options(option_manager):
parse_from_config=True,
help='Show full traceback with diff from isort',
)
option_manager.add_option(
'--isort-no-skip-gitignore',
gforcada marked this conversation as resolved.
Show resolved Hide resolved
action='store_true',
parse_from_config=True,
help=(
"Temporarily override the set value of isort's `skip_gitignore` option "
'with `False`. This can cause flake8-isort to run significantly faster '
"at the cost of making flake8-isort's behavior differ slightly from "
'the behavior of `isort --check`.'
),
)

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


class Flake8Isort5(Flake8IsortBase):
Expand All @@ -53,10 +66,16 @@ class Flake8Isort5(Flake8IsortBase):
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)
gforcada marked this conversation as resolved.
Show resolved Hide resolved
input_string = ''.join(self.lines)
traceback = ''
isort_changed = False
Expand Down
10 changes: 8 additions & 2 deletions run_tests.py
Expand Up @@ -212,15 +212,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
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -17,7 +17,7 @@ def read_file(filename):

setup(
name='flake8-isort',
version='5.0.4.dev0',
version='5.1.0.dev0',
description=short_description,
long_description=long_description,
# Get more from https://pypi.org/classifiers/
Expand Down