You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
922 B
31 lines
922 B
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()
|