From 090c6f9ff6abfe3682df42255e9a3028c6ee2bb1 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Wed, 27 Jun 2018 15:05:09 +0200 Subject: [PATCH] Add util function get_strict_version (#1686) The utility function `aiida.get_strict_version` will return a StrictVersion instance from `distutils.version` with the current version of the package. --- aiida/__init__.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/aiida/__init__.py b/aiida/__init__.py index 5fced53c56..fc5f9f67dc 100644 --- a/aiida/__init__.py +++ b/aiida/__init__.py @@ -8,13 +8,13 @@ # 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 __copyright__ = u"Copyright (c), This file is part of the AiiDA platform. For further information please visit http://www.aiida.net/. All rights reserved." __license__ = "MIT license, see LICENSE.txt file." __version__ = "1.0.0a1" -__version__ = "0.12.1" __authors__ = "The AiiDA team." __paper__ = """G. Pizzi, A. Cepellotti, R. Sabatini, N. Marzari, and B. Kozinsky, "AiiDA: automated interactive infrastructure and database for computational science", Comp. Mat. Sci 111, 218-230 (2016); http://dx.doi.org/10.1016/j.commatsci.2015.09.013 - http://www.aiida.net.""" __paper_short__ = """G. Pizzi et al., Comp. Mat. Sci 111, 218 (2016).""" @@ -27,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. @@ -36,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` @@ -52,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__ @@ -71,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; @@ -80,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)