Repository: timothycrosley/isort (python)

Issue:
skip and skip-glob are not enforced when using settings-path
Hi,

Version used: 4.3.15, not tested on other versions.

Setup:
```console
$ tree -a
.
├── conf
│   └── .isort.cfg
├── file_glob_skip.py
└── file_to_be_skipped.py

1 directory, 3 files
$ cat conf/.isort.cfg 
[isort]
skip =
    file_to_be_skipped.py
skip_glob =
    *glob_skip*
$ cat file_glob_skip.py 
import os

print("Hello World")

import sys
$ cat file_to_be_skipped.py 
import os

print("Hello World")

import sys
```

Files are not skipped when using `--settings-path=conf/.isort.cfg`:
```console
$ isort --check-only --settings-path=conf/.isort.cfg
ERROR: /home/romain/Area51/isort_skip_bug/file_glob_skip.py Imports are incorrectly sorted.
ERROR: /home/romain/Area51/isort_skip_bug/file_to_be_skipped.py Imports are incorrectly sorted.
```
But works when using CLI options:
```console
$ isort --check-only --skip file_to_be_skipped.py --skip-glob '*glob_skip*' 
Skipped 2 files
```

The problem seems to have two causes:
1.  `check_skip` is _always_ set to `False` [1] which make `SortImports` not even trying any of the skip options [2] while the class use `True` as default for that argument [3]
2. Options defined in a settings-path file are not used [4] by `iter_source_code()` [5], the `config` dict will only contain options a local `.isort.cfg` and CLI options.

[1] https://github.com/timothycrosley/isort/blob/4.3.15/isort/main.py#L320
[2] https://github.com/timothycrosley/isort/blob/4.3.15/isort/isort.py#L98
[3] https://github.com/timothycrosley/isort/blob/4.3.15/isort/isort.py#L51
[4] https://github.com/timothycrosley/isort/blob/4.3.15/isort/main.py#L348-L349
[5] https://github.com/timothycrosley/isort/blob/4.3.15/isort/main.py#L353

A bisect give me 91ae94e477d066f133a889d13f3bd25363785258 as first bad commit.

Pull request:
Feature/fix issue 909
Fixes #909 by including custom path aware config before iter_source is called

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 85638132..d656640d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 Changelog
 =========
+### 4.3.16 - March 23, 2019 - hot fix release
+- Fixed issue #909 - skip and skip-glob are not enforced when using settings-path
+
 ### 4.3.15 - March 10, 2019 - hot fix release
 - Fixed a regression with handling streaming input from pipes (Issue #895)
 - Fixed handling of \x0c whitespace character (Issue #811)
diff --git a/isort/main.py b/isort/main.py
index 24de5c0c..8c3ec9a3 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -345,7 +345,8 @@ def main(argv=None):
             arguments['recursive'] = True
             if not arguments.get('apply', False):
                 arguments['ask_to_apply'] = True
-        config = from_path(os.path.abspath(file_names[0]) or os.getcwd()).copy()
+
+        config = from_path(arguments.get('settings_path', '') or os.path.abspath(file_names[0]) or os.getcwd()).copy()
         config.update(arguments)
         wrong_sorted_files = False
         skipped = []


Test patch:
diff --git a/test_isort.py b/test_isort.py
index 8c157c4e..1e75c17e 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -23,21 +23,22 @@ OTHER DEALINGS IN THE SOFTWARE.
 """
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-from tempfile import NamedTemporaryFile
 import io
 import os
 import os.path
 import posixpath
 import sys
 import sysconfig
+from subprocess import check_output
+from tempfile import NamedTemporaryFile
 
 import pytest
 
 from isort import finders, main, settings
 from isort.isort import SortImports
-from isort.utils import exists_case_sensitive
 from isort.main import is_python_file
 from isort.settings import WrapModes
+from isort.utils import exists_case_sensitive
 
 try:
     import toml
@@ -2888,3 +2889,33 @@ def test_to_ensure_correctly_handling_of_whitespace_only_issue_811(capsys):
     out, err = capsys.readouterr()
     assert out == ''
     assert err == ''
+
+
+def test_settings_path_skip_issue_909(tmpdir):
+    base_dir = tmpdir.mkdir('project')
+    config_dir = base_dir.mkdir('conf')
+    config_dir.join('.isort.cfg').write('[isort]\n'
+                                        'skip =\n'
+                                        '    file_to_be_skipped.py\n'
+                                        'skip_glob =\n'
+                                        '    *glob_skip*\n')
+
+    base_dir.join('file_glob_skip.py').write('import os\n'
+                                             '\n'
+                                             'print("Hello World")\n'
+                                             '\n'
+                                             'import sys\n')
+    base_dir.join('file_to_be_skipped.py').write('import os\n'
+                                                 '\n'
+                                                 'print("Hello World")'
+                                                 '\n'
+                                                 'import sys\n')
+
+    test_run_directory = os.getcwd()
+    os.chdir(str(base_dir))
+    with pytest.raises(Exception):  # without the settings path provided: the command should not skip & identify errors
+        check_output(['isort', '--check-only'])
+    results = check_output(['isort', '--check-only', '--settings-path=conf/.isort.cfg'])
+    os.chdir(str(test_run_directory))
+
+    assert b'skipped 2' in results.lower()