Skip to content

Commit

Permalink
Merge pull request #1676 from dongfangtianyu/develop
Browse files Browse the repository at this point in the history
fix :Failed to pull configuration information from pyproject.toml
  • Loading branch information
timothycrosley committed Feb 24, 2021
2 parents 25d1095 + f903034 commit 713a059
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion isort/settings.py
Expand Up @@ -647,7 +647,7 @@ def _find_config(path: str) -> Tuple[str, Dict[str, Any]]:
def _get_config_data(file_path: str, sections: Tuple[str]) -> Dict[str, Any]:
settings: Dict[str, Any] = {}

with open(file_path) as config_file:
with open(file_path, encoding="utf-8") as config_file:
if file_path.endswith(".toml"):
config = toml.load(config_file)
for section in sections:
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_settings.py
Expand Up @@ -189,6 +189,31 @@ def test_editorconfig_without_sections(tmpdir):
assert not loaded_settings


def test_get_config_data_with_toml_and_utf8(tmpdir):
test_config = tmpdir.join("pyproject.toml")
# Exception: UnicodeDecodeError: 'gbk' codec can't decode byte 0x84 in position 57
test_config.write_text(
"""
[tool.poetry]
description = "基于FastAPI + Mysql的 TodoList" # Exception: UnicodeDecodeError
name = "TodoList"
version = "0.1.0"
[tool.isort]
multi_line_output = 3
""",
"utf8",
)
loaded_settings = settings._get_config_data(
str(test_config), sections=settings.CONFIG_SECTIONS["pyproject.toml"]
)
assert loaded_settings
assert str(tmpdir) in loaded_settings["source"]


def test_as_bool():
assert settings._as_bool("TrUe") is True
assert settings._as_bool("true") is True
Expand Down

0 comments on commit 713a059

Please sign in to comment.