Skip to content

Commit

Permalink
Add util function get_strict_version (#1686) (#2099)
Browse files Browse the repository at this point in the history
The utility function `aiida.get_strict_version` will return a StrictVersion
instance from `distutils.version` with the current version of the package.
  • Loading branch information
ltalirz authored and giovannipizzi committed Oct 23, 2018
1 parent 1f4b86e commit 28ecda9
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions aiida/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# For further information please visit http://www.aiida.net #
###########################################################################
import warnings

from aiida.common.log import configure_logging
from aiida.common.setup import get_property

Expand All @@ -26,6 +27,7 @@
# in Python 2.7 it is suppressed by default
warnings.simplefilter('default', DeprecationWarning)


def try_load_dbenv(*argc, **argv):
"""
Run `load_dbenv` unless the dbenv has already been loaded.
Expand All @@ -35,6 +37,7 @@ def try_load_dbenv(*argc, **argv):
return True
return False


def load_dbenv(*argc, **argv):
"""
Alias for `load_dbenv` from `aiida.backends.utils`
Expand All @@ -51,9 +54,21 @@ def is_dbenv_loaded(*argc, **argv):
return is_dbenv_loaded(*argc, **argv)


def get_strict_version():
"""
Return a distutils StrictVersion instance with the current distribution version
:returns: StrictVersion instance with the current version
"""
from distutils.version import StrictVersion
return StrictVersion(__version__)


def get_version():
"""
Very simple function to get a string with the version number.
Return the current distribution version
:returns: a string with the current version
"""
return __version__

Expand All @@ -70,6 +85,7 @@ def _get_raw_file_header():
{}
""".format(__version__, __paper__)


def get_file_header(comment_char="# "):
"""
Get a string to be put as header of files created with AiiDA;
Expand All @@ -79,4 +95,4 @@ def get_file_header(comment_char="# "):
:return: a (multiline) string
"""
lines = _get_raw_file_header().splitlines()
return "\n".join("{}{}".format(comment_char, line) for line in lines)
return '\n'.join('{}{}'.format(comment_char, line) for line in lines)

0 comments on commit 28ecda9

Please sign in to comment.