"""Django app providing ``HashableFileFieldsBaseModel``, a base django model to automatically compute
file-fields hashes."""

from os import path

import pkg_resources
from setuptools.config import read_configuration


def _extract_version(package_name):
    """Extract the installed version of the given package name.

    Parameters
    ----------
    package_name : str
        The package for which we want the version

    Returns
    -------
    str
        The installed version as a string

    """
    try:
        # if package is installed
        version = pkg_resources.get_distribution(package_name).version
    except pkg_resources.DistributionNotFound:
        # if not installed, so we must be in source, with ``setup.cfg`` available
        _conf = read_configuration(path.join(path.dirname(__file__), "..", "setup.cfg"))
        version = _conf["metadata"]["version"]

    return version


__version__ = _extract_version("django_hashable_file_fields")
VERSION = tuple(int(part) for part in __version__.split(".") if str(part).isnumeric())
