# based on https://coverage.readthedocs.io/en/stable/config.htmlfromcollections.abcimportMutableMappingfromfunctoolsimportpartial,update_wrapperfromtypingimportTypeVarfrom..transformationsimportcoerce_scalar,split_listfrom..typesimportTransformationasTfrom..typesimportTranslatorM=TypeVar("M",bound=MutableMapping)
classCoverage:"""Convert settings to 'pyproject.toml' equivalent"""PREFIX="coverage:"SECTIONS=("run","paths","report","html","xml","json")LIST_VALUES=("exclude_lines","concurrency","disable_warnings","debug","include","omit","plugins","source","source_pkgs","partial_branches",)defprocess_values(self,doc:M,sections=SECTIONS,prefix=PREFIX)->M:fornameinsections:candidates=[doc.get(f"{prefix}{name}"),doc.get("tool",{}).get("coverage",{}).get(name),doc.get(("tool","coverage"),{}).get(name),doc.get(("tool","coverage",name)),]forsectionincandidates:ifsection:self.process_section(section)returndocdefprocess_section(self,section:M):forfieldinsection:fn:T=split_listiffieldinself.LIST_VALUESelsecoerce_scalarsection[field]=fn(section[field])