Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3961 - Fix build error with Python bindings due to zlib's crypt.h #3963

Merged
merged 11 commits into from May 7, 2020
9 changes: 4 additions & 5 deletions CMakeLists.txt
Expand Up @@ -801,11 +801,10 @@ if(BUILD_NODE_MODULES)
endif()

if(BUILD_PYTHON_BINDINGS)
# need python
# TODO: add support for 3.x
find_package(PythonInterp 2.7 REQUIRED)
find_package(PythonLibs 2.7 REQUIRED)
include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS})

find_package(Python COMPONENTS Interpreter Development REQUIRED)

include_directories(SYSTEM ${Python_INCLUDE_DIRS})
set(ALL_PYTHON_BINDINGS "") # global list of python bindings
set(ALL_PYTHON_BINDING_DEPENDS "") # global list of library dependencies of the generated wrapper cxx files
set(ALL_PYTHON_WRAPPER_FILES "") # global list of generated wrapper cxx files
Expand Down
2 changes: 1 addition & 1 deletion ConanInstall.cmake
Expand Up @@ -72,7 +72,7 @@ if(NOT CONAN_OPENSTUDIO_ALREADY_RUN)
#boost_geometry/${BOOST_VERSION}@bincrafters/stable
pugixml/1.10@bincrafters/stable
jsoncpp/1.9.2
zlib/1.2.11
zlib/1.2.11@nrel/testing # TODO: Temp, pending merging of https://github.com/conan-io/conan-center-index/pull/1526, to resolve #3961
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this has been approved and just wanting on the merge. conan-io/conan-center-index#1526. It'd be nice to have a ref to the official vs using the NREL so we can wait on this for another couple of days and check back.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't be merged until I get approved in their Early access program, where access is granted by batches every two or three weeks from what I gathered after asking them directly.

It also ties into #3940, at some point I'd just make this nrel/stable instead of nrel/testing and that's it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, well if that's the case we can make the change at later date.

