File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,18 @@ def _py_abspath(path):
24
24
return os .path .abspath (path )
25
25
26
26
27
+ def distribution_version (name ):
28
+ """try to get the version of the named distribution,
29
+ returs None on failure"""
30
+ from pkg_resources import get_distribution , DistributionNotFound
31
+ try :
32
+ dist = get_distribution (name )
33
+ except DistributionNotFound :
34
+ pass
35
+ else :
36
+ return dist .version
37
+
38
+
27
39
def initpkg (pkgname , exportdefs , attr = dict ()):
28
40
""" initialize given package from the export definitions. """
29
41
oldmod = sys .modules .get (pkgname )
Original file line number Diff line number Diff line change @@ -526,3 +526,8 @@ def test_initpkg_without_old_module():
526
526
dict (modules = "sys:modules" ))
527
527
from initpkg_without_old_module import modules
528
528
assert modules is sys .modules
529
+
530
+
531
+ def test_get_distribution_version ():
532
+ assert apipkg .distribution_version ('setuptools' ) is not None
533
+ assert apipkg .distribution_version ('email' ) is None
You can’t perform that action at this time.
0 commit comments