Ejemplo n.º 1
0
def insert_new_group_id_into_library_versions_toml(group_id):
    """Inserts a group ID into the libraryversions.toml file.

    If one already exists, then this function just returns and reuses
    the existing one.

    Args:
        group_id: group_id of the new library
    """
    new_group_id_variable_name = group_id.replace("androidx.","").replace(".","_").upper()

    # Open toml file
    library_versions = toml.load(LIBRARY_VERSIONS_FP)
    if not new_group_id_variable_name in library_versions["versions"]:
        library_versions["versions"][new_group_id_variable_name] = "1.0.0-alpha01"
    if not new_group_id_variable_name in library_versions["groups"]:
        decoder = toml.decoder.TomlDecoder()
        group_entry = decoder.get_empty_inline_table()
        group_entry["group"] = group_id
        group_entry["atomicGroupVersion"] = "versions." + new_group_id_variable_name
        library_versions["groups"][new_group_id_variable_name] = group_entry

    # Sort the entries
    library_versions["versions"] = dict(sorted(library_versions["versions"].items()))
    library_versions["groups"] = dict(sorted(library_versions["groups"].items()))

    # Open file for writing and update toml
    with open(LIBRARY_VERSIONS_FP, 'w') as f:
        toml.dump(library_versions, f, encoder=toml.TomlPreserveInlineDictEncoder())
Ejemplo n.º 2
0
def _toml_inline(**d):
    class InlineDict(dict, toml.decoder.InlineTableDict):
        pass

    for k, v in d.items():
        d[k] = InlineDict(v)
    return toml.dumps(d, encoder=toml.TomlPreserveInlineDictEncoder())
Ejemplo n.º 3
0
def update_versions_in_library_versions_toml(group_id, artifact_id,
                                             old_version):
    """Updates the versions in the libraryversions.toml file.

    This will take the old_version and increment it to find the appropriate
    new version.

    Args:
        group_id: group_id of the existing library
        artifact_id: artifact_id of the existing library
        old_version: old version of the existing library

    Returns:
        True if the version was updated, false otherwise.
    """
    group_id_variable_name = group_id.replace("androidx.",
                                              "").replace(".", "_").upper()
    artifact_id_variable_name = artifact_id.replace("androidx.",
                                                    "").replace("-",
                                                                "_").upper()
    new_version = increment_version(old_version)
    # Special case Compose because it uses the same version variable.
    if (group_id_variable_name.startswith("COMPOSE")
            and group_id_variable_name != "COMPOSE_MATERIAL3"):
        group_id_variable_name = "COMPOSE"

    # Open toml file
    library_versions = toml.load(LIBRARY_VERSIONS_FP)
    updated_version = False

    # First check any artifact ids with unique versions.
    if artifact_id_variable_name in library_versions["versions"]:
        old_version = library_versions["versions"][artifact_id_variable_name]
        if should_update_version_in_library_versions_toml(
                old_version, new_version, group_id):
            library_versions["versions"][
                artifact_id_variable_name] = new_version
            updated_version = True

    if not updated_version:
        # Then check any group ids.
        if group_id_variable_name in library_versions["versions"]:
            old_version = library_versions["versions"][group_id_variable_name]
            if should_update_version_in_library_versions_toml(
                    old_version, new_version, group_id):
                library_versions["versions"][
                    group_id_variable_name] = new_version
                updated_version = True

    # sort the entries
    library_versions["versions"] = dict(
        sorted(library_versions["versions"].items()))

    # Open file for writing and write toml back
    with open(LIBRARY_VERSIONS_FP, 'w') as f:
        toml.dump(library_versions,
                  f,
                  encoder=toml.TomlPreserveInlineDictEncoder())
    return updated_version
Ejemplo n.º 4
0
def write_toml(p, data):
    spec = {
        'source': source,
        'packages': {},
        'dev-packages': {},
        'requires': requires
    }
    spec.update(data)
    p.write_text(toml.dumps(spec, toml.TomlPreserveInlineDictEncoder()))
Ejemplo n.º 5
0
def test_inline_dict():
    class TestDict(dict, InlineTableDict):
        pass

    encoder = toml.TomlPreserveInlineDictEncoder()
    t = copy.deepcopy(TEST_DICT)
    t['d'] = TestDict()
    t['d']['x'] = "abc"
    o = toml.loads(toml.dumps(t, encoder=encoder))
    assert o == toml.loads(toml.dumps(o, encoder=encoder))
Ejemplo n.º 6
0
def write_pyproject(p, data):
    spec = {
        'build-system': {
            'requires': ["setuptools", "wheel"],
            'build-backend': "setuptools.build_meta",
        },
        'tool': {
            'setuptools-pipfile': data
        },
    }
    p.write_text(toml.dumps(spec, toml.TomlPreserveInlineDictEncoder()))