Skip to content

Commit

Permalink
MAINT: use importlib to get version information (#840)
Browse files Browse the repository at this point in the history
* MAINT: use importlib to get version information

* TYPO: fix variable name
  • Loading branch information
ColmTalbot authored Nov 6, 2024
1 parent 442f747 commit 3f3462c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bilby/core/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import subprocess
import sys
from importlib import metadata

logger = logging.getLogger('bilby')

Expand Down Expand Up @@ -69,8 +70,11 @@ def loaded_modules_dict():
module_names = list(sys.modules.keys())
vdict = {}
for key in module_names:
if "." not in str(key):
vdict[key] = str(getattr(sys.modules[key], "__version__", "N/A"))
if "." not in key:
try:
vdict[key] = metadata.version(key)
except metadata.PackageNotFoundError:
continue
return vdict


Expand Down

0 comments on commit 3f3462c

Please sign in to comment.