Skip to content

Commit

Permalink
Fix failed install pypi package due to unable to get version. Fix #4909
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Feb 19, 2018
1 parent 43f87a8 commit f1f51a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 41 deletions.
4 changes: 2 additions & 2 deletions safe/common/test/test_version.py
Expand Up @@ -80,14 +80,14 @@ def test_compare_version(self):
for line in fid.readlines():
if line.startswith('version'):
version_metadata = line.strip().split('=')[1]
self.assertEqual(version_metadata, inasafe_version)

if line.startswith('status'):
status_metadata = line.strip().split('=')[1]
self.assertEqual(status_metadata, inasafe_release_status)

fid.close()

self.assertEqual(version_metadata, inasafe_version)
self.assertEqual(status_metadata, inasafe_release_status)

if __name__ == '__main__':
unittest.main()
57 changes: 18 additions & 39 deletions setup.py
Expand Up @@ -10,49 +10,28 @@
from setuptools import setup, find_packages


def get_version(version=None):
"""Returns a PEP 386-compliant version number from VERSION.
def get_version():
"""Obtain InaSAFE's version from version file.
:param version: A tuple that represent a version.
:type version: tuple
:returns: a PEP 386-compliant version number.
:returns: The current version number.
:rtype: str
"""
if version is None:
# Get location of application wide version info
root_dir = os.path.abspath(os.path.join(
os.path.dirname(__file__)))
fid = open(os.path.join(root_dir, 'metadata.txt'))
version_list = []
status = ''
for line in fid.readlines():
if line.startswith('version'):
version_string = line.strip().split('=')[1]
version_list = version_string.split('.')

if line.startswith('status'):
status = line.strip().split('=')[1]
fid.close()
version = tuple(version_list + [status] + ['0'])

if len(version) != 5:
msg = 'Version must be a tuple of length 5. I got %s' % (version,)
raise RuntimeError(msg)

if version[3] not in ('alpha', 'beta', 'rc', 'final'):
msg = 'Version tuple not as expected. I got %s' % (version,)
raise RuntimeError(msg)

# Now build the two parts of the version number:
# main = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|c}N - for alpha, beta and rc releases
parts = 2 if version[2] == 0 else 3
main = '.'.join(str(x) for x in version[:parts])

return main
# Get location of application wide version info
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__)))
version_file = os.path.join(root_dir, 'safe', 'definitions', 'versions.py')
fid = open(version_file)
version = ''
for line in fid.readlines():
if line.startswith('inasafe_version'):
version = line.strip().split(' = ')[1]
version = version.replace('\'', '')
break
fid.close()
if version:
return version
else:
raise Exception('Version is not found in %s' % version_file)


setup(
Expand Down

0 comments on commit f1f51a2

Please sign in to comment.