|
10 | 10 | import logging |
11 | 11 | import os |
12 | 12 | import sys |
| 13 | +from importlib.metadata import PackageNotFoundError, version |
13 | 14 | from logging.handlers import RotatingFileHandler |
14 | 15 | from shutil import copy |
15 | 16 | from time import localtime, strftime |
16 | 17 |
|
17 | | -import pkg_resources |
18 | | -from pkg_resources import DistributionNotFound |
19 | 18 | from requests import HTTPError |
20 | 19 |
|
21 | 20 | from genologics.config import MAIN_LOG |
@@ -83,13 +82,10 @@ def __enter__(self): |
83 | 82 | logging.info(f"Executing file: {sys.argv[0]}") |
84 | 83 | logging.info(f"with parameters: {sys.argv[1:]}") |
85 | 84 | try: |
86 | | - logging.info( |
87 | | - f"Version of {self.PACKAGE}: " |
88 | | - + pkg_resources.require(self.PACKAGE)[0].version |
89 | | - ) |
90 | | - except DistributionNotFound as e: |
| 85 | + logging.info(f"Version of {self.PACKAGE}: {version(self.PACKAGE)}") |
| 86 | + except PackageNotFoundError as e: |
91 | 87 | logging.error(e) |
92 | | - logging.error(f"Make sure you have the {self.PACKAGE} " "package installed") |
| 88 | + logging.error(f"Make sure you have the {self.PACKAGE} package installed") |
93 | 89 | sys.exit(-1) |
94 | 90 | return self |
95 | 91 |
|
@@ -182,7 +178,7 @@ def prepend_old_log(self, external_log_file=None): |
182 | 178 | f.write("=" * 80 + "\n") |
183 | 179 | except HTTPError: # Probably no artifact found, skip prepending |
184 | 180 | print( |
185 | | - ("No log file artifact found " f"for id: {log_file_name}"), |
| 181 | + (f"No log file artifact found for id: {log_file_name}"), |
186 | 182 | file=sys.stderr, |
187 | 183 | ) |
188 | 184 | except OSError as e: # Probably some path was wrong in copy |
@@ -414,7 +410,7 @@ def _log_after_change(self): |
414 | 410 | } |
415 | 411 |
|
416 | 412 | logging.info( |
417 | | - "Updated {d_elt_type} udf: {d_udf}, from {su} to " "{nv}.".format(**d) |
| 413 | + "Updated {d_elt_type} udf: {d_udf}, from {su} to {nv}.".format(**d) |
418 | 414 | ) |
419 | 415 |
|
420 | 416 | def copy_udf(self, changelog_f=None): |
|
0 commit comments