From 5f73a35afbca485b7bcfd5f5b02f56224ea138a5 Mon Sep 17 00:00:00 2001 From: thorbjoernl <51087536+thorbjoernl@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:19:16 +0200 Subject: [PATCH] fix: version issue in Pyaerocom tests --- src/aerovaldb/jsondb/jsonfiledb.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/aerovaldb/jsondb/jsonfiledb.py b/src/aerovaldb/jsondb/jsonfiledb.py index 42860fb..e4daf82 100644 --- a/src/aerovaldb/jsondb/jsonfiledb.py +++ b/src/aerovaldb/jsondb/jsonfiledb.py @@ -8,6 +8,7 @@ import orjson from async_lru import alru_cache from packaging.version import Version +from pkg_resources import get_distribution # type: ignore from aerovaldb.aerovaldb import AerovalDB from aerovaldb.exceptions import UnusedArguments, TemplateNotFound @@ -232,7 +233,14 @@ async def _get_version(self, project: str, experiment: str) -> Version: version_str = config["exp_info"]["pyaerocom_version"] version = Version(version_str) except KeyError: - version = Version("0.0.1") + try: + # If pyaerocom is installed in the current environment, but no config has + # been written, we use the version of the installed pyaerocom. This is + # important for tests to work correctly, and for files to be written + # correctly if the config file happens to be written after data files. + version = Version(get_distribution("pyaerocom").version) + except KeyError: + version = Version("0.0.1") return version