Skip to content

Commit

Permalink
Don't use pkg_resources
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Mar 28, 2024
1 parent b5812fc commit 5cff54a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 50 deletions.
21 changes: 3 additions & 18 deletions datanommer.commands/datanommer/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
import importlib.metadata
import json
import logging
import time
Expand All @@ -25,6 +26,8 @@
import datanommer.models as m


__version__ = importlib.metadata.version("datanommer.commands")

log = logging.getLogger("datanommer")


Expand Down Expand Up @@ -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
22 changes: 4 additions & 18 deletions datanommer.consumer/datanommer/consumer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
import importlib.metadata
import logging

from fedora_messaging import config

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"]
Expand All @@ -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
18 changes: 4 additions & 14 deletions datanommer.models/datanommer/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
import datetime
import importlib.metadata
import json
import logging
import math
import traceback
import uuid
from warnings import warn

import pkg_resources
from sqlalchemy import (
and_,
between,
Expand Down Expand Up @@ -64,6 +64,9 @@
UniqueViolation = lookup_error("23505")


__version__ = importlib.metadata.version("datanommer.models")


log = logging.getLogger("datanommer")

maker = sessionmaker()
Expand Down Expand Up @@ -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

0 comments on commit 5cff54a

Please sign in to comment.