def version_string(static_version, commit_hash, build_number):
    """
    Format a full version string version.build_number~commit_hash.
    :param static_version: manually managed (static) version part, e.g. 0.1.5
    :param commit_hash: commit hash (optional)
    :param build_number: build number (doesn't have to be a number
    :return: str
    """
    return '{}.{}~{}'.format(static_version, build_number, commit_hash[:7]) if commit_hash \
           else '{}.{}'.format(static_version, build_number)