Unverified Commit 6ebdc5a6 authored by Richard Si's avatar Richard Si Committed by GitHub
Browse files

Fix toml parsing and bump toml from 0.10.0 to 0.10.1 (#1501)

* Bump toml from 0.10.0 to 0.10.1 to fix a bug

* Add tests for TOML parsing and reading

* Fix configuration bug affecting vim plugin

The vim plugin directly calls parse_pyproject and skips the Click processing
, but parse_pyproject assumed that it would only be used before Click processing
and therefore made the config values click friendly. This moves the "make the values
click friendly processing" into read_pyproject_toml which is only called by a Click
callback.

* Please mypy and flake8
parent e4c55b48
Loading
Loading
Loading
Loading
+19 −19
Changes for Pipfile: 19 added lines, 19 removed lines.
Original line number Diff line number Diff line
[[source]]
name = "pypi"
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]
aiohttp = ">=3.3.2"
click = ">=6.5"
appdirs = "*"
toml = ">=0.9.4"
black = {path = ".",extras = ["d"],editable = true}
aiohttp-cors = "*"
typed-ast = "==1.4.0"
typing_extensions = ">=3.7.4"
mypy_extensions = ">=0.4.3"
regex = ">=2019.8"
pathspec = ">=0.6"
dataclasses = {version = ">=0.6",python_version = "< 3.7"}

[dev-packages]
pre-commit = "*"
Sphinx = "*"
coverage = "*"
docutils = "==0.15"  # not a direct dependency, see https://github.com/pypa/pipenv/issues/3865
flake8 = "*"
flake8-bugbear = "*"
flake8-mypy = "*"
mypy = ">=0.740"
pre-commit = "*"
readme_renderer = "*"
recommonmark = "*"
Sphinx = "*"
setuptools = ">=39.2.0"
setuptools-scm = "*"
twine = ">=1.11.0"
wheel = ">=0.31.1"
setuptools-scm = "*"
black = {path = ".",extras = ["d"],editable = true}
black = {editable = true,extras = ["d"],path = "."}

[packages]
aiohttp = ">=3.3.2"
aiohttp-cors = "*"
appdirs = "*"
click = ">=6.5"
mypy_extensions = ">=0.4.3"
pathspec = ">=0.6"
regex = ">=2019.8"
toml = "==0.10.1"
typed-ast = "==1.4.0"
typing_extensions = ">=3.7.4"
black = {editable = true,extras = ["d"],path = "."}
dataclasses = {"python_version <" = "3.7","version >" = "0.6"}
+119 −75

File changed.

Preview size limit exceeded, changes collapsed.

+9 −6
Changes for src/black/__init__.py: 9 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -281,12 +281,7 @@ def parse_pyproject_toml(path_config: str) -> Dict[str, Any]:
    """
    pyproject_toml = toml.load(path_config)
    config = pyproject_toml.get("tool", {}).get("black", {})
    return {
        k.replace("--", "").replace("-", "_"): str(v)
        if not isinstance(v, (list, dict))
        else v
        for k, v in config.items()
    }
    return {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}


def read_pyproject_toml(
@@ -311,6 +306,14 @@ def read_pyproject_toml(

    if not config:
        return None
    else:
        # Sanitize the values to be Click friendly. For more information please see:
        # https://github.com/psf/black/issues/1458
        # https://github.com/pallets/click/issues/1567
        config = {
            k: str(v) if not isinstance(v, (list, dict)) else v
            for k, v in config.items()
        }

    target_version = config.get("target_version")
    if target_version is not None and not isinstance(target_version, list):

tests/test.toml

0 → 100644
+10 −0
Changes for tests/test.toml: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
[tool.black]
verbose = 1
--check = "no"
diff = "y"
color = true
line-length = 79
target-version = ["py36", "py37", "py38"]
exclude='\.pyi?$'
include='\.py?$'
+40 −1

File changed.

Preview size limit exceeded, changes collapsed.