Skip to content

Commit

Permalink
use importlib_metadata rather than pbr to introspect versions at runtime
Browse files Browse the repository at this point in the history
Use of pbr at runtime is super ugly, as all it does is use pkg_resources to
parse distribution versions and pkg_resources could do the exact same thing. But
they are both slow, because pkg_resources is (by design) slow.

importlib.metadata was added to the stdlib in python 3.8 to fulfill this use
case in a speedy and elegant manner.

FIXME: this entire schema is ugly, not merely at runtime -- use of pbr for
versioning from git is an outdated and stale idea, this should use
setuptools_scm instead which:
- is standard
- supports writing the version to _version.py
  • Loading branch information
eli-schwartz committed Sep 9, 2021
1 parent ef84195 commit bc14194
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions guake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@

def guake_version():
# Do not import in the module root to speed up the dbus communication as much as possible
import pbr.version
# That being said, importlib.metadata is pretty speedy unlike pbr/pkg_resources
try:
import importlib.metadata as importlib_metadata
except ImportError:
import importlib_metadata

return pbr.version.VersionInfo("guake").version_string()
return importlib_metadata.version("guake")


def vte_version():
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
# `Pipfile.lock` and then regenerate `requirements*.txt`.
################################################################################

pbr
importlib_metadata; python_version < '3.8'
typing ; python_version < '3.5'

0 comments on commit bc14194

Please sign in to comment.