Version getting now doesn't require importing spintrum

This commit is contained in:
Samer Afach 2017-01-13 10:57:12 +01:00
parent 67d0c5a2aa
commit e81b27ef4e
3 changed files with 38 additions and 7 deletions

View File

@ -48,13 +48,21 @@ endif()
set(CMAKE_BUILD_TYPE Release)
#add_definitions(-DPOLYMATH_DEBUG)
set(VERSION 0.1.6)
execute_process(COMMAND "python3 -c 'from spintrum import meta; print(meta.__version__)'" OUTPUT_VARIABLE VERSION)
set(VERSION_GETTER python3 ${CMAKE_SOURCE_DIR}/get_version.py)
execute_process(COMMAND ${VERSION_GETTER}
OUTPUT_VARIABLE VERSION_GET_OUTPUT
ERROR_VARIABLE VERSION_GET_ERROR
RESULT_VARIABLE VERSION_GET_RESULT
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
file (STRINGS "${CMAKE_BINARY_DIR}/TEMP_VERSION.txt" VERSION)
if(NOT "${VERSION_GET_RESULT}" STREQUAL "0")
message(FATAL_ERROR "${BoldRed}Error: Unable to get version number by executing ${VERSION_GETTER}${ColourReset}")
endif()
add_definitions(-DSPINTRUM_VERSION="${VERSION}")
message("${BoldBlue}Building Spintrum, version: ${VERSION}${ColourReset}")
INCLUDE_DIRECTORIES(${PolymathPath}/include)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
#INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${SpintrumPath})
INCLUDE_DIRECTORIES(${OpenBLASPath})

15
get_version.py Normal file
View File

@ -0,0 +1,15 @@
import re
import os
def get_version():
VERSIONFILE = os.path.join(os.path.dirname(os.path.abspath(__file__)),"spintrum/meta.py")
verstrline = open(VERSIONFILE, "rt").read()
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
mo = re.search(VSRE, verstrline, re.M)
if mo:
return str(mo.group(1))
else:
raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
with open("TEMP_VERSION.txt","w") as f:
f.write(get_version())

View File

@ -1,6 +1,4 @@
from setuptools import setup, find_packages
from distutils.command.build import build as _build
from spintrum import meta
import os
import sys
import shutil
@ -8,6 +6,7 @@ import errno
import tempfile
import subprocess
import glob
import re
import fnmatch
try:
@ -27,6 +26,15 @@ def _print_error(msg):
sys.stderr.write("\n\n" + error_color_start + "ERROR: " + msg + color_end + " \n\n\n ")
sys.stderr.flush()
def get_version():
VERSIONFILE = os.path.join(os.path.dirname(os.path.abspath(__file__)),"spintrum/meta.py")
verstrline = open(VERSIONFILE, "rt").read()
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
mo = re.search(VSRE, verstrline, re.M)
if mo:
return str(mo.group(1))
else:
raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
def which(program):
"""
@ -245,7 +253,7 @@ class DependenciesBuilder(_build):
setup(name='spintrum',
version=meta.__version__,
version=get_version(),
description='Software for spin systems simulation',
url='http://www.afach.de/',
author='Samer Afach',