From 4ab6123ff0d99c5590dbf3165731b9486ff8b197 Mon Sep 17 00:00:00 2001 From: "Charles K. Neimog" Date: Tue, 26 Nov 2024 02:48:35 -0300 Subject: [PATCH] fix object for mac --- Resources/Pd/pd4web.cpp | 44 ++++++++++++++++++++++++---------------- Sources/pd4web/Pd4Web.py | 14 ++++++++++++- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Resources/Pd/pd4web.cpp b/Resources/Pd/pd4web.cpp index e6a8483e..4f867df1 100644 --- a/Resources/Pd/pd4web.cpp +++ b/Resources/Pd/pd4web.cpp @@ -193,7 +193,7 @@ bool pd4web_terminal(Pd4Web *x, std::string cmd, bool detached = false, std::thread t([x, cmd, sucessMsg, showMessage, clearNewline]() { //post("[pd4web] Running command: %s", cmd.c_str()); - std::array Buf; + std::array Buf; std::string Result; FILE *Pipe = popen(cmd.c_str(), "r"); if (!Pipe) { @@ -260,6 +260,26 @@ bool pd4web_terminal(Pd4Web *x, std::string cmd, bool detached = false, return x->result; } +// ───────────────────────────────────── +static void pd4web_debug_terminal(Pd4Web *x, t_symbol *s, int argc, t_atom *argv) { + // loop through the arguments and create the command + std::string cmd; + for (int i = 0; i < argc; i++) { + if (argv[i].a_type == A_SYMBOL) { + cmd += atom_getsymbolarg(i, argc, argv)->s_name; + } else if (argv[i].a_type == A_FLOAT) { + cmd += std::to_string(atom_getfloatarg(i, argc, argv)); + } else { + pd_error(x, "[pd4web] Invalid argument"); + return; + } + if (i < argc - 1) { + cmd += " "; + } + } + pd4web_terminal(x, cmd, false, false, true, false); +} + // ───────────────────────────────────── static void pd4web_version(Pd4Web *x); @@ -534,6 +554,9 @@ static void pd4web_compile(Pd4Web *x) { if (x->patch != "") { cmd += x->patch; + } else { + pd_error(x, "[pd4web] No patch selected"); + return; } if (x->running) { @@ -551,27 +574,14 @@ static void *pd4web_new(t_symbol *s, int argc, t_atom *argv) { x->objRoot = pd4web_class->c_externdir->s_name; x->running = false; - // check if there is some python installed - #ifdef _WIN32 x->pythonGlobal = "py"; x->pip = "\"" + x->objRoot + "\\.venv\\Scripts\\pip.exe\""; x->python = "\"" + x->objRoot + "\\.venv\\Scripts\\python.exe\""; x->pd4web = "\"" + x->objRoot + "\\.venv\\Scripts\\pd4web.exe\""; #elif defined(__APPLE__) - std::string PATHS = "PATH=" + x->objRoot + "/.venv/bin:"; - std::string venv_folder = x->objRoot + "/.venv/lib/"; - for (const auto &entry : std::filesystem::directory_iterator(venv_folder)) { - std::string folder = entry.path().filename().string(); - if (folder.find("python") != std::string::npos) { - venv_folder += folder; - break; - } - } - post("[pd4web] venv folder: %s", venv_folder.c_str()); - PATHS += venv_folder + "/site-packages:"; - PATHS += "/usr/local/bin:/usr/bin:/bin"; - putenv((char *)PATHS.c_str()); + std::string PATHS = "PATH=" + x->objRoot + "/.venv/bin:/usr/local/bin:/usr/bin:/bin"; + putenv((char * )PATHS.c_str()); x->pythonGlobal = "python3"; x->pip = "\"" + x->objRoot + "/.venv/bin/pip\""; x->python = "\"" + x->objRoot + "/.venv/bin/python\""; @@ -586,7 +596,6 @@ static void *pd4web_new(t_symbol *s, int argc, t_atom *argv) { return nullptr; #endif std::string python = x->pythonGlobal + " --version"; - if (!pd4web_terminal(x, python, false, false, false, false)) { pd_error(x, "[pd4web] Python 3 is not installed. Please install Python first."); return nullptr; @@ -639,5 +648,6 @@ extern "C" void pd4web_setup(void) { class_addmethod(pd4web_class, (t_method)pd4web_update, gensym("update"), A_GIMME, 0); class_addmethod(pd4web_class, (t_method)pd4web_update, gensym("git"), A_GIMME, 0); class_addmethod(pd4web_class, (t_method)pd4web_clear_install, gensym("uninstall"), A_NULL); + class_addmethod(pd4web_class, (t_method)pd4web_debug_terminal, gensym("_run"), A_GIMME, A_NULL); class_addbang(pd4web_class, (t_method)pd4web_compile); } diff --git a/Sources/pd4web/Pd4Web.py b/Sources/pd4web/Pd4Web.py index 74919e28..08cc40a0 100644 --- a/Sources/pd4web/Pd4Web.py +++ b/Sources/pd4web/Pd4Web.py @@ -67,6 +67,7 @@ def argParse(self): self.Parser = parser self.Patch = os.path.abspath(self.Parser.patch_file) + if not os.path.isfile(self.Patch): self.exception("\n\nError: Patch file not found") @@ -114,7 +115,10 @@ def InitVariables(self): self.env = os.environ.copy() python_dir = os.path.dirname(sys.executable) - self.env["PATH"] = f"{python_dir};{self.env['PATH']}" + if "PATH" in self.env: + self.env["PATH"] = f"{python_dir};{self.env['PATH']}" + else: + self.env["PATH"] = python_dir self.env["PYTHON"] = sys.executable self.env["EMSDK_QUIET"] = "1" @@ -326,6 +330,14 @@ def options_flags(self, parser): type=int, help="Initial memory size in MB", ) + + parser.add_argument( + "--patch-file", + required=False, + default="", + type=str, + help="Patch file to compile", + ) # GUI parser.add_argument(