Skip to content
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

Fix #5249 - Implement a CLI pip_list subcommand similar to the ruby gem_list one #5301

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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