diff options
author | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2019-05-01 07:51:11 -0700 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2019-05-01 22:20:55 -0700 |
commit | 96032a8c9dadaa755dd0bfb6ee3707ba07e5ef3f (patch) | |
tree | 1457956f614666618019018440cc05a5b6635a38 | |
parent | 01196cde0f9ab343f415b7cd035222e6a52f8264 (diff) | |
download | isort-96032a8c9dadaa755dd0bfb6ee3707ba07e5ef3f.tar.gz |
Merge pull request #939 from timothycrosley/feature/implement-938
Feature/implement 938
-rw-r--r-- | isort/main.py | 12 | ||||
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | test_isort.py | 43 |
3 files changed, 56 insertions, 1 deletions
diff --git a/isort/main.py b/isort/main.py index 17d2471b..8d5e2353 100644 --- a/isort/main.py +++ b/isort/main.py @@ -295,6 +295,8 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]: '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} @@ -343,6 +345,16 @@ def main(argv: Optional[Sequence[str]] = None) -> None: config.update(arguments) wrong_sorted_files = False skipped = [] # type: List[str] + + if config.get('filter_files'): + filtered_files = [] + for file_name in file_names: + if file_should_be_skipped(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 diff --git a/test_isort.py b/test_isort.py index d68033dd..6c404e19 100644 --- a/test_isort.py +++ b/test_isort.py @@ -2959,6 +2959,49 @@ 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' + 'import user\n') + assert SortImports(file_contents=test_input).output == test_input + + def test_failing_file_check_916(): test_input = ('#!/usr/bin/env python\n' '# -*- coding: utf-8 -*-\n' |