Beispiel #1
0
def test_dump_with_Version():
    example = {
        "windows": {
            "python_configurations": [
                {
                    "identifier": "cp27-win32",
                    "version": Version("2.7.18"),
                    "arch": "32"
                },
                {
                    "identifier": "cp27-win_amd64",
                    "version": Version("2.7.18"),
                    "arch": "64"
                },
            ]
        }
    }

    result = """\
[windows]
python_configurations = [
  { identifier = "cp27-win32", version = "2.7.18", arch = "32" },
  { identifier = "cp27-win_amd64", version = "2.7.18", arch = "64" },
]
"""

    output = toml.dumps(example, encoder=InlineArrayDictEncoder())
    print(output)
    assert output == result
Beispiel #2
0
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
def update_pythons(force: bool, level: str) -> None:

    logging.basicConfig(
        level="INFO",
        format="%(message)s",
        datefmt="[%X]",
        handlers=[RichHandler(rich_tracebacks=True, markup=True)],
    )
    log.setLevel(level)

    all_versions = AllVersions()
    toml_file_path = RESOURCES_DIR / "build-platforms.toml"

    original_toml = toml_file_path.read_text()
    configs = toml.loads(original_toml)

    for config in configs["windows"]["python_configurations"]:
        all_versions.update_config(config)

    for config in configs["macos"]["python_configurations"]:
        all_versions.update_config(config)

    result_toml = toml.dumps(configs,
                             encoder=InlineArrayDictEncoder())  # type: ignore

    rich.print()  # spacer

    if original_toml == result_toml:
        rich.print("[green]Check complete, Python configurations unchanged.")
        return

    rich.print("Python configurations updated.")
    rich.print("Changes:")
    rich.print()

    toml_relpath = toml_file_path.relative_to(DIR).as_posix()
    diff_lines = difflib.unified_diff(
        original_toml.splitlines(keepends=True),
        result_toml.splitlines(keepends=True),
        fromfile=toml_relpath,
        tofile=toml_relpath,
    )
    rich.print(Syntax("".join(diff_lines), "diff", theme="ansi_light"))
    rich.print()

    if force:
        toml_file_path.write_text(result_toml)
        rich.print("[green]TOML file updated.")
    else:
        rich.print("[yellow]File left unchanged. Use --force flag to update.")