From e9bfc3fc957e846a0a01f4daa6677cd85bb4ef62 Mon Sep 17 00:00:00 2001 From: Jan Rodak Date: Wed, 26 Jul 2023 12:31:54 +0200 Subject: [PATCH] Fix deprecation warning DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html --- openscap_report/__init__.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/openscap_report/__init__.py b/openscap_report/__init__.py index 52a550d7..be7fcf72 100644 --- a/openscap_report/__init__.py +++ b/openscap_report/__init__.py @@ -1,14 +1,11 @@ # Copyright 2022, Red Hat, Inc. # SPDX-License-Identifier: LGPL-2.1-or-later +from importlib.metadata import PackageNotFoundError, version from os import path -from pkg_resources import DistributionNotFound, get_distribution - DISTRIBUTION_NAME = "openscap-report" try: - distribution = get_distribution(DISTRIBUTION_NAME) -except DistributionNotFound: + __version__ = version(DISTRIBUTION_NAME) +except PackageNotFoundError: __version__ = f"Version is unavailable. Please install {DISTRIBUTION_NAME}!" -else: - __version__ = distribution.version