import importlib.metadata import logging import os import pathlib import toml LOG = logging.getLogger("acm.version") def __get_version(): """ Automatically determine the version of the application being run """ # Attempt to read the installed package information try: return importlib.metadata.version('asset-compression-manager') except importlib.metadata.PackageNotFoundError: LOG.debug("The package is not installed, reading the version from another source") # Fallback on parsing the pyproject.toml file root_dir = pathlib.Path(__file__).parent.parent.resolve() with open(os.path.join(root_dir, "pyproject.toml"), "r") as project_file: project = toml.load(project_file) return project["tool"]["poetry"]["version"] LOG.debug("Falling back on UNKNOWN version identifier") return "UNKNOWN" # Application Version VERSION = __get_version()