diff --git a/datanommer.commands/datanommer/commands/__init__.py b/datanommer.commands/datanommer/commands/__init__.py
index 2b8eb2a55..2d6b77973 100644
--- a/datanommer.commands/datanommer/commands/__init__.py
+++ b/datanommer.commands/datanommer/commands/__init__.py
@@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
+import importlib.metadata
import json
import logging
import time
@@ -25,6 +26,8 @@
import datanommer.models as m
+__version__ = importlib.metadata.version("datanommer.commands")
+
log = logging.getLogger("datanommer")
@@ -335,21 +338,3 @@ def formatter(key, val):
results.append(formatter(result.category, result))
click.echo(f"[{','.join(results)}]")
-
-
-# Set the version
-try: # pragma: no cover
- import importlib.metadata
-
- __version__ = importlib.metadata.version("datanommer.commands")
-except ImportError: # pragma: no cover
- try:
- import pkg_resources
-
- try:
- __version__ = pkg_resources.get_distribution("datanommer.commands").version
- except pkg_resources.DistributionNotFound:
- # The app is not installed, but the flask dev server can run it nonetheless.
- __version__ = None
- except ImportError:
- __version__ = None
diff --git a/datanommer.consumer/datanommer/consumer/__init__.py b/datanommer.consumer/datanommer/consumer/__init__.py
index dde5ee9f3..690f44178 100644
--- a/datanommer.consumer/datanommer/consumer/__init__.py
+++ b/datanommer.consumer/datanommer/consumer/__init__.py
@@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
+import importlib.metadata
import logging
from fedora_messaging import config
@@ -20,6 +21,9 @@
import datanommer.models as m
+__version__ = importlib.metadata.version("datanommer.consumer")
+
+
def get_datanommer_sqlalchemy_url():
try:
return config.conf["consumer_config"]["datanommer_sqlalchemy_url"]
@@ -43,21 +47,3 @@ def __call__(self, message):
except Exception:
m.session.rollback()
raise
-
-
-# Set the version
-try: # pragma: no cover
- import importlib.metadata
-
- __version__ = importlib.metadata.version("datanommer.consumer")
-except ImportError: # pragma: no cover
- try:
- import pkg_resources
-
- try:
- __version__ = pkg_resources.get_distribution("datanommer.consumer").version
- except pkg_resources.DistributionNotFound:
- # The app is not installed, but the flask dev server can run it nonetheless.
- __version__ = None
- except ImportError:
- __version__ = None
diff --git a/datanommer.models/datanommer/models/__init__.py b/datanommer.models/datanommer/models/__init__.py
index 487f5f9c9..1f2e784f1 100644
--- a/datanommer.models/datanommer/models/__init__.py
+++ b/datanommer.models/datanommer/models/__init__.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
import datetime
+import importlib.metadata
import json
import logging
import math
@@ -21,7 +22,6 @@
import uuid
from warnings import warn
-import pkg_resources
from sqlalchemy import (
and_,
between,
@@ -64,6 +64,9 @@
UniqueViolation = lookup_error("23505")
+__version__ = importlib.metadata.version("datanommer.models")
+
+
log = logging.getLogger("datanommer")
maker = sessionmaker()
@@ -548,16 +551,3 @@ def _setup_hypertable(table_class):
_setup_hypertable(Message)
-
-
-# Set the version
-try: # pragma: no cover
- import importlib.metadata
-
- __version__ = importlib.metadata.version("datanommer.models")
-except ImportError: # pragma: no cover
- try:
- __version__ = pkg_resources.get_distribution("datanommer.models").version
- except pkg_resources.DistributionNotFound:
- # The app is not installed, but the flask dev server can run it nonetheless.
- __version__ = None