From 60d70f0b1a3e33db0203cbc812ad41342c20d641 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 2 May 2020 03:08:13 -0400 Subject: [PATCH] made pip install a tool --- src/tasks/pyqt.cpp | 20 +++++--------------- src/tools.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/tools.h | 19 +++++++++++++++++++ 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/src/tasks/pyqt.cpp b/src/tasks/pyqt.cpp index 0097c83..eb43eb9 100644 --- a/src/tasks/pyqt.cpp +++ b/src/tasks/pyqt.cpp @@ -36,13 +36,9 @@ void pyqt::do_build_and_install() "_QOpenGLFunctions_4_1_Core" }; - run_tool(process_runner(process() - .binary(python::python_exe()) - .arg("-m", "pip") - .arg("install") - .arg("--no-warn-script-location") - .arg("--disable-pip-version-check") - .arg("PyQt-builder==" + versions::pyqt_builder()))); + run_tool(pip_install() + .package("PyQt-builder") + .version(versions::pyqt_builder())); run_tool(patcher() .task(name()) @@ -100,14 +96,8 @@ void pyqt::do_build_and_install() } else { - run_tool(process_runner(process() - .binary(python::python_exe()) - .arg("-m", "pip") - .arg("install") - .arg("--no-warn-script-location") - .arg("--disable-pip-version-check") - .arg(paths::cache() / sip_install_file()) - .cwd(python::source_path()))); + run_tool(pip_install() + .file(paths::cache() / sip_install_file())); op::touch(source_path() / "_mob_installed"); } diff --git a/src/tools.cpp b/src/tools.cpp index 76b7d6f..2ddf600 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -3,6 +3,7 @@ #include "utility.h" #include "op.h" #include "conf.h" +#include "tasks/tasks.h" namespace builder { @@ -865,4 +866,45 @@ void nuget::do_run() execute_and_join(); } + +pip_install::pip_install() + : basic_process_runner("pip install") +{ +} + +pip_install& pip_install::package(const std::string& s) +{ + package_ = s; + return *this; +} + +pip_install& pip_install::version(const std::string& s) +{ + version_ = s; + return *this; +} + +pip_install& pip_install::file(const fs::path& p) +{ + file_ = p; + return *this; +} + +void pip_install::do_run() +{ + process_ + .binary(python::python_exe()) + .arg("-m", "pip") + .arg("install") + .arg("--no-warn-script-location") + .arg("--disable-pip-version-check"); + + if (!package_.empty()) + process_.arg(package_ + "==" + version_); + else if (!file_.empty()) + process_.arg(file_); + + execute_and_join(); +} + } // namespace diff --git a/src/tools.h b/src/tools.h index 0a5694b..a5cec69 100644 --- a/src/tools.h +++ b/src/tools.h @@ -274,4 +274,23 @@ private: fs::path sln_; }; + +class pip_install : public basic_process_runner +{ +public: + pip_install(); + + pip_install& package(const std::string& s); + pip_install& version(const std::string& s); + pip_install& file(const fs::path& p); + +protected: + void do_run() override; + +private: + std::string package_; + std::string version_; + fs::path file_; +}; + } // namespace