Skip to content

Commit

Permalink
Merge pull request #410 from malthe/fix-pypy
Browse files Browse the repository at this point in the history
Fix pypy compatibility (not all distributions are packages)
  • Loading branch information
malthe authored Jan 18, 2024
2 parents 8ffa8e1 + 2b3e54b commit 6cab7dc
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/chameleon/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,25 @@
from chameleon.compiler import ExpressionEngine


def get_package_versions() -> list[tuple[str, str]]:
if sys.version_info >= (3, 10):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata
if sys.version_info >= (3, 10):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata


def safe_get_package_version(name: str) -> str | None:
try:
return importlib_metadata.version(name)
except importlib_metadata.PackageNotFoundError:
return None


def get_package_versions() -> list[tuple[str, str]]:
distributions = importlib_metadata.packages_distributions().values()
versions = {
x: importlib_metadata.version(x)
for x in sum(importlib_metadata.packages_distributions().values(), [])}
x: safe_get_package_version(x) or ""
for x in sum(distributions, [])
}
return sorted(versions.items())


Expand Down

0 comments on commit 6cab7dc

Please sign in to comment.