Skip to content

Commit

Permalink
Revert changes to keep backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bonprosoft committed Sep 29, 2022
1 parent 614ab18 commit 4c2c2db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pysen/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .manifest_builder import build
from .mypy import Mypy
from .plugin_loader import load_plugin
from .pyproject_model import Config, LintConfig, get_tool_section, parse
from .pyproject_model import Config, LintConfig, has_tool_section, parse

_logger = logging.getLogger(__name__)
TConfig = TypeVar("TConfig")
Expand Down Expand Up @@ -110,8 +110,8 @@ def load_manifest(path: pathlib.Path) -> ManifestBase:
def _check_section_exists(config_path: pathlib.Path) -> bool:
pyproject = tomlkit.loads(config_path.read_text())
return (
get_tool_section("jiro", pyproject) is not None
or get_tool_section("pysen", pyproject) is not None
has_tool_section("jiro", pyproject) is not None
or has_tool_section("pysen", pyproject) is not None
)


Expand Down
7 changes: 7 additions & 0 deletions pysen/pyproject_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ def get_tool_section(
return _get_descendant(pyproject, ["tool", tool_name])


def has_tool_section(
tool_name: str,
pyproject: tomlkit.toml_document.TOMLDocument,
) -> bool:
return get_tool_section(tool_name, pyproject) is not None


def _load_pysen_section(path: pathlib.Path) -> Dict[str, Any]:
if not path.exists():
raise FileNotFoundError(path)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pyproject_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
_parse_plugin_configs,
_parse_python_version,
_parse_source,
get_tool_section,
has_tool_section,
parse,
)
from pysen.source import SourceEntrySetting
Expand Down Expand Up @@ -411,11 +411,11 @@ def test_lint_config_update() -> None:
assert lhs.py_version == PythonVersion(3, 8)


def test_get_tool_section() -> None:
def test_has_tool_section() -> None:
def _check_example_toml(tool_name: str, filename: str) -> bool:
path = CONFIG_DIR / filename
pyproject = tomlkit.loads(path.read_text())
return get_tool_section(tool_name, pyproject) is not None
return has_tool_section(tool_name, pyproject)

assert not _check_example_toml("pysen", "non_pysen_config.toml")
assert not _check_example_toml("jiro", "non_pysen_config.toml")
Expand Down

0 comments on commit 4c2c2db

Please sign in to comment.