MCPcopy
hub / github.com/psf/black / parse_pyproject_toml

Function parse_pyproject_toml

src/black/files.py:121–135  ·  view source on GitHub ↗

Parse a pyproject toml file, pulling out relevant parts for Black. If parsing fails, will raise a tomllib.TOMLDecodeError.

(path_config: str)

Source from the content-addressed store, hash-verified

119
120@mypyc_attr(patchable=True)
121def parse_pyproject_toml(path_config: str) -> dict[str, Any]:
122 """Parse a pyproject toml file, pulling out relevant parts for Black.
123
124 If parsing fails, will raise a tomllib.TOMLDecodeError.
125 """
126 pyproject_toml = _load_toml(path_config)
127 config: dict[str, Any] = pyproject_toml.get("tool", {}).get("black", {})
128 config = {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}
129
130 if "target_version" not in config:
131 inferred_target_version = infer_target_version(pyproject_toml)
132 if inferred_target_version is not None:
133 config["target_version"] = [v.name.lower() for v in inferred_target_version]
134
135 return config
136
137
138def infer_target_version(

Callers 1

read_pyproject_tomlFunction · 0.90

Calls 3

_load_tomlFunction · 0.85
infer_target_versionFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected