Skip to content

Commit 69a2340

Browse files
committed
pass 3.9 too
1 parent 9a7c346 commit 69a2340

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

codeflash/code_utils/code_utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,20 @@ def exit_with_message(message: str, *, error_on_exit: bool = False) -> None:
246246

247247
def get_installed_packages() -> list[str]:
248248
try:
249-
import importlib.metadata as importlib_metadata
250-
except ImportError:
251249
try:
252-
import importlib_metadata
250+
import importlib.metadata as importlib_metadata
253251
except ImportError:
254-
return []
252+
import importlib_metadata
253+
except ImportError:
254+
return []
255+
256+
try:
257+
pkgs = importlib_metadata.packages_distributions().keys()
258+
except AttributeError:
259+
pkgs = [dist.metadata.get("Name", "") for dist in importlib_metadata.distributions()]
255260

256-
pkgs = importlib_metadata.packages_distributions().keys()
257261
return [
258262
pkg
259263
for pkg in pkgs
260-
if not any(blacklisted in pkg for blacklisted in blacklist_installed_pkgs) and not pkg.startswith("_")
264+
if pkg and not pkg.startswith("_") and not any(blacklisted in pkg for blacklisted in blacklist_installed_pkgs)
261265
]

0 commit comments

Comments
 (0)