Repository: timothycrosley/isort
Pull request #939 (2019-05-01 06:50:51)

Feature/implement 938


Patch:
diff --git a/isort/main.py b/isort/main.py
index 8c3ec9a3..fe36d112 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -296,6 +296,8 @@ def parse_args(argv=None):
                              'where it may not be safe to operate in')
     parser.add_argument('--case-sensitive', dest='case_sensitive', action='store_true',
                         help='Tells isort to include casing when sorting module names')
+    parser.add_argument('--filter-files', dest='filter_files', action='store_true',
+                        help='Tells isort to filter files even when they are explicitly passed in as part of the command')
     parser.add_argument('files', nargs='*', help='One or more Python source files that need their imports sorted.')
 
     arguments = {key: value for key, value in vars(parser.parse_args(argv)).items() if value}
@@ -350,6 +352,16 @@ def main(argv=None):
         config.update(arguments)
         wrong_sorted_files = False
         skipped = []
+
+        if config.get('filter_files'):
+            filtered_files = []
+            for file_name in file_names:
+                if should_skip(file_name, config):
+                    skipped.append(file_name)
+                else:
+                    filtered_files.append(file_name)
+            file_names = filtered_files
+
         if arguments.get('recursive', False):
             file_names = iter_source_code(file_names, config, skipped)
         num_skipped = 0
diff --git a/requirements.txt b/requirements.txt
index ebd54a93..532f895f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
-pytest==2.9.1
+pytest==4.4.1
 ipython==4.1.2
 appdirs


Test patch:
diff --git a/test_isort.py b/test_isort.py
index ad0fbb15..8768a26f 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2917,6 +2917,42 @@ def test_settings_path_skip_issue_909(tmpdir):
     assert b'skipped 2' in results.lower()
 
 
+def test_skip_paths_issue_938(tmpdir):
+    base_dir = tmpdir.mkdir('project')
+    config_dir = base_dir.mkdir('conf')
+    config_dir.join('.isort.cfg').write('[isort]\n'
+                                        'line_length = 88\n'
+                                        'multi_line_output = 4\n'
+                                        'lines_after_imports = 2\n'
+                                        'skip_glob =\n'
+                                        '    migrations/**.py\n')
+    base_dir.join('dont_skip.py').write('import os\n'
+                                        '\n'
+                                        'print("Hello World")'
+                                        '\n'
+                                        'import sys\n')
+
+    migrations_dir = base_dir.mkdir('migrations')
+    migrations_dir.join('file_glob_skip.py').write('import os\n'
+                                                   '\n'
+                                                   'print("Hello World")\n'
+                                                   '\n'
+                                                   'import sys\n')
+
+    test_run_directory = os.getcwd()
+    os.chdir(str(base_dir))
+    results = check_output(['isort', 'dont_skip.py', 'migrations/file_glob_skip.py'])
+    os.chdir(str(test_run_directory))
+
+    assert b'skipped' not in results.lower()
+
+    os.chdir(str(base_dir))
+    results = check_output(['isort', '--filter-files', '--settings-path=conf/.isort.cfg', 'dont_skip.py', 'migrations/file_glob_skip.py'])
+    os.chdir(str(test_run_directory))
+
+    assert b'skipped 1' in results.lower()
+
+
 def test_standard_library_deprecates_user_issue_778():
     test_input = ('import os\n'
                   '\n'