Skip to content

Commit dd238f8

Browse files
committed
Add transition GUI to the E+ Auxiliary CLI
1 parent 9814fa5 commit dd238f8

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/EnergyPlus/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ if(LINK_WITH_PYTHON)
979979
TARGET energyplusapi
980980
POST_BUILD # TODO: I don't think we want to quote the generator expression
981981
COMMAND ${CMAKE_COMMAND} -E env --unset=PIP_REQUIRE_VIRTUALENV
982-
${Python_EXECUTABLE} -m pip install --target="$<TARGET_FILE_DIR:energyplusapi>/python_lib" --upgrade energyplus-launch==3.7.2
982+
${Python_EXECUTABLE} -m pip install --target="$<TARGET_FILE_DIR:energyplusapi>/python_lib" --upgrade energyplus-launch==3.7.2 energyplus-transition-tools==2.1.1
983983
COMMAND ${Python_EXECUTABLE} "${PROJECT_SOURCE_DIR}/cmake/PythonFixUpTclTk.py" "$<TARGET_FILE_DIR:energyplusapi>/python_lib"
984984
)
985985
endif()

src/EnergyPlus/CommandLineInterface.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,50 @@ sys.argv.append("energyplus")
278278
cmd += R"python(
279279
from eplaunch.tk_runner import main_gui
280280
main_gui()
281+
)python";
282+
// std::cout << "Trying to execute this python snippet: " << std::endl << cmd << std::endl;
283+
engine.exec(cmd);
284+
exit(0);
285+
});
286+
287+
auto *updaterSubCommand = auxiliaryToolsSubcommand->add_subcommand("updater", "IDF Version Updater");
288+
updaterSubCommand->add_option("args", python_fwd_args, "Extra Arguments forwarded to IDF Version Updater")->option_text("ARG ...");
289+
updaterSubCommand->positionals_at_end(true);
290+
updaterSubCommand->footer("You can pass extra arguments after the updater keyword, they will be forwarded to IDF Version Updater.");
291+
292+
updaterSubCommand->callback([&state, &python_fwd_args] {
293+
EnergyPlus::Python::PythonEngine engine(state);
294+
// There's probably better to be done, like instantiating the pythonEngine with the argc/argv then calling PyRun_SimpleFile but whatever
295+
std::string cmd = R"python(import sys
296+
sys.argv.clear()
297+
sys.argv.append("energyplus")
298+
)python";
299+
for (const auto &arg : python_fwd_args) {
300+
cmd += fmt::format("sys.argv.append(\"{}\")\n", arg);
301+
}
302+
303+
fs::path programDir = FileSystem::getParentDirectoryPath(FileSystem::getAbsolutePath(FileSystem::getProgramPath()));
304+
fs::path const pathToPythonPackages = programDir / "python_lib";
305+
std::string sPathToPythonPackages = std::string(pathToPythonPackages.string());
306+
std::replace(sPathToPythonPackages.begin(), sPathToPythonPackages.end(), '\\', '/');
307+
cmd += fmt::format("sys.path.insert(0, \"{}\")\n", sPathToPythonPackages);
308+
309+
std::string tclConfigDir;
310+
for (auto &p : std::filesystem::directory_iterator(pathToPythonPackages)) {
311+
if (p.is_directory()) {
312+
std::string dirName = p.path().filename().string();
313+
if (dirName.find("tcl", 0) == 0 && dirName.find(".", 0) > 0) {
314+
tclConfigDir = dirName;
315+
break;
316+
}
317+
}
318+
}
319+
cmd += "from os import environ\n";
320+
cmd += fmt::format("environ[\'TCL_LIBRARY\'] = \"{}/{}\"\n", sPathToPythonPackages, tclConfigDir);
321+
322+
cmd += R"python(
323+
from energyplus_transition.runner import main_gui
324+
main_gui(True)
281325
)python";
282326
// std::cout << "Trying to execute this python snippet: " << std::endl << cmd << std::endl;
283327
engine.exec(cmd);

0 commit comments

Comments
 (0)