INNER CODE UNIT · Python
read_black_config
snakemake/snakefmt · snakefmt/config.py:111
def read_black_config(path: Optional[PathLike]) -> Mode:
"""Parse Black configuration from provided toml."""
black_mode = Mode(
line_length=DEFAULT_LINE_LENGTH, target_versions=DEFAULT_TARGET_VERSIONS
)
if path is None:
return black_mode
if not Path(path).is_file():
raise FileNotFoundError(f"{path} is not a file.")
try:
with open(path, "rb") as f:
pyproject_toml = tomllib.load(f)
config = pyproject_toml.get("tool", {}).get("black", {})
except tomllib.TOMLDecodeError as error:
raise MalformattedToml(error)
valid_black_filemode_params = sorted([field.name for field in fields(Mode)])