-
Notifications
You must be signed in to change notification settings - Fork 192
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
Python plugin jinja template #4858
Conversation
resources/Examples/compact_osw/files/python_plugin_program_erb.py
Outdated
Show resolved
Hide resolved
from pyenergyplus.plugin import EnergyPlusPlugin | ||
|
||
import os, sys | ||
sys.path.append('C:/Python38/Lib/site-packages') # this should (needs to?) be same version as E+'s version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to have to make this path to system python's site_packages some kind of cmake replacement or a command line arg if we want to test this.
But more broadly, this is going to pose the question of whether we should/need to provide some common python packages out of the box like we do for ruby gems (and take into account the pain that it is to maintain that stuff). I'm specifically thinking about native packages (related to this issue #4846), (pandas does have a C extension as well, I think something about numpy may be special)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following #4868 you can make your test pass the --python_home
or --python_path
and it'll work (provided the machine it runs on does have jinja2 installed)
I think we should discuss whether we should always add some common python packages like Jinja2 (#4906 (comment))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the jinja2
package doesn't get bundled into the CLI, what paths would be set for --python_home
and --python_path
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See here:
OpenStudio/src/cli/CMakeLists.txt
Lines 343 to 393 in 0ab0280
if(NOT EXISTS "${Python_ROOT_DIR}") | |
# Python_STDLIB: we expect it to be | |
# Unix: ~/.pyenv/versions/3.8.12/lib/python3.8 or | |
# or on CI: /usr/lib/python3.8/ ... with numpy if install via pip3 and not apt install python3-numpy in `/usr/local/lib/python3.8/dist-packages/` | |
# Windows C:\Python38\Lib | |
cmake_path(GET Python_STDLIB PARENT_PATH Python_ROOT_DIR) | |
if(UNIX) | |
cmake_path(GET Python_ROOT_DIR PARENT_PATH Python_ROOT_DIR) | |
endif() | |
endif() | |
if(UNIX) | |
if(EXISTS "${Python_SITELIB}") | |
set(PYTHON_PATH "${Python_SITELIB}" "${Python_STDLIB}/lib-dynload") | |
else() | |
set(PYTHON_PATH "${Python_STDLIB}/lib-dynload") | |
endif() | |
if(NOT APPLE) | |
set(EXTRA_LOCAL_DIST "/usr/local/lib/python3.8/dist-packages") | |
if (EXISTS "${EXTRA_LOCAL_DIST}") | |
list(APPEND PYTHON_PATH "${EXTRA_LOCAL_DIST}") | |
endif() | |
endif() | |
else() | |
set(PYTHON_PATH "$<SHELL_PATH:${Python_SITELIB}>") | |
endif() | |
message(DEBUG "PYTHON_PATH=${PYTHON_PATH}") | |
add_test(NAME OpenStudioCLI.Labs.execute_python_script.numpy.explicit_sys_path_insert | |
COMMAND $<TARGET_FILE:openstudio> labs execute_python_script execute_python_script_with_numpy.py ${Python_STDLIB} | |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test/" | |
) | |
add_test(NAME OpenStudioCLI.Labs.execute_python_script.numpy.python_path | |
COMMAND $<TARGET_FILE:openstudio> labs | |
"$<$<BOOL:${PYTHON_PATH}>:--python_path;$<JOIN:${PYTHON_PATH},;--python_path;>>" | |
execute_python_script execute_python_script_with_numpy.py | |
COMMAND_EXPAND_LISTS | |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test/" | |
) | |
add_test(NAME OpenStudioCLI.Labs.execute_python_script.numpy.python_home | |
COMMAND $<TARGET_FILE:openstudio> labs | |
--python_home "$<SHELL_PATH:${Python_ROOT_DIR}>" | |
execute_python_script execute_python_script_with_numpy.py | |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test/" | |
) | |
else() | |
message(AUTHOR_WARNING "Cannot run the python numpy test, as numpy isn't installed on your system python") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(py39)julien@OS-build-release$ Products/openstudio labs -c "import jinja2"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'jinja2'
terminate called after throwing an instance of 'std::runtime_error'
what(): Error executing Python code
Aborted (core dumped)
(py39)julien@OS-build-release$ Products/openstudio labs --python_path /home/julien/.pyenv/versions/3.8.13/lib/python3.8/site-packages -c "import jinja2"
66c37d0
to
2182b84
Compare
@jmarrec This appears to be working now (i.e., can import pandas and jinja2). How can we formalize running |
@@ -0,0 +1,132 @@ | |||
import os, sys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import os, sys | |
import os | |
import sys |
Generally speaking you should pip install black isort
on your system and reformat your python files via
isort .
black -l 120 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to resources/workflow
.
Or it'll get installed: resources/Examples is installed to disk:
OpenStudio/resources/CMakeLists.txt
Line 420 in d8bbf52
install(DIRECTORY "Examples" DESTINATION . COMPONENT "CLI") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be inside the measures directory inside resources/ , so it is a proper measure and can be moved around.
…B/Jinja templates are python files
… pathlib.Path (modernize python code)
… to ensure plugins do run
Yes. like you've done. But it bothers me we don't check at all if E+ actually runs the python plugins |
@joseph-robertson I've made some adjustments (moved things around, linted) + actually tested the plugins are running. Assuming CI comes clean and you're ok with the changes, this can drop. |
CI Results for 148f089:
|
Pull request overview
Addresses Approach 1(A), but using a python measure: #4634 (comment)
I've created two measures:
PythonPluginRuby
(usespython_plugin_program_erb.py
template)PythonPluginPython
(usespython_plugin_program_jinja.py
template)Both measures are called by
compact_python_plugin.osw
.Appears to be working successfully.
Update: I've removed
sys.path.append
and tried running with OS v3.7.0 (w/out labs), and it appears to be working successfully.Pull Request Author
src/model/test
)src/energyplus/Test
)src/osversion/VersionTranslator.cpp
)Labels:
IDDChange
APIChange
Pull Request - Ready for CI
so that CI builds your PRReview Checklist
This will not be exhaustively relevant to every PR.