Skip to content

Commit

Permalink
get rid of manual Version parsing class
Browse files Browse the repository at this point in the history
  • Loading branch information
renefritze committed Jan 6, 2017
1 parent d508fec commit 90a1e95
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 62 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -117,7 +117,7 @@ def __getattr__(cls, name):
# The default replacements for |version| and |release|, also used in various
# other places throughout the built documents.
#
version = str(pymor.VERSION)
version = pymor.__version__

# The full version, including alpha/beta/rc tags.
release = version.split('-')[0]
Expand Down
57 changes: 0 additions & 57 deletions src/pymor/__init__.py
Expand Up @@ -15,62 +15,6 @@
from pymor.core.defaults import load_defaults_from_file


class Version(object):
def __init__(self, revstring):

# special casing for debian versions like '0.1.3~precise~ppa9'
if '~' in revstring:
revstring = revstring[:revstring.index('~')]
revstringparts = revstring.strip().split('-')
if len(revstringparts) not in (1, 3):
raise ValueError('Invalid revstring: ' + revstring)
if len(revstringparts) == 3:
self.distance = int(revstringparts[1])
self.shorthash = revstringparts[2]
else:
self.distance = 0
self.shorthash = ''

version_parts = revstringparts[0].split('.')
if version_parts[-1].find('rc') >= 0:
s = version_parts[-1].split('rc')
if len(s) != 2:
raise ValueError('Invalid revstring')
version_parts[-1] = s[0]
self.rc_number = int(s[1])
self.has_rc_number = True
else:
self.rc_number = 0
self.has_rc_number = False

self.version = tuple(int(x) for x in version_parts)
self.full_version = self.version + (self.rc_number,)

def __eq__(self, other):
if not isinstance(other, Version):
other = Version(other)
return self.version == other.version and self.rc_number == other.rc_number and self.distance == other.distance

def __lt__(self, other):
if not isinstance(other, Version):
other = Version(other)
return self.full_version < other.full_version

def __gt__(self, other):
if not isinstance(other, Version):
other = Version(other)
return self.full_version > other.full_version

def __str__(self):
git_part = '-{}-{}'.format(self.distance, self.shorthash) if self.distance else ''
version_part = '.'.join(map(str, self.version))
rc_part = 'rc{}'.format(self.rc_number) if self.has_rc_number else ''
return version_part + rc_part + git_part

def __repr__(self):
return 'Version({})'.format(str(self))


if 'PYMOR_DEB_VERSION' in os.environ:
revstring = os.environ['PYMOR_DEB_VERSION']
else:
Expand All @@ -79,7 +23,6 @@ def __repr__(self):

__version__ = str(revstring)


import os
if 'PYMOR_DEFAULTS' in os.environ:
filename = os.environ['PYMOR_DEFAULTS']
Expand Down
2 changes: 1 addition & 1 deletion src/pymor/core/config.py
Expand Up @@ -115,7 +115,7 @@ def __repr__(self):
Defaults
--------
See pymor.core.defaults.print_defaults.
'''[1:].format(self.version, self.PYTHON_VESRION, '-' * max(map(len, package_info)),
'''[1:].format(self.version, self.PYTHON_VERSION, '-' * max(map(len, package_info)),
'\n'.join(package_info))
return info

Expand Down
3 changes: 2 additions & 1 deletion src/pymor/version.py
Expand Up @@ -474,7 +474,7 @@ def render(pieces, style):
"date": pieces.get("date")}


def get_versions(version_default='0.0.0-0-0'):
def get_versions():
"""Get version information or return default if unable to do so."""
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
# __file__, we can work backwards from there to the root. Some
Expand All @@ -483,6 +483,7 @@ def get_versions(version_default='0.0.0-0-0'):

cfg = get_config()
verbose = cfg.verbose
version_default = '0.unknown'

try:
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
Expand Down
4 changes: 2 additions & 2 deletions src/pymortests/core/interface.py
Expand Up @@ -55,8 +55,8 @@ def abstract_static_method():
assert inst.abstract_static_method() == 0

def testVersion(self):
assert pymor.VERSION > pymor.NO_VERSION
assert isinstance(pymor.VERSION, pymor.Version)
assert 'unknown' not in pymor.__version__
assert '?' not in pymor.__version__


@SubclassForImplemetorsOf(ImmutableInterface)
Expand Down

0 comments on commit 90a1e95

Please sign in to comment.