-
Notifications
You must be signed in to change notification settings - Fork 222
Make pip install run only once instead of everytime CMake reconfigures #5266
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
Conversation
| # Add a command to pip install the requirements into the E+ folder and generate a stamp file | ||
| # Make it depend on the requirements.txt, so that it reruns when it changes | ||
| add_custom_command( | ||
| OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pip_install_done.stamp" | ||
| COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/pip_install_done.stamp" | ||
| COMMAND ${CMAKE_COMMAND} -E env --unset=PIP_REQUIRE_VIRTUALENV ${Python_EXECUTABLE} | ||
| -m pip install --target=${ENERGYPLUS_DIR}/python_lib --upgrade -r ${PROJECT_SOURCE_DIR}/python/requirements.txt | ||
| DEPENDS ${PROJECT_SOURCE_DIR}/python/requirements.txt | ||
| ) | ||
|
|
||
| # And a target that calls the above command. It is NOT called by default | ||
| add_custom_target(pip_install | ||
| DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pip_install_done.stamp" | ||
| ) | ||
|
|
||
| if(BUILD_CLI) | ||
| # When you build CLI, we want the pip_install to run, so add it as a dependency | ||
| # which will ensure it's run (beforehand, at **build** not configure time) | ||
| add_dependencies(pythonengine pip_install) | ||
| endif() |
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 is the gist, and it's commented enough that I don't need to say anything else.
I have tested that this works, and that changing requirements.txt triggers another pip install correctly.
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.
It's pretty much the same as
OpenStudio/ProjectMacros.cmake
Lines 153 to 180 in ba1b94b
| if(NOT TARGET ${PARENT_TARGET}_GeneratedHeaders) | |
| if ("${NAME}" STREQUAL "OpenStudioUtilitiesCore") | |
| # Workaround appending GenerateIddFactoryRun to GeneratedHeaders, so we ensure that the custom command below actually is called AFTER | |
| # GenerateIddFactoryRun has been called | |
| list(APPEND GeneratedHeaders "GenerateIddFactoryRun") | |
| endif() | |
| # Add a command to generate the generated headers discovered at this point. | |
| add_custom_command( | |
| OUTPUT "${PROJECT_BINARY_DIR}/${PARENT_TARGET}_HeadersGenerated_done.stamp" | |
| COMMAND ${CMAKE_COMMAND} -E touch "${PROJECT_BINARY_DIR}/${PARENT_TARGET}_HeadersGenerated_done.stamp" | |
| DEPENDS ${GeneratedHeaders} | |
| ) | |
| # And a target that calls the above command | |
| add_custom_target(${PARENT_TARGET}_GeneratedHeaders | |
| SOURCES "${PROJECT_BINARY_DIR}/${PARENT_TARGET}_HeadersGenerated_done.stamp" | |
| ) | |
| # Now we say that our PARENT_TARGET depends on this new GeneratedHeaders | |
| # target. This is where the magic happens. By making both the parent | |
| # and this *_swig.cxx files below rely on this new target we force all | |
| # of the generated files to be generated before either the | |
| # PARENT_TARGET is built or the cxx files are generated. This solves the problems with | |
| # parallel builds trying to generate the same file multiple times while still | |
| # allowing files to compile in parallel | |
| add_dependencies(${PARENT_TARGET} ${PARENT_TARGET}_GeneratedHeaders) | |
| endif() |
DEPENDS instead of SOURCES in add_custom_target, because I think that's the right one.
DEPENDS
Reference files and outputs of custom commands created with add_custom_command() command calls in the same directory (CMakeLists.txt file). They will be brought up to date when the target is built.
SOURCES
Specify additional source files to be included in the custom target. Specified source files will be added to IDE project files for convenience in editing even if they have no build rules.
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.
I think I've setup similar build rules with a custom target combined with a custom command. Each time I think I go back to the documentation looking for a way to do it with a single custom target, as I did again today, but in the end I think what you've done is the correct way. The add_custom_target command is always out of date, so we have to do this in two steps.
|
|
||
| execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}/${ENERGYPLUS_PATH}") | ||
|
|
||
| file(REMOVE "${PROJECT_BINARY_DIR}/python/engine/pip_install_done.stamp") |
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.
When we change E+ directory (update), remove the .stamp file to trigger another install
…run everytime cmake reconfigures
e2dc20c to
463dca6
Compare
| # Add a command to pip install the requirements into the E+ folder and generate a stamp file | ||
| # Make it depend on the requirements.txt, so that it reruns when it changes | ||
| add_custom_command( | ||
| OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pip_install_done.stamp" | ||
| COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/pip_install_done.stamp" | ||
| COMMAND ${CMAKE_COMMAND} -E env --unset=PIP_REQUIRE_VIRTUALENV ${Python_EXECUTABLE} | ||
| -m pip install --target=${ENERGYPLUS_DIR}/python_lib --upgrade -r ${PROJECT_SOURCE_DIR}/python/requirements.txt | ||
| DEPENDS ${PROJECT_SOURCE_DIR}/python/requirements.txt | ||
| ) | ||
|
|
||
| # And a target that calls the above command. It is NOT called by default | ||
| add_custom_target(pip_install | ||
| DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pip_install_done.stamp" | ||
| ) | ||
|
|
||
| if(BUILD_CLI) | ||
| # When you build CLI, we want the pip_install to run, so add it as a dependency | ||
| # which will ensure it's run (beforehand, at **build** not configure time) | ||
| add_dependencies(pythonengine pip_install) | ||
| endif() |
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.
I think I've setup similar build rules with a custom target combined with a custom command. Each time I think I go back to the documentation looking for a way to do it with a single custom target, as I did again today, but in the end I think what you've done is the correct way. The add_custom_target command is always out of date, so we have to do this in two steps.
Pull request overview
Make pip install run only once. This takes 15s to a minute (depending on pip cache and internet connection) and would run everytime cmake reconfigures, which annoyed the crap out of me.
@kbenne please review.
Pull Request Author
src/model/test)src/energyplus/Test)src/osversion/VersionTranslator.cpp)Labels:
IDDChangeAPIChangePull Request - Ready for CIso that CI builds your PRReview Checklist
This will not be exhaustively relevant to every PR.