fmt/6.0.0
sqlite3/3.30.1
cpprestsdk/2.10.14@bincrafters/stable
Expand Down
13 changes: 8 additions & 5 deletions ProjectMacros.cmake
Expand Up @@ -435,7 +435,7 @@ macro(MAKE_SWIG_TARGET NAME SIMPLENAME KEY_I_FILE I_FILES PARENT_TARGET PARENT_S
set(ALL_RUBY_BINDING_WRAPPERS_FULL_PATH "${ALL_RUBY_BINDING_WRAPPERS_FULL_PATH}" PARENT_SCOPE)

# Python bindings
if(PYTHON_LIBRARY AND BUILD_PYTHON_BINDINGS)
if(BUILD_PYTHON_BINDINGS)
set(swig_target "python_${NAME}")

# utilities goes into OpenStudio. directly, everything else is nested
Expand Down Expand Up @@ -464,15 +464,17 @@ macro(MAKE_SWIG_TARGET NAME SIMPLENAME KEY_I_FILE I_FILES PARENT_TARGET PARENT_S

# Add the -py3 flag if the version used is Python 3
set(SWIG_PYTHON_3_FLAG "")
if (PYTHON_VERSION_MAJOR)
if (PYTHON_VERSION_MAJOR EQUAL 3)
if (Python_VERSION_MAJOR)
if (Python_VERSION_MAJOR EQUAL 3)
set(SWIG_PYTHON_3_FLAG -py3)
message(STATUS "${MODULE} - Building SWIG Bindings for Python 3")
else()
message(STATUS "${MODULE} - Building SWIG Bindings for Python 2")
endif()
else()
message(STATUS "${MODULE} - Couldnt determine version of Python - Building SWIG Bindings for Python 2")
# Python2 has been EOL since January 1, 2020
set(SWIG_PYTHON_3_FLAG -py3)
message(STATUS "${MODULE} - Couldnt determine version of Python - Building SWIG Bindings for Python 3")
endif()

add_custom_command(
Expand Down Expand Up @@ -501,6 +503,7 @@ macro(MAKE_SWIG_TARGET NAME SIMPLENAME KEY_I_FILE I_FILES PARENT_TARGET PARENT_S
${SWIG_WRAPPER}
)

# TODO: for local testing, PYTHON_GENERATED_SRC should go into Products/python next to the .so files
install(FILES "${PYTHON_GENERATED_SRC}" DESTINATION Python COMPONENT "Python")
install(TARGETS ${swig_target} DESTINATION Python COMPONENT "Python")

Expand All @@ -520,7 +523,7 @@ macro(MAKE_SWIG_TARGET NAME SIMPLENAME KEY_I_FILE I_FILES PARENT_TARGET PARENT_S
endif()
endif()

target_link_libraries(${swig_target} ${PARENT_TARGET} ${PYTHON_LIBRARY})
target_link_libraries(${swig_target} ${PARENT_TARGET} ${PYTHON_Libraries})

add_dependencies(${swig_target} ${PARENT_TARGET})

Expand Down
2 changes: 1 addition & 1 deletion python/CMakeLists.txt
Expand Up @@ -21,7 +21,7 @@
#target_link_libraries(openstudio_python
# ${ALL_PYTHON_BINDING_DEPENDS}
# ${Boost_LIBRARIES}
# ${PYTHON_LIBRARY}
# ${Python_LIBRARIES}
#)

#install(TARGETS openstudio_python DESTINATION Python CONFIGURATIONS COMPONENT "Python")
Expand Down
6 changes: 5 additions & 1 deletion python/README.txt
@@ -1,7 +1,11 @@
Example for launching example

Note: the *.py files are generated in <build>/python_wrapper/generated_sources while the library files are in <build>/Products/python.
When installing, they will end up in the same directory. You can either go symlink the generated_sources/*.py to Products/python, or specify both
in PYTHONPATH

On Linux:
PYTHONPATH=~/openstudio/build/OSCore-prefix/src/OSCore-build/Products/python/ python testpath.py
PYTHONPATH=~/openstudio/build/Products/python/:~/openstudio/build/python_wrapper/generated_sources/ python testpath.py

On Windows:
set PYTHONPATH=\working\openstudio\build\OSCore-prefix\src\OSCore-build\Products\python\Release
Expand Down
101 changes: 68 additions & 33 deletions python/openstudio.py
@@ -1,38 +1,73 @@
# imports all of the openstudio libraries into a friendly namespace

import .openstudioairflow as airflow
import .openstudioanalysis as analysis
import .openstudioanalysisdriver as analysisdriver
import .openstudioenergyplus as energyplus
import .openstudiogbxml as gbxml
import .openstudioisomodel as isomodel
import .openstudiolib as lib
import .openstudiomeasure as measure
import .openstudiomodel as model
# import openstudiomodelcore as modelcore
# import openstudiomodelgenerators as modelgenerators
# import openstudiomodelgeometry as modelgeometry
# import openstudiomodelhvac as modelhvac
# import openstudiomodelrefrigeration as modelrefrigeration
# import openstudiomodelresources as modelresources
# import openstudiomodelsimulation as modelsimulation
import .openstudioosversion as osversion
import .openstudioradiance as radiance
import .openstudiosdd as sdd
# import .openstudiomodeleditor as modeleditor
if __package__ or "." in __name__:

from .openstudioutilities import *
from .openstudioutilitiesbcl import *
from .openstudioutilitiescore import *
from .openstudioutilitiesdata import *
from .openstudioutilitieseconomics import *
from .openstudioutilitiesgeometry import *
from .openstudioutilitiesidd import *
from .openstudioutilitiesidf import *
# from .openstudioutilitiesfiletypes import *
# from .openstudioutilitiesplot import *
from .openstudioutilitiessql import *
from .openstudioutilitiestime import *
from .openstudioutilitiesunits import *
from . import openstudioairflow as airflow
from . import openstudioenergyplus as energyplus
from . import openstudiogbxml as gbxml
from . import openstudioisomodel as isomodel
from . import openstudiomeasure as measure
from . import openstudiomodel as model
# from . import openstudiomodelcore as modelcore
# from . import openstudiomodelgenerators as modelgenerators
# from . import openstudiomodelgeometry as modelgeometry
# from . import openstudiomodelhvac as modelhvac
# from . import openstudiomodelrefrigeration as modelrefrigeration
# from . import openstudiomodelresources as modelresources
# from . import openstudiomodelsimulation as modelsimulation
# from . import openstudiomodelairflow as modelairflow
# from . import openstudiomodelavailabilitymanager as modelavailabilitymanager
# from . import openstudiomodelplantequipmentoperationscheme as modelplantequipmentoperationscheme
# from . import openstudiomodelstraightcomponent as modelstraightcomponent
# from . import openstudiomodelzonehvac as momodelzonehvac
from . import openstudioosversion as osversion
from . import openstudioradiance as radiance
from . import openstudiosdd as sdd
from .openstudioutilities import *
from .openstudioutilitiesbcl import *
from .openstudioutilitiescore import *
from .openstudioutilitiesdata import *
from .openstudioutilitiesgeometry import *
from .openstudioutilitiesidd import *
from .openstudioutilitiesidf import *
# from .openstudioutilitiesfiletypes import *
# from .openstudioutilitiesplot import *
from .openstudioutilitiessql import *
from .openstudioutilitiestime import *
from .openstudioutilitiesunits import *

else:

import openstudioairflow as airflow
import openstudioenergyplus as energyplus
import openstudiogbxml as gbxml
import openstudioisomodel as isomodel
import openstudiomeasure as measure
import openstudiomodel as model
# import openstudiomodelcore as modelcore
# import openstudiomodelgenerators as modelgenerators
# import openstudiomodelgeometry as modelgeometry
# import openstudiomodelhvac as modelhvac
# import openstudiomodelrefrigeration as modelrefrigeration
# import openstudiomodelresources as modelresources
# import openstudiomodelsimulation as modelsimulation
# import openstudiomodelairflow as modelairflow
# import openstudiomodelavailabilitymanager as modelavailabilitymanager
# import openstudiomodelplantequipmentoperationscheme as modelplantequipmentoperationscheme
# import openstudiomodelstraightcomponent as modelstraightcomponent
# import openstudiomodelzonehvac as momodelzonehvac
import openstudioosversion as osversion
import openstudioradiance as radiance
import openstudiosdd as sdd
from openstudioutilities import *
from openstudioutilitiesbcl import *
from openstudioutilitiescore import *
from openstudioutilitiesdata import *
from openstudioutilitiesgeometry import *
from openstudioutilitiesidd import *
from openstudioutilitiesidf import *
# from openstudioutilitiesfiletypes import *
# from openstudioutilitiesplot import *
from openstudioutilitiessql import *
from openstudioutilitiestime import *
from openstudioutilitiesunits import *
69 changes: 69 additions & 0 deletions python/openstudio_dynamic.py
@@ -0,0 +1,69 @@
# imports all of the openstudio libraries into a friendly namespace


def import_module(module_name, namespace=None):
""" Helper to require a given module, and place it in a namespace or import
all in global namespace.

"""
statement = None
if namespace:
if __package__ or "." in __name__:
statement = "from . import {} as {}".format(module_name, namespace)
else:
statement = "import {} as {}".format(module_name, namespace)
else:
if __package__ or "." in __name__:
statement = "from .{} import *".format(module_name)
else:
statement = "from {} import *".format(module_name)
try:
exec(statement)
except ImportError as e:
# Output expected (until fixed) ImportErrors.
print(e.__class__.__name__ + ": " + str(e))
except Exception as e:
# Output unexpected Exceptions.
print(e, False)
print(e.__class__.__name__ + ": " + str(e))


imports = [
# (Module, Namespace)
('openstudioairflow', 'airflow'),
('openstudioenergyplus', 'energyplus'),
('openstudiogbxml', 'gbxml'),
('openstudioisomodel', 'isomodel'),
('openstudiomeasure', 'measure'),
('openstudiomodel', 'model'),
# ('openstudiomodelcore', 'modelcore'),
# ('openstudiomodelgenerators', 'modelgenerators'),
# ('openstudiomodelgeometry', 'modelgeometry'),
# ('openstudiomodelhvac', 'modelhvac'),
# ('openstudiomodelrefrigeration', 'modelrefrigeration'),
# ('openstudiomodelresources', 'modelresources'),
# ('openstudiomodelsimulation', 'modelsimulation'),
# ('openstudiomodelairflow', 'modelairflow'),
# ('openstudiomodelavailabilitymanager', 'modelavailabilitymanager'),
# ('openstudiomodelplantequipmentoperationscheme', 'modelplantequipmentoperationscheme'),
# ('openstudiomodelstraightcomponent', 'modelstraightcomponent'),
# ('openstudiomodelzonehvac', 'momodelzonehvac'),
('openstudioosversion', 'osversion'),
('openstudioradiance', 'radiance'),
('openstudiosdd', 'sdd'),
('openstudioutilities', None),
('openstudioutilitiesbcl', None),
('openstudioutilitiescore', None),
('openstudioutilitiesdata', None),
('openstudioutilitiesgeometry', None),
('openstudioutilitiesidd', None),
('openstudioutilitiesidf', None),
# ('openstudioutilitiesfiletypes', None),
# ('openstudioutilitiesplot', None),
('openstudioutilitiessql', None),
('openstudioutilitiestime', None),
('openstudioutilitiesunits', None),
]

for (module_name, namespace) in imports:
import_module(module_name, namespace)
13 changes: 8 additions & 5 deletions python/testpath.py
@@ -1,20 +1,23 @@
import openstudio
# import openstudio
import openstudio_dynamic as openstudio

print openstudio.toString(openstudio.runmanager.RunManager().dbPath())
print(openstudio.toString(openstudio.runmanager.RunManager().dbPath()))

# workspace test
workspace = openstudio.Workspace()
zone = workspace.addObject(openstudio.IdfObject(openstudio.IddObjectType("Zone")))
zone = workspace.addObject(
openstudio.IdfObject(openstudio.IddObjectType("Zone"))
)
zone = zone.get()
zone.setName("New Zone")

for obj in workspace.objects():
print obj
print(obj)

# model test
model = openstudio.model.Model()
space = openstudio.model.Space(model)
space.setName("New Space")

for s in openstudio.model.getSpaces(model):
print s
print(s)