--- a/src/fablib/core.py Thu Jun 20 11:14:12 2013 +0200
+++ b/src/fablib/core.py Thu Jun 20 14:01:48 2013 +0200
@@ -119,6 +119,17 @@
finally:
os.chdir(current_path)
print("Build source dist at %s done" % path)
+
+def get_version(version):
+ version_str = '%s.%s' % (version[0], version[1])
+ if version[2]:
+ version_str = '%s.%s' % (version_str, version[2])
+ if version[3:] == ('alpha', 0):
+ version_str = '%s pre-alpha' % version_str
+ else:
+ if version[3] != 'final':
+ version_str = '%s %s %s' % (version_str, version[3], version[4])
+ return version_str
def get_src_version(key, path):
@@ -134,18 +145,34 @@
try:
f, pathname, description = imp.find_module(mod_name, [path])
src_mod = imp.load_module(mod_name, f, pathname, description)
+ except:
+ src_mod = None
+ print("Could not import module, trying to parse")
finally:
os.chdir(current_path)
if f:
f.close()
- if hasattr(src_mod, "VERSION"):
+ version = None
+ if src_mod is None:
+ with open(os.path.join(mod_name,"__init__.py"),'r') as init_file:
+ for line in init_file:
+ m = re.search('VERSION\s+=\s+\((.+)\)', line, re.I)
+ if m:
+ version = tuple([re.sub('[\s\"\']','', item) for item in m.group(1).split(',')])
+ break
+ elif hasattr(src_mod, "VERSION"):
version = src_mod.VERSION
elif hasattr(src_mod, "__version__"):
version = src_mod.__version__
+ if version is None:
+ version = ""
+
if not isinstance(version, basestring):
- if hasattr(src_mod, "get_version"):
+ if src_mod and hasattr(src_mod, "get_version"):
version_str = src_mod.get_version()
+ elif isinstance(version, tuple):
+ version_str = get_version(version)
else:
version_str = str(version)
else: