Automatically generate the enum keys for Python. Maybe helps with pydev issue; See #367

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2014-12-24 12:09:25 -05:00
parent c2047e4162
commit c50a4f6494
4 changed files with 26 additions and 235 deletions

View File

@@ -1,109 +0,0 @@
# This file is automatically generated by the generate_constants_module.py script in dev/scripts.
# DO NOT MODIFY THE CONTENTS OF THIS FILE!
cimport constants_header
imolar_mass = constants_header.imolar_mass
irhomolar_reducing = constants_header.irhomolar_reducing
irhomolar_critical = constants_header.irhomolar_critical
iT_reducing = constants_header.iT_reducing
iT_critical = constants_header.iT_critical
irhomass_reducing = constants_header.irhomass_reducing
irhomass_critical = constants_header.irhomass_critical
iP_critical = constants_header.iP_critical
iT_triple = constants_header.iT_triple
iP_triple = constants_header.iP_triple
iT_min = constants_header.iT_min
iT_max = constants_header.iT_max
iP_max = constants_header.iP_max
iP_min = constants_header.iP_min
iT = constants_header.iT
iP = constants_header.iP
iQ = constants_header.iQ
iTau = constants_header.iTau
iDelta = constants_header.iDelta
iDmolar = constants_header.iDmolar
iHmolar = constants_header.iHmolar
iSmolar = constants_header.iSmolar
iCpmolar = constants_header.iCpmolar
iCp0molar = constants_header.iCp0molar
iCvmolar = constants_header.iCvmolar
iUmolar = constants_header.iUmolar
iGmolar = constants_header.iGmolar
iDmass = constants_header.iDmass
iHmass = constants_header.iHmass
iSmass = constants_header.iSmass
iCpmass = constants_header.iCpmass
iCp0mass = constants_header.iCp0mass
iCvmass = constants_header.iCvmass
iUmass = constants_header.iUmass
iGmass = constants_header.iGmass
iviscosity = constants_header.iviscosity
iconductivity = constants_header.iconductivity
isurface_tension = constants_header.isurface_tension
iPrandtl = constants_header.iPrandtl
ispeed_sound = constants_header.ispeed_sound
iisothermal_compressibility = constants_header.iisothermal_compressibility
iisobaric_expansion_coefficient = constants_header.iisobaric_expansion_coefficient
ifundamental_derivative_of_gas_dynamics = constants_header.ifundamental_derivative_of_gas_dynamics
ialphar = constants_header.ialphar
idalphar_dtau_constdelta = constants_header.idalphar_dtau_constdelta
idalphar_ddelta_consttau = constants_header.idalphar_ddelta_consttau
ialpha0 = constants_header.ialpha0
idalpha0_dtau_constdelta = constants_header.idalpha0_dtau_constdelta
idalpha0_ddelta_consttau = constants_header.idalpha0_ddelta_consttau
iBvirial = constants_header.iBvirial
iCvirial = constants_header.iCvirial
idBvirial_dT = constants_header.idBvirial_dT
idCvirial_dT = constants_header.idCvirial_dT
iZ = constants_header.iZ
iGWP20 = constants_header.iGWP20
iGWP100 = constants_header.iGWP100
iGWP500 = constants_header.iGWP500
iFH = constants_header.iFH
iHH = constants_header.iHH
iPH = constants_header.iPH
iODP = constants_header.iODP
iundefined_parameter = constants_header.iundefined_parameter
QT_INPUTS = constants_header.QT_INPUTS
PQ_INPUTS = constants_header.PQ_INPUTS
PT_INPUTS = constants_header.PT_INPUTS
DmassT_INPUTS = constants_header.DmassT_INPUTS
DmolarT_INPUTS = constants_header.DmolarT_INPUTS
HmolarT_INPUTS = constants_header.HmolarT_INPUTS
HmassT_INPUTS = constants_header.HmassT_INPUTS
SmolarT_INPUTS = constants_header.SmolarT_INPUTS
SmassT_INPUTS = constants_header.SmassT_INPUTS
TUmolar_INPUTS = constants_header.TUmolar_INPUTS
TUmass_INPUTS = constants_header.TUmass_INPUTS
DmassP_INPUTS = constants_header.DmassP_INPUTS
DmolarP_INPUTS = constants_header.DmolarP_INPUTS
HmassP_INPUTS = constants_header.HmassP_INPUTS
HmolarP_INPUTS = constants_header.HmolarP_INPUTS
PSmass_INPUTS = constants_header.PSmass_INPUTS
PSmolar_INPUTS = constants_header.PSmolar_INPUTS
PUmass_INPUTS = constants_header.PUmass_INPUTS
PUmolar_INPUTS = constants_header.PUmolar_INPUTS
HmassSmass_INPUTS = constants_header.HmassSmass_INPUTS
HmolarSmolar_INPUTS = constants_header.HmolarSmolar_INPUTS
SmassUmass_INPUTS = constants_header.SmassUmass_INPUTS
SmolarUmolar_INPUTS = constants_header.SmolarUmolar_INPUTS
DmassHmass_INPUTS = constants_header.DmassHmass_INPUTS
DmolarHmolar_INPUTS = constants_header.DmolarHmolar_INPUTS
DmassSmass_INPUTS = constants_header.DmassSmass_INPUTS
DmolarSmolar_INPUTS = constants_header.DmolarSmolar_INPUTS
DmassUmass_INPUTS = constants_header.DmassUmass_INPUTS
DmolarUmolar_INPUTS = constants_header.DmolarUmolar_INPUTS
FLUID_TYPE_PURE = constants_header.FLUID_TYPE_PURE
FLUID_TYPE_PSEUDOPURE = constants_header.FLUID_TYPE_PSEUDOPURE
FLUID_TYPE_REFPROP = constants_header.FLUID_TYPE_REFPROP
FLUID_TYPE_INCOMPRESSIBLE_LIQUID = constants_header.FLUID_TYPE_INCOMPRESSIBLE_LIQUID
FLUID_TYPE_INCOMPRESSIBLE_SOLUTION = constants_header.FLUID_TYPE_INCOMPRESSIBLE_SOLUTION
FLUID_TYPE_UNDEFINED = constants_header.FLUID_TYPE_UNDEFINED
iphase_liquid = constants_header.iphase_liquid
iphase_supercritical = constants_header.iphase_supercritical
iphase_supercritical_gas = constants_header.iphase_supercritical_gas
iphase_supercritical_liquid = constants_header.iphase_supercritical_liquid
iphase_gas = constants_header.iphase_gas
iphase_twophase = constants_header.iphase_twophase
iphase_unknown = constants_header.iphase_unknown
iphase_not_imposed = constants_header.iphase_not_imposed

View File

@@ -1,113 +0,0 @@
# This file is automatically generated by the generate_constants_module.py script in dev/scripts.
# DO NOT MODIFY THE CONTENTS OF THIS FILE!
cdef extern from "DataStructures.h" namespace "CoolProp":
ctypedef enum parameters:
imolar_mass
irhomolar_reducing
irhomolar_critical
iT_reducing
iT_critical
irhomass_reducing
irhomass_critical
iP_critical
iT_triple
iP_triple
iT_min
iT_max
iP_max
iP_min
iT
iP
iQ
iTau
iDelta
iDmolar
iHmolar
iSmolar
iCpmolar
iCp0molar
iCvmolar
iUmolar
iGmolar
iDmass
iHmass
iSmass
iCpmass
iCp0mass
iCvmass
iUmass
iGmass
iviscosity
iconductivity
isurface_tension
iPrandtl
ispeed_sound
iisothermal_compressibility
iisobaric_expansion_coefficient
ifundamental_derivative_of_gas_dynamics
ialphar
idalphar_dtau_constdelta
idalphar_ddelta_consttau
ialpha0
idalpha0_dtau_constdelta
idalpha0_ddelta_consttau
iBvirial
iCvirial
idBvirial_dT
idCvirial_dT
iZ
iGWP20
iGWP100
iGWP500
iFH
iHH
iPH
iODP
iundefined_parameter
ctypedef enum input_pairs:
QT_INPUTS
PQ_INPUTS
PT_INPUTS
DmassT_INPUTS
DmolarT_INPUTS
HmolarT_INPUTS
HmassT_INPUTS
SmolarT_INPUTS
SmassT_INPUTS
TUmolar_INPUTS
TUmass_INPUTS
DmassP_INPUTS
DmolarP_INPUTS
HmassP_INPUTS
HmolarP_INPUTS
PSmass_INPUTS
PSmolar_INPUTS
PUmass_INPUTS
PUmolar_INPUTS
HmassSmass_INPUTS
HmolarSmolar_INPUTS
SmassUmass_INPUTS
SmolarUmolar_INPUTS
DmassHmass_INPUTS
DmolarHmolar_INPUTS
DmassSmass_INPUTS
DmolarSmolar_INPUTS
DmassUmass_INPUTS
DmolarUmolar_INPUTS
ctypedef enum fluid_types:
FLUID_TYPE_PURE
FLUID_TYPE_PSEUDOPURE
FLUID_TYPE_REFPROP
FLUID_TYPE_INCOMPRESSIBLE_LIQUID
FLUID_TYPE_INCOMPRESSIBLE_SOLUTION
FLUID_TYPE_UNDEFINED
ctypedef enum phases:
iphase_liquid
iphase_supercritical
iphase_supercritical_gas
iphase_supercritical_liquid
iphase_gas
iphase_twophase
iphase_unknown
iphase_not_imposed

View File

@@ -1,7 +1,8 @@
from __future__ import print_function
import os,shutil
"""
A little script to wrap the params enum for use in Cython code
A little module to wrap the params enum for use in Cython code
Ian Bell, May 2014
"""
@@ -33,10 +34,12 @@ def params_constants(enum_key):
return keys
def generate_cython(data):
print('****** Writing the constants module ******')
#Write the PXD definition file
pxd_output_file = open('constants_header.pxd','w')
pxd_output_file.write('# This file is automatically generated by the generate_constants_module.py script in dev/scripts.\n# DO NOT MODIFY THE CONTENTS OF THIS FILE!\n\ncdef extern from "DataStructures.h" namespace "CoolProp":\n')
# Write the PXD definition file
pxd_output_file = open('CoolProp/constants_header.pxd','w')
pxd_output_file.write('# This file is automatically generated by the generate_constants_module.py script in wrappers/Python.\n# DO NOT MODIFY THE CONTENTS OF THIS FILE!\n\ncdef extern from "DataStructures.h" namespace "CoolProp":\n')
for enum_key, entries in data:
pxd_output_file.write('\tctypedef enum '+enum_key+':\n')
@@ -45,18 +48,24 @@ def generate_cython(data):
pxd_output_file.write('\t\t'+param+'\n')
pxd_output_file.close()
#Write the PYX implementation file
pyx_output_file = open('constants.pyx','w')
pyx_output_file.write('# This file is automatically generated by the generate_constants_module.py script in dev/scripts.\n# DO NOT MODIFY THE CONTENTS OF THIS FILE!\ncimport constants_header\n\n')
# Write the PYX implementation file
pyx_output_file = open('CoolProp/_constants.pyx','w')
pyx_output_file.write('# This file is automatically generated by the generate_constants_module.py script in wrappers/Python.\n# DO NOT MODIFY THE CONTENTS OF THIS FILE!\ncimport constants_header\n\n')
for enum_key, entries in data:
for param in entries:
param = param.strip()
pyx_output_file.write(param+' = '+'constants_header.'+param+'\n')
pyx_output_file.close()
shutil.copy2('constants_header.pxd',os.path.join('..','..','wrappers','Python','CoolProp','constants_header.pxd'))
shutil.copy2('constants.pyx',os.path.join('..','..','wrappers','Python','CoolProp','constants.pyx'))
if __name__=='__main__':
# Write the PY implementation file
py_output_file = open('CoolProp/constants.py','w')
py_output_file.write('# This file is automatically generated by the generate_constants_module.py script in wrappers/Python.\n# DO NOT MODIFY THE CONTENTS OF THIS FILE!\nimport _constants\n\n')
for enum_key, entries in data:
for param in entries:
param = param.strip()
py_output_file.write(param+' = '+'_constants.'+param+'\n')
py_output_file.close()
def generate():
data = [(enum,params_constants(enum)) for enum in ['parameters', 'input_pairs', 'fluid_types', 'phases']]
generate_cython(data)

View File

@@ -177,6 +177,10 @@ if __name__=='__main__':
# Generate the headers - does nothing if up to date - but only if not pypi
generate_headers.generate()
del generate_headers
import generate_constants_module
generate_constants_module.generate()
del generate_constants_module
# Read the version from a bare string stored in file in root directory
version = open(os.path.join(CProot,'.version'),'r').read().strip()
@@ -236,8 +240,8 @@ if __name__=='__main__':
CoolProp_module = Extension('CoolProp.CoolProp',
[os.path.join('CoolProp','CoolProp.' + cy_ext)] + sources,
**common_args)
constants_module = Extension('CoolProp.constants',
[os.path.join('CoolProp','constants.' + cy_ext)],
constants_module = Extension('CoolProp._constants',
[os.path.join('CoolProp','_constants.' + cy_ext)],
**common_args)
if not pypi: