From 9ccfadd207cfd8390ff365d1f9a082762746633c Mon Sep 17 00:00:00 2001 From: Maxim Kurnikov Date: Thu, 25 Apr 2019 13:32:48 +0300 Subject: make compat layer to preserve public api --- isort/__init__.py | 2 +- isort/compat.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ isort/isort.py | 2 +- isort/main.py | 2 +- isort/pylama_isort.py | 2 +- test_isort.py | 3 +-- 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 isort/compat.py diff --git a/isort/__init__.py b/isort/__init__.py index 4314b858..dd113998 100644 --- a/isort/__init__.py +++ b/isort/__init__.py @@ -20,6 +20,6 @@ OTHER DEALINGS IN THE SOFTWARE. """ from . import settings # noqa: F401 -from .isort import SortImports # noqa: F401 +from .compat import SortImports # noqa: F401 __version__ = "4.3.17" diff --git a/isort/compat.py b/isort/compat.py new file mode 100644 index 00000000..e7a8b45d --- /dev/null +++ b/isort/compat.py @@ -0,0 +1,45 @@ +from typing import Optional, Any + +from isort.isort import _SortImports + + +class SortImports(object): + def __init__( + self, + file_path: Optional[str] = None, + file_contents: Optional[str] = None, + write_to_stdout: bool = False, + check: bool = False, + show_diff: bool = False, + settings_path: Optional[str] = None, + ask_to_apply: bool = False, + run_path: str = '', + check_skip: bool = True, + **setting_overrides: Any + ): + self.sorted_imports = _SortImports(file_path, file_contents, write_to_stdout, check, show_diff, settings_path, + ask_to_apply, run_path, check_skip, **setting_overrides) + + @property + def config(self): + return self.sorted_imports.config + + @property + def sections(self): + return self.sorted_imports.sections + + @property + def incorrectly_sorted(self): + return self.sorted_imports.incorrectly_sorted + + @property + def skipped(self) -> bool: + return self.sorted_imports.skipped + + @property + def length_change(self) -> int: + return self.sorted_imports.length_change + + @property + def output(self): + return self.sorted_imports.output diff --git a/isort/isort.py b/isort/isort.py index 94c61341..4df1808c 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -56,7 +56,7 @@ if TYPE_CHECKING: }) -class SortImports(object): +class _SortImports(object): incorrectly_sorted = False skipped = False diff --git a/isort/main.py b/isort/main.py index 17d2471b..211b0557 100644 --- a/isort/main.py +++ b/isort/main.py @@ -27,7 +27,7 @@ from typing import Any, Dict, Iterable, Iterator, List, MutableMapping, Optional import setuptools -from isort import SortImports, __version__ +from isort import __version__, SortImports from isort.settings import DEFAULT_SECTIONS, WrapModes, default, file_should_be_skipped, from_path INTRO = r""" diff --git a/isort/pylama_isort.py b/isort/pylama_isort.py index 9248981e..a8e508e9 100644 --- a/isort/pylama_isort.py +++ b/isort/pylama_isort.py @@ -4,7 +4,7 @@ from typing import Any, Dict, List from pylama.lint import Linter as BaseLinter -from .isort import SortImports +from . import SortImports class Linter(BaseLinter): diff --git a/test_isort.py b/test_isort.py index 68367885..d68033dd 100644 --- a/test_isort.py +++ b/test_isort.py @@ -34,8 +34,7 @@ import py import pytest from isort import finders, main, settings -from isort.isort import SortImports -from isort.main import is_python_file +from isort.main import is_python_file, SortImports from isort.settings import WrapModes from isort.utils import exists_case_sensitive -- cgit v1.2.1