Source code for spinetoolbox.spinedb_api_version_check

######################################################################################################################
# Copyright (C) 2017-2021 Spine project consortium
# This file is part of Spine Toolbox.
# Spine Toolbox is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
# Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
# any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
# Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################

"""
Contains the spinedb_api_version_check function.

This module should import as few things as possible to avoid accidentally importing anything from spinedb_api
that is not available in the current spinedb_api version.

:authors: A. Soininen (VTT)
:date:   30.3.2020
"""

import sys
import spinedb_api
from .config import REQUIRED_SPINEDB_API_VERSION


[docs]def spinedb_api_version_check(): """Check if spinedb_api is the correct version and explain how to upgrade if it is not.""" try: current_version = spinedb_api.__version__ current_split = [int(x) for x in current_version.split(".")] required_split = [int(x) for x in REQUIRED_SPINEDB_API_VERSION.split(".")] if current_split >= required_split: return True except AttributeError: current_version = "not reported" script = "upgrade_spinedb_api.bat" if sys.platform == "win32" else "upgrade_spinedb_api.py" print( """SPINEDB_API OUTDATED. Spine Toolbox failed to start because spinedb_api is outdated. (Required version is {0}, whereas current is {1}) Please upgrade spinedb_api to v{0} and start Spine Toolbox again. To upgrade, run script '{2}' in the '/bin' folder. Or upgrade it manually by running, pip install --upgrade git+https://github.com/Spine-project/Spine-Database-API.git """.format( REQUIRED_SPINEDB_API_VERSION, current_version, script ) ) return False