File: version.py

package info (click to toggle)
python-trame-server 3.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 480 kB
  • sloc: python: 4,075; javascript: 5; sh: 4; makefile: 3
file content (22 lines) | stat: -rw-r--r-- 590 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
try:
    # Use importlib metadata if available (python >=3.8)
    from importlib.metadata import PackageNotFoundError, version
except ImportError:
    # No importlib metadata. Try to use pkg_resources instead.
    from pkg_resources import (
        DistributionNotFound as PackageNotFoundError,
    )
    from pkg_resources import (
        get_distribution,
    )

    def version(x):
        return get_distribution(x).version


def get_version(package_name):
    try:
        return version(package_name)
    except PackageNotFoundError:
        # package is not installed
        pass