diff --git a/src/cli/UpdateCommand.cpp b/src/cli/UpdateCommand.cpp index 4a66f56240..8e33996e76 100644 --- a/src/cli/UpdateCommand.cpp +++ b/src/cli/UpdateCommand.cpp @@ -297,5 +297,17 @@ shell.interact() pythonEngine->exec(cmd); } + void executePipListCommand(ScriptEngineInstance& pythonEngine) { + // TODO: seems like the CLI is picking up your virtualenvironment, so we manipulate sys.path to keep only the E+ folder for now + const std::string cmd = R"python( +import sys +sys.path = [x for x in sys.path if "EnergyPlus" in x] +import importlib.metadata +mods = sorted([f"{x.name}=={x.version}" for x in importlib.metadata.distributions()]) +[print(x) for x in mods] + )python"; + pythonEngine->exec(cmd); + } + } // namespace cli } // namespace openstudio diff --git a/src/cli/UpdateCommand.hpp b/src/cli/UpdateCommand.hpp index ef9eed1958..6874f23759 100644 --- a/src/cli/UpdateCommand.hpp +++ b/src/cli/UpdateCommand.hpp @@ -21,6 +21,7 @@ namespace cli { void executePythonScriptCommand(openstudio::path pythonScriptPath, ScriptEngineInstance& pythonEngine, const std::vector& arguments); void executeGemListCommand(ScriptEngineInstance& rubyEngine); + void executePipListCommand(ScriptEngineInstance& pythonEngine); void executeRubyRepl(ScriptEngineInstance& rubyEngine); void executePythonRepl(ScriptEngineInstance& pythonEngine); diff --git a/src/cli/main.cpp b/src/cli/main.cpp index e02f5039a9..4745f703be 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -270,9 +270,15 @@ int main(int argc, char* argv[]) { python_repl_command->callback([&pythonEngine] { openstudio::cli::executePythonRepl(pythonEngine); }); // } - [[maybe_unused]] auto* gem_listCommand = app.add_subcommand("gem_list", "Lists the set gems available to openstudio")->callback([&rubyEngine]() { - openstudio::cli::executeGemListCommand(rubyEngine); - }); + [[maybe_unused]] auto* gem_listCommand = + app.add_subcommand("gem_list", "Lists the set of gems available to openstudio")->callback([&rubyEngine]() { + openstudio::cli::executeGemListCommand(rubyEngine); + }); + + [[maybe_unused]] auto* pip_listCommand = + app.add_subcommand("pip_list", "Lists the set of python modules available to openstudio")->callback([&pythonEngine]() { + openstudio::cli::executePipListCommand(pythonEngine); + }); // Not hidding any commands right now // [[maybe_unused]] auto* list_commandsCommand = app.add_subcommand("list_commands", "Lists the entire set of available commands");