summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-11-08 00:54:16 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-11-08 00:54:16 -0800
commitae4c17fcf102fffc1137323069951c06edd28995 (patch)
tree97ee2706a042f7443084d6c7db3d4650f7c15d13
parent592d07a364a7d8a2fcf2c2b55e42a8f6507209e6 (diff)
downloadisort-ae4c17fcf102fffc1137323069951c06edd28995.tar.gz
Flake8 fixes
-rw-r--r--isort/api.py4
-rw-r--r--isort/compat.py2
-rw-r--r--isort/main.py5
-rw-r--r--isort/settings.py12
-rw-r--r--tests/test_isort.py18
5 files changed, 21 insertions, 20 deletions
diff --git a/isort/api.py b/isort/api.py
index 22802a97..25dc2be3 100644
--- a/isort/api.py
+++ b/isort/api.py
@@ -21,8 +21,8 @@ def _config(
if path:
if (
config is DEFAULT_CONFIG
- and not "settings_path" in config_kwargs
- and not "settings_file" in config_kwargs
+ and "settings_path" not in config_kwargs
+ and "settings_file" not in config_kwargs
):
config_kwargs["settings_path"] = path
diff --git a/isort/compat.py b/isort/compat.py
index 3ff70f62..9bc5aea8 100644
--- a/isort/compat.py
+++ b/isort/compat.py
@@ -54,7 +54,7 @@ class SortImports:
if settings_path:
setting_overrides["settings_path"] = settings_path
- elif file_path and not "settings_file" in setting_overrides:
+ elif file_path and "settings_file" not in setting_overrides:
setting_overrides["settings_path"] = file_path.parent
config = Config(**setting_overrides)
diff --git a/isort/main.py b/isort/main.py
index 1616f9c5..2d47f79b 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -525,7 +525,6 @@ def parse_args(argv: Optional[Sequence[str]] = None) -> Dict[str, Any]:
f"(currently: {sys.version_info.major}{sys.version_info.minor}) will be used.",
)
- values = vars(parser.parse_args(argv))
arguments = {key: value for key, value in vars(parser.parse_args(argv)).items() if value}
if "dont_order_by_type" in arguments:
arguments["order_by_type"] = False
@@ -568,8 +567,10 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
if not arguments.get("apply", False):
arguments["ask_to_apply"] = True
- if not "settings_path" in arguments:
+ if "settings_path" not in arguments:
arguments["settings_path"] = os.path.abspath(file_names[0]) or os.getcwd()
+ if not os.path.isdir(arguments["settings_path"]):
+ arguments["settings_path"] = os.path.basename(arguments["settings_path"])
config_dict = arguments.copy()
config_dict.pop("recursive", False)
diff --git a/isort/settings.py b/isort/settings.py
index 5ac7938d..b802b2ae 100644
--- a/isort/settings.py
+++ b/isort/settings.py
@@ -32,8 +32,9 @@ from typing import (
)
from warnings import warn
-from . import sections, stdlibs
+from . import stdlibs
from ._future import dataclass, field
+from .sections import DEFAULT as SECTION_DEFAULTS
from .utils import difference, union
from .wrap_modes import WrapModes
from .wrap_modes import from_string as wrap_mode_from_string
@@ -117,7 +118,7 @@ class _Config:
line_length: int = 79
wrap_length: int = 0
line_ending: str = ""
- sections: Tuple[str, ...] = sections.DEFAULT
+ sections: Tuple[str, ...] = SECTION_DEFAULTS
no_sections: bool = False
known_future_library: FrozenSet[str] = frozenset(("__future__",))
known_third_party: FrozenSet[str] = frozenset(("google.appengine.api",))
@@ -209,7 +210,7 @@ class Config(_Config):
config_settings: Dict[str, Any]
if settings_file:
- config_settings = config_data = _get_config_data(
+ config_settings = _get_config_data(
settings_file,
CONFIG_SECTIONS.get(os.path.basename(settings_file), FALLBACK_CONFIG_SECTIONS),
)
@@ -261,7 +262,8 @@ class Config(_Config):
config_settings.get("source", None) or os.getcwd()
)
- # Remove any config values that are used for creating config object but aren't defined in dataclass
+ # Remove any config values that are used for creating config object but
+ # aren't defined in dataclass
combined_config.pop("source", None)
if known_other:
for known_key in known_other.keys():
@@ -278,10 +280,8 @@ class Config(_Config):
"""Returns True if the file and/or folder should be skipped based on current settings."""
if self.directory and Path(self.directory) in file_path.parents:
file_name = os.path.relpath(file_path, self.directory)
- path = self.directory
else:
file_name = str(file_path)
- path = ""
os_path = str(file_path)
diff --git a/tests/test_isort.py b/tests/test_isort.py
index 8424ed6a..98b88040 100644
--- a/tests/test_isort.py
+++ b/tests/test_isort.py
@@ -14,7 +14,7 @@ from typing import Any, Dict, Iterator, List, Set, Tuple
import py
import pytest
-from isort import finders, main, settings, sections
+from isort import finders, main, sections
from isort.main import SortImports, is_python_file
from isort.settings import WrapModes, Config
from isort.utils import exists_case_sensitive
@@ -661,10 +661,10 @@ def test_skip_with_file_name() -> None:
test_input = "import django\nimport myproject\n"
sort_imports = SortImports(
- file_path="/baz.py", file_contents=test_input, settings_path=os.getcwd(), skip=["baz.py"]
+ filename="/baz.py", file_contents=test_input, settings_path=os.getcwd(), skip=["baz.py"]
)
assert sort_imports.skipped
- assert sort_imports.output is None
+ assert sort_imports.output == ""
def test_skip_within_file() -> None:
@@ -672,7 +672,7 @@ def test_skip_within_file() -> None:
test_input = "# isort:skip_file\nimport django\nimport myproject\n"
sort_imports = SortImports(file_contents=test_input, known_third_party=["django"])
assert sort_imports.skipped
- assert sort_imports.output is None
+ assert sort_imports.output == ""
def test_force_to_top() -> None:
@@ -1952,7 +1952,7 @@ def test_other_file_encodings(tmpdir) -> None:
file_contents = f"# coding: {encoding}\n\ns = u'ã'\n"
tmp_fname.write_binary(file_contents.encode(encoding))
assert (
- SortImports(file_path=str(tmp_fname), settings_path=os.getcwd()).output == file_contents
+ SortImports(filename=str(tmp_fname), settings_path=os.getcwd()).output == file_contents
)
@@ -1961,7 +1961,7 @@ def test_encoding_not_in_comment(tmpdir) -> None:
tmp_fname = tmpdir.join("test_encoding.py")
file_contents = "class Foo\n coding: latin1\n\ns = u'ã'\n"
tmp_fname.write_binary(file_contents.encode("utf8"))
- assert SortImports(file_path=str(tmp_fname), settings_path=os.getcwd()).output == file_contents
+ assert SortImports(filename=str(tmp_fname), settings_path=os.getcwd()).output == file_contents
def test_encoding_not_in_first_two_lines(tmpdir) -> None:
@@ -1969,7 +1969,7 @@ def test_encoding_not_in_first_two_lines(tmpdir) -> None:
tmp_fname = tmpdir.join("test_encoding.py")
file_contents = "\n\n# -*- coding: latin1\n\ns = u'ã'\n"
tmp_fname.write_binary(file_contents.encode("utf8"))
- assert SortImports(file_path=str(tmp_fname), settings_path=os.getcwd()).output == file_contents
+ assert SortImports(filename=str(tmp_fname), settings_path=os.getcwd()).output == file_contents
def test_comment_at_top_of_file() -> None:
@@ -4089,11 +4089,11 @@ def test_pyi_formatting_issue_942(tmpdir) -> None:
source_py = tmpdir.join("source.py")
source_py.write(test_input)
- assert SortImports(file_path=str(source_py)).output.splitlines() == expected_py_output
+ assert SortImports(filename=str(source_py)).output.splitlines() == expected_py_output
source_pyi = tmpdir.join("source.pyi")
source_pyi.write(test_input)
- assert SortImports(file_path=str(source_pyi)).output.splitlines() == expected_pyi_output
+ assert SortImports(filename=str(source_pyi)).output.splitlines() == expected_pyi_output
def test_move_class_issue_751() -> None: