refactor: identifiers in a file (#511)

* refactor: identifiers in a file

* chore: more typing

* refactor: PlatStr -> PlatformName

* refactor: load in file, use importlib.resources

* refactor: change toml structure

* refactor: use common Traversable

* fix: ensure reasonable version of importlib_resources

* style: fix extra line
This commit is contained in:
Henry Schreiner
2021-01-09 15:40:40 -05:00
committed by GitHub
parent 635b226a6c
commit 5eb5ea10f5
9 changed files with 180 additions and 92 deletions
+28
View File
@@ -0,0 +1,28 @@
import toml
from toml.encoder import TomlEncoder
from cibuildwheel.util import resources_dir
class InlineArrayDictEncoder(TomlEncoder):
def dump_sections(self, o: dict, sup: str):
if all(isinstance(a, list) for a in o.values()):
val = ""
for k, v in o.items():
inner = ",\n ".join(self.dump_inline_table(d_i).strip() for d_i in v)
val += f"{k} = [\n {inner},\n]\n"
return val, self._dict()
else:
return super().dump_sections(o, sup)
def test_compare_configs():
with open(resources_dir / "build-platforms.toml") as f:
txt = f.read()
dict_txt = toml.loads(txt)
new_txt = toml.dumps(dict_txt, encoder=InlineArrayDictEncoder())
print(new_txt)
assert new_txt == txt