Skip to content

Commit

Permalink
Merge pull request #5301 from NREL/5249_pip_list
Browse files Browse the repository at this point in the history
Fix #5249 - Implement a CLI `pip_list` subcommand similar to the ruby `gem_list` one
  • Loading branch information
kbenne authored Nov 13, 2024
2 parents a021de9 + 6d75a7c commit 1ce1991
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/cli/UpdateCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/cli/UpdateCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace cli {
void executePythonScriptCommand(openstudio::path pythonScriptPath, ScriptEngineInstance& pythonEngine, const std::vector<std::string>& arguments);

void executeGemListCommand(ScriptEngineInstance& rubyEngine);
void executePipListCommand(ScriptEngineInstance& pythonEngine);

void executeRubyRepl(ScriptEngineInstance& rubyEngine);
void executePythonRepl(ScriptEngineInstance& pythonEngine);
Expand Down
12 changes: 9 additions & 3 deletions src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 1ce1991

Please sign in to comment.