From 36b6b24afbf058f108e518ee1e7ded3f933d3b2e Mon Sep 17 00:00:00 2001 From: Timothy Edmund Crosley Date: Sat, 23 Mar 2019 22:31:52 -0700 Subject: Merge pull request #911 from timothycrosley/feature/fix-issue-909 Feature/fix issue 909 --- CHANGELOG.md | 3 +++ isort/main.py | 3 ++- test_isort.py | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c718f994..5d9371bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ Internal: Planned: - profile support for common project types (black, django, google, etc) +### 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 300a2311..17d2471b 100644 --- a/isort/main.py +++ b/isort/main.py @@ -338,7 +338,8 @@ def main(argv: Optional[Sequence[str]] = None) -> 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 = [] # type: List[str] diff --git a/test_isort.py b/test_isort.py index 91cb6f10..a729139b 100644 --- a/test_isort.py +++ b/test_isort.py @@ -20,22 +20,23 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT OTHER DEALINGS IN THE SOFTWARE. """ -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 py 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 @@ -2930,3 +2931,33 @@ def test_standard_library_deprecates_user_issue_778(): '\n' 'import user\n') assert SortImports(file_contents=test_input).output == test_input + + +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() -- cgit v1.2.1