Unverified Commit 2946d3b0 authored by Richard Si's avatar Richard Si Committed by GitHub
Browse files

Switch `toml` TOML library for `tomli` (#2301)

toml unfortunately has a lack of maintainership issue right now. It's
evident by the fact toml only supports TOML v0.5.0. TOML v1.0.0 has
been recently released and right now Black crashes hard on its usage.

tomli is a brand new parse only TOML library. It supports TOML
v1.0.0. Although TBH we're switching to this one mostly because
pip is doing the same.

*The upper bound was included at the library maintainer's request.

Co-authored-by: default avatarŁukasz Langa <lukasz@langa.pl>
Co-authored-by: default avatarTaneli Hukkinen <3275109+hukkin@users.noreply.github.com>
parent c64fb8cb
Loading
Loading
Loading
Loading
+2 −0
Changes for CHANGES.md: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@

### _Black_

- Configuration files using TOML features higher than spec v0.5.0 are now supported
  (#2301)
- Add primer support and test for code piped into black via STDIN (#2315)
- Fix internal error when `FORCE_OPTIONAL_PARENTHESES` feature is enabled (#2332)
- Accept empty stdin (#2346)
+1 −1
Changes for Pipfile: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ click = ">=8.0.0"
mypy_extensions = ">=0.4.3"
pathspec = ">=0.8.1"
regex = ">=2020.1.8"
toml = ">=0.10.1"
tomli = ">=0.2.6, <2.0.0"
typed-ast = "==1.4.2"
typing_extensions = {"python_version <" = "3.8","version >=" = "3.7.4"}
black = {editable = true,extras = ["d"],path = "."}
+195 −196

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Changes for setup.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ def get_long_description() -> str:
    install_requires=[
        "click>=7.1.2",
        "appdirs",
        "toml>=0.10.1",
        "tomli>=0.2.6,<2.0.0",
        "typed-ast>=1.4.2; python_version < '3.8'",
        "regex>=2020.1.8",
        "pathspec>=0.8.1, <1",
+4 −3
Changes for src/black/files.py: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
)

from pathspec import PathSpec
import toml
import tomli

from black.output import err
from black.report import Report
@@ -89,9 +89,10 @@ def find_pyproject_toml(path_search_start: Tuple[str, ...]) -> Optional[str]:
def parse_pyproject_toml(path_config: str) -> Dict[str, Any]:
    """Parse a pyproject toml file, pulling out relevant parts for Black

    If parsing fails, will raise a toml.TomlDecodeError
    If parsing fails, will raise a tomli.TOMLDecodeError
    """
    pyproject_toml = toml.load(path_config)
    with open(path_config, encoding="utf8") as f:
        pyproject_toml = tomli.load(f)
    config = pyproject_toml.get("tool", {}).get("black", {})
    return {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}

Loading