python builders work!!

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2014-08-03 14:00:46 +02:00
parent df17eaf6cc
commit a14731783e
7 changed files with 50 additions and 37 deletions

View File

@@ -24,7 +24,7 @@ cpdef ndarray_or_iterable(object input):
else:
return input
#include "HumidAirProp.pyx"
include "HumidAirProp.pyx"
# def set_reference_state(string_like FluidName, *args):
# """
@@ -173,7 +173,6 @@ cpdef get_aliases(str Fluid):
cdef bytes _Fluid = Fluid.encode('ascii')
return [F.encode('ascii') for F in (_get_fluid_param_string(_Fluid,'aliases').encode('ascii')).decode('ascii').split(',')]
#
cpdef string get_REFPROPname(str Fluid):
"""
Return the REFPROP compatible name for the fluid
@@ -214,7 +213,7 @@ cpdef string get_REFPROPname(str Fluid):
# key, string
# empty string if Fluid not in CoolProp, "Bad key" if key is invalid
# """
# return _get_BibTeXKey(Fluid.encode('ascii'), key.encode('ascii'))
# return _get_BibTeXKey(Fluid, key)
# cpdef string get_errstr():
# """
# Return the current error string
@@ -245,7 +244,7 @@ cpdef int get_debug_level():
the more verbose the output will be
"""
return _get_debug_level()
#
# cpdef bint IsFluidType(string Fluid, string Type):
# """
# Check if a fluid is of a given type

View File

@@ -35,7 +35,7 @@ cpdef HAProps(str OutputName, str Input1Name, Input1, str Input2Name, Input2, st
There are also strings for the mixture volume and mixture enthalpy that will return the properties on a total humid air flow rate basis, they are given by 'Vha' [units of m^3/kg humid air] and 'Cha' [units of kJ/kg humid air/K] and 'Hha' [units of kJ/kg humid air] respectively.
For more information, go to http://coolprop.sourceforge.net
For more information, go to http://www.coolprop.org
"""
#Convert all strings to byte-strings
cdef bytes _OutputName = OutputName.encode('ascii')

View File

@@ -1,4 +1,3 @@
from __future__ import absolute_import
# We made everything build into one module for simplicity as it makes the code much nicer to compile
from .CoolProp import State, get_debug_level, set_debug_level, Props
from .CoolProp import *

View File

@@ -2,8 +2,8 @@ from __future__ import absolute_import
from . import AbstractState
from . import CoolProp
# from . import HumidAirProp
# from . import State
from . import HumidAirProp
from . import State
from .constants import *
__fluids__ = CoolProp.get_global_param_string(b'FluidList')

View File

@@ -1,4 +1,4 @@
recursive-include src *.*
recursive-include include *.*
recursive-include externals *.*
recursive-include externals *
include *.*

View File

@@ -16,6 +16,8 @@ def collect(tmp):
shutil.copy2(os.path.join('..','setup.py'),os.path.join(tmp,'setup.py'))
print('touching .build_without_cython')
fp = open(os.path.join(tmp,'.build_without_cython'), 'w'); fp.close()
print('touching .use_this_directory_as_root')
fp = open(os.path.join(tmp,'.use_this_directory_as_root'), 'w'); fp.close()
if __name__=='__main__':
@@ -32,7 +34,8 @@ if __name__=='__main__':
collect(tmp)
# Try to make the source distro
subprocess.check_call(['python','setup.py','sdist','--pypi'], shell = True, cwd = tmp, stdout = sys.stdout, stderr = sys.stderr)
subprocess.check_call(['python','setup.py','sdist'], shell = True, cwd = tmp, stdout = sys.stdout, stderr = sys.stderr)
except BaseException as B:
#shutil.rmtree(tmp)

View File

@@ -15,11 +15,7 @@ if __name__=='__main__':
import subprocess, shutil, os, sys, glob
# Check if a sdist build for pypi
if '--pypi' in sys.argv:
sys.argv.remove('--pypi')
pypi = True
else:
pypi = False
pypi = os.path.exists('.use_this_directory_as_root')
"""
Modes of operation:
@@ -27,7 +23,7 @@ if __name__=='__main__':
2) Installing from source (generate_headers.py must have been run before making the repo)
3) Installing from git repo (need to make sure to run generate_headers.py)
4)
"""
"""
# Determine whether or not to use Cython - default is to use cython unless the file .build_without_cython is found in the current working directory
USE_CYTHON = not os.path.exists('.build_without_cython')
@@ -49,6 +45,14 @@ if __name__=='__main__':
_profiling_enabled = True
else:
_profiling_enabled = False
if _profiling_enabled:
cython_directives = dict(profile = True,
embed_signature = True)
else:
cython_directives = dict(embed_signature = True)
else:
cython_directives = {}
# Determine the path to the root of the repository, the folder that contains the CMakeLists.txt file
# for normal builds, or the main directory for sdist builds
@@ -67,10 +71,12 @@ if __name__=='__main__':
stdout = sys.stdout,
cwd = os.path.join(CProot, 'dev')
)
# Read the version from a bare string stored in file in root directory
version = open(os.path.join(CProot,'.version'),'r').read().strip()
setup_kwargs = {}
from setuptools import setup, Extension, find_packages
if USE_CYTHON:
import Cython.Compiler
@@ -78,11 +84,13 @@ if __name__=='__main__':
from Cython.Build import cythonize
from Cython.Distutils import build_ext
# This will generate HTML to show where there are still pythonic bits hiding out
# This will always generate HTML to show where there are still pythonic bits hiding out
Cython.Compiler.Options.annotate = True
setup_kwargs['cmdclass'] = dict(build_ext = build_ext)
print('Cython will be used; cy_ext is ' + cy_ext)
else:
cythonize = lambda args: args # A dummy cythonize function that just returns the extensions again
print('Cython will not be used; cy_ext is ' + cy_ext)
def find_cpp_sources(root = os.path.join('..','..','src'), extensions = ['.cpp'], skip_files = None):
@@ -99,25 +107,19 @@ if __name__=='__main__':
# Set variables for C++ sources and include directories
sources = find_cpp_sources(os.path.join(CProot,'src'), '*.cpp')
include_dirs = [os.path.join(CProot, 'include'), os.path.join(CProot, 'externals', 'Eigen')]
#This will generate HTML to show where there are still pythonic bits hiding out
Cython.Compiler.Options.annotate = True
## If the file is run directly without any parameters, clean, build and install
if len(sys.argv)==1:
sys.argv += ['clean','build']
if _profiling_enabled:
cython_directives = dict(profile = True,
embed_signature = True)
else:
cython_directives = dict(embed_signature = True)
sys.argv += ['clean', 'build', 'install']
common_args = dict(include_dirs = include_dirs,
language='c++',
cython_c_in_temp = True,
cython_directives = cython_directives
)
language='c++')
if USE_CYTHON:
common_args.update(dict(cython_c_in_temp = True,
cython_directives = cython_directives
)
)
AbstractState_module = Extension('CoolProp5.AbstractState',
[os.path.join('CoolProp5','AbstractState.' + cy_ext)] + sources,
@@ -125,10 +127,18 @@ if __name__=='__main__':
CoolProp_module = Extension('CoolProp5.CoolProp',
[os.path.join('CoolProp5','CoolProp.' + cy_ext)] + sources,
**common_args)
constants_module = Extension('CoolProp5.constants',
[os.path.join('CoolProp5','constants.' + cy_ext)],
**common_args)
if not pypi:
copy_files()
ext_modules = [CoolProp_module, AbstractState_module, constants_module]
if USE_CYTHON:
ext_modules = cythonize(ext_modules)
try:
setup (name = 'CoolProp5',
version = version, # look above for the definition of version variable - don't modify it here
@@ -137,12 +147,10 @@ if __name__=='__main__':
url='http://www.coolprop.org',
description = """Open-source thermodynamic and transport properties database""",
packages = find_packages(),
ext_modules = cythonize([CoolProp_module, AbstractState_module]),
ext_modules = ext_modules,
package_data = {'CoolProp5':['State.pxd',
'CoolProp.pxd',
'CoolPropBibTeXLibrary.bib'] + find_cpp_sources(os.path.join('include'), '*.h')},
cmdclass={'build_ext': build_ext},
classifiers = [
"Programming Language :: Python",
"Development Status :: 4 - Beta",
@@ -152,6 +160,7 @@ if __name__=='__main__':
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules"
],
**setup_kwargs
)
except BaseException as E:
if not pypi:
@@ -159,4 +168,7 @@ if __name__=='__main__':
raise
else:
if not pypi:
remove_files()
remove_files()
sys.path.pop(0)
import CoolProp5