示例#1
0
def test_dump_with_Version():
    # MyPy doesn't understand deeply nested dicts correctly
    example: Dict[str, Dict[str, List[Dict[str, Printable]]]] = {
        "windows": {
            "python_configurations": [
                {
                    "identifier": "cp27-win32",
                    "version": Version("2.7.18"),
                    "arch": "32"
                },
                {
                    "identifier": "cp27-win_amd64",
                    "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 = dump_python_configurations(example)
    print(output)
    assert output == result
示例#2
0
def test_compare_configs():
    with open(resources_dir / "build-platforms.toml") as f1:
        txt = f1.read()

    with open(resources_dir / "build-platforms.toml", "rb") as f2:
        dict_txt = tomli.load(f2)

    new_txt = dump_python_configurations(dict_txt)
    print(new_txt)

    assert new_txt == txt
示例#3
0
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()
    with toml_file_path.open("rb") as f:
        configs = tomllib.load(f)

    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 = dump_python_configurations(configs)

    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.")