15 return std::make_unique<PluginPythonShell>();
22 description.
add(
"--python",
"start python shell");
25 {
"--python-args",
"--py-args"},
"supply arguments to the python invocation. to provide multiple arguments use '\"' and separate them with spaces", {
ProgramOptions::A_REQUIRED_PARAMETER});
32 return std::string(
"HAL Python");
37 return std::string(
"0.1");
43 wchar_t** argv =
nullptr;
48 std::vector<std::string> py_args;
51 if (py_arg_str.find(
' ') != std::string::npos)
57 py_args.push_back(py_arg_str);
61 argc = py_args.size();
62 argv =
new wchar_t*[argc];
65 for (
int i = 0; i < argc; i++)
67 argv[i] = Py_DecodeLocale(py_args[i].c_str(),
nullptr);
68 if (argv[i] ==
nullptr)
79 PySys_SetArgv(argc, argv);
81 PyRun_SimpleString(
"import sys");
83 PyRun_SimpleString(
"from hal_py import *");
84 PyRun_SimpleString(
"import hal_py");
93 if (!std::filesystem::exists(file_path) || std::filesystem::is_directory(file_path) || !
utils::ends_with(file_path, std::string(
".py")))
99 std::ifstream stream(file_path);
101 stream.seekg(0, std::ios::end);
102 str.reserve(stream.tellg());
103 stream.seekg(0, std::ios::beg);
104 str.assign((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
106 PyRun_SimpleString(str.c_str());
116 for (
int i = 0; i < argc; ++i)
118 PyMem_RawFree(argv[i]);
ProgramOptions get_cli_options() const override
std::string get_name() const override
bool exec(ProgramArguments &args) override
std::string get_version() const override
std::string get_parameter(const std::string &flag) const
bool is_option_set(const std::string &flag) const
bool add(const std::string &flag, const std::string &description, const std::initializer_list< std::string > ¶meters={})
static const std::string A_REQUIRED_PARAMETER
constant to specify that a parameter is required and does not have a default value.
#define log_error(channel,...)
std::filesystem::path get_library_directory()
bool ends_with(const T &s, const T &end)
std::vector< T > split(const T &s, const char delim, bool obey_brackets=false)
std::unique_ptr< BasePluginInterface > create_plugin_instance()