diff --git a/src/aerovaldb/jsondb/jsonfiledb.py b/src/aerovaldb/jsondb/jsonfiledb.py index e4daf82..4613912 100644 --- a/src/aerovaldb/jsondb/jsonfiledb.py +++ b/src/aerovaldb/jsondb/jsonfiledb.py @@ -8,7 +8,7 @@ import orjson from async_lru import alru_cache from packaging.version import Version -from pkg_resources import get_distribution # type: ignore +from pkg_resources import DistributionNotFound, get_distribution # type: ignore from aerovaldb.aerovaldb import AerovalDB from aerovaldb.exceptions import UnusedArguments, TemplateNotFound @@ -224,7 +224,16 @@ async def _get_version(self, project: str, experiment: str) -> Version: try: config = await self.get_config(project, experiment) except FileNotFoundError: - return 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 DistributionNotFound: + version = Version("0.0.1") + finally: + return version except orjson.JSONDecodeError: # Work around for https://github.com/metno/aerovaldb/issues/28 return Version("0.14.0") @@ -233,14 +242,7 @@ async def _get_version(self, project: str, experiment: str) -> Version: version_str = config["exp_info"]["pyaerocom_version"] version = Version(version_str) except KeyError: - 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") + version = Version("0.0.1") return version