def get_version()

in metaflow/metaflow_version.py [0:0]


def get_version(public=False):
    """Tracks the version number.

    public: bool
        When True, this function returns a *public* version specification which
        doesn't include any local information (dirtiness or hash). See
        https://packaging.python.org/en/latest/specifications/version-specifiers/#version-scheme

    We first check the INFO file to see if we recorded a version of Metaflow. If there
    is none, we check if we are in a GIT repository and if so, form the version
    from that.

    Otherwise, we return the version of Metaflow that was installed.

    """

    global _version_cache

    # To get the version we do the following:
    #  - Check if we have a cached version. If so, return that
    #  - Then check if we have an INFO file present. If so, use that as it is
    #    the most reliable way to get the version. In particular, when running remotely,
    #    metaflow is installed in a directory and if any extension is using distutils to
    #    determine its version, this would return None and querying the version directly
    #    from the extension would fail to produce the correct result
    #  - Then if we are in the GIT repository and if so, use the git describe
    #  - If we don't have an INFO file, we look at the version information that is
    #    populated by metaflow and the extensions.

    if _version_cache[public] is not None:
        return _version_cache[public]

    version = (
        read_info_version()
    )  # Version info is cached in INFO file; includes extension info

    if version:
        _version_cache[public] = version
        return version

    # Get the version for Metaflow, favor the GIT version
    import metaflow

    version = format_git_describe(
        call_git_describe(file_to_check=metaflow.__file__), public=public
    )
    if version is None:
        version = metaflow.__version__

    # Look for extensions and compute their versions. Properly formed extensions have
    # a toplevel file which will contain a __mf_extensions__ value and a __version__
    # value. We already saved the properly formed modules when loading metaflow in
    # __ext_tl_modules__.
    ext_versions = []
    for pkg_name, extension_module in metaflow.__ext_tl_modules__:
        ext_name = getattr(extension_module, "__mf_extensions__", "<unk>")
        ext_version = format_git_describe(
            call_git_describe(file_to_check=extension_module.__file__), public=public
        )
        if ext_version is None:
            ext_version = getattr(extension_module, "__version__", "<unk>")
        # Update the package information about reported version for the extension
        # (only for the full info which is called at least once -- if we update more
        # it will error out since we can only update_package_info once)
        if not public:
            update_package_info(
                package_name=pkg_name,
                extension_name=ext_name,
                package_version=ext_version,
            )
        ext_versions.append("%s(%s)" % (ext_name, ext_version))

    # We now have all the information about extensions so we can form the final string
    if ext_versions:
        version = version + "+" + ";".join(ext_versions)
    _version_cache[public] = version
    return version