Fixed python files for py3.x I think, though I hate python 3 string handling

This commit is contained in:
Ian Bell
2014-08-07 23:27:37 +02:00
parent 65df77f81e
commit 584b975b4b
3 changed files with 25 additions and 30 deletions

View File

@@ -475,19 +475,13 @@ endif()
if (COOLPROP_PYTHON_BINARIES)
if (WIN32)
set(COOLPROP_PYTHON_BINARY_VERSIONS bdist_wheel bdist_wininst)
set(COOLPROP_PYTHON_BINARY_VERSIONS bdist_wheel --dist-dir ${CMAKE_INSTALL_PREFIX}/Python bdist_wininst --dist-dir ${CMAKE_INSTALL_PREFIX}/Python)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(COOLPROP_PYTHON_BINARY_VERSIONS bdist_wheel)
endif()
if (DEFINED AND_UPLOAD)
set(_AND_UPLOAD upload)
else()
set(_AND_UPLOAD )
set(COOLPROP_PYTHON_BINARY_VERSIONS bdist_wheel --dist-dir ${CMAKE_INSTALL_PREFIX}/Python)
endif()
add_custom_target(CoolProp
COMMAND ${PYTHON_EXECUTABLE} setup.py ${COOLPROP_PYTHON_BINARY_VERSIONS} ${_AND_UPLOAD} --dist-dir=${CMAKE_INSTALL_PREFIX}/Python
COMMAND ${PYTHON_EXECUTABLE} setup.py ${COOLPROP_PYTHON_BINARY_VERSIONS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/wrappers/Python
)

View File

@@ -18,7 +18,8 @@ json_options = {'indent' : 2, 'sort_keys' : True}
def get_hash(data):
return hashlib.sha224(data).hexdigest()
repo_root_path = os.path.normpath(os.path.join(os.path.abspath(__file__),'..','..'))
# unicode
repo_root_path = os.path.normpath(os.path.join(os.path.abspath(__file__), '..', '..'))
# Load up the hashes of the data that will be written to each file
hashes_fname = os.path.join(repo_root_path,'dev','hashes.json')
@@ -68,6 +69,8 @@ def TO_CPP(root_dir, hashes):
# Put the lines back together again
# The chunks are joined together with commas, and then EOL are used to join the rest
hex_string = ',\n'.join([', '.join(chunk) for chunk in chunks])
print(type(hex_string))
# Check if hash is up to date based on using variable as key
if variable not in hashes or (variable in hashes and hashes[variable] != get_hash(hex_string.encode('ascii'))):
@@ -120,34 +123,32 @@ def version_to_file(root_dir):
hashes['version'] = get_hash(version)
# Format the string to be written
string_for_file = '//Generated by the generate_headers.py script on {t:s}\n\nstatic char version [] ="{v:s}";'.format(t = str(datetime.now()),v = version)
string_for_file = b'//Generated by the generate_headers.py script on {t:s}\n\nstatic char version [] ="{v:s}";'.format(t = str(datetime.now()),v = version)
# Include path relative to the root
include_dir = os.path.join(root_dir,'include')
include_dir = os.path.join(root_dir, b'include')
# The name of the file to be written into
file_name = os.path.join(include_dir,'cpversion.h')
file_name = os.path.join(include_dir, b'cpversion.h')
# Write to file
f = open(file_name,'w')
f.write(string_for_file)
f.close()
print('version written to file: ' + file_name)
print(b'version written to file: ' + file_name)
else:
print('cpversion.h is up to date')
hidden_file_name = os.path.join(root_dir,'.version').encode('ascii')
hidden_file_name = os.path.join(root_dir, '.version')
# Write to file
f = open(hidden_file_name,'w')
f.write(version)
f.close()
print(b'version written to hidden file: ' + hidden_file_name + b" for use in builders that don't use git repo")
print('version written to hidden file: ' + hidden_file_name + " for use in builders that don't use git repo")
def gitrev_to_file(root_dir):
"""
@@ -178,9 +179,9 @@ def gitrev_to_file(root_dir):
gitrev = open(gitrevision_path, 'r').read().strip()
else:
print('tried to get git revision from '+gitrevision_path+', but could not')
gitrev = '???'
gitrev = b'???'
else:
gitrev = stdout.strip()
gitrev = stdout.strip() # bytes
try:
is_hash = gitrev.find(' ') == -1 # python 2.x
@@ -190,10 +191,9 @@ def gitrev_to_file(root_dir):
if not is_hash:
raise ValueError('No hash returned from call to git, got '+rev+' instead')
gitrev = gitrev.encode('ascii')
print('git revision is', gitrev)
print('git revision is', str(gitrev))
if 'gitrevision' not in hashes or ('gitrevision' in hashes and hashes['gitrevision'] != get_hash(gitrev.encode('ascii'))):
if 'gitrevision' not in hashes or ('gitrevision' in hashes and hashes['gitrevision'] != get_hash(gitrev)):
print('*** Generating gitrevision.h ***')
gitstring = '//Generated by the generate_headers.py script on {t:s}\n\nstd::string gitrevision = \"{rev:s}\";'.format(t = str(datetime.now()), rev = gitrev)
@@ -257,7 +257,7 @@ def combine_json(root_dir):
fp.write(json.dumps(master))
fp.close()
if __name__=='__main__':
def generate():
import shutil
shutil.copy2(os.path.join(repo_root_path, 'externals','Catch','single_include','catch.hpp'),os.path.join(repo_root_path,'include','catch.hpp'))
@@ -272,4 +272,7 @@ if __name__=='__main__':
fp = open(hashes_fname,'w')
fp.write(json.dumps(hashes))
fp.close()
if __name__=='__main__':
generate()

View File

@@ -65,13 +65,11 @@ if __name__=='__main__':
else:
raise ValueError('Could not run script from this folder(' + os.path.abspath(os.path.curdir) + '). Run from wrappers/Python folder')
sys.path.append(os.path.join(CProot, 'dev'))
import generate_headers
# Generate the headers - does nothing if up to date - but only if not pypi
subprocess.check_call('python generate_headers.py',
shell = True,
stdout = sys.stdout,
cwd = os.path.join(CProot, 'dev')
)
generate_headers.generate()
del generate_headers
# Read the version from a bare string stored in file in root directory
version = open(os.path.join(CProot,'.version'),'r').read().strip()