From 98682a1da35e7401bfc21d24abeb757ce91287b4 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 18 Nov 2020 00:02:19 -0500 Subject: [PATCH] renamed pip_install tool to just pip, move all the pip stuff to it filter out annoying ensurepip messages --- src/tasks/pyqt.cpp | 4 +-- src/tasks/python.cpp | 20 +----------- src/tools/tools.cpp | 76 ++++++++++++++++++++++++++++++++++++++++---- src/tools/tools.h | 20 +++++++++--- 4 files changed, 88 insertions(+), 32 deletions(-) diff --git a/src/tasks/pyqt.cpp b/src/tasks/pyqt.cpp index 102faa2..1489a80 100644 --- a/src/tasks/pyqt.cpp +++ b/src/tasks/pyqt.cpp @@ -132,7 +132,7 @@ void pyqt::build_and_install_from_source() { instrument([&] { - run_tool(pip_install() + run_tool(pip(pip::install) .package("PyQt-builder") .version(builder_version())); @@ -211,7 +211,7 @@ void pyqt::install_sip_file() } else { - run_tool(pip_install() + run_tool(pip(pip::install) .file(paths::cache() / sip_install_file())); installed_bypass.create(); diff --git a/src/tasks/python.cpp b/src/tasks/python.cpp index 6b84f1c..7628a5c 100644 --- a/src/tasks/python.cpp +++ b/src/tasks/python.cpp @@ -235,25 +235,7 @@ void python::copy_files() void python::install_pip() { cx().trace(context::generic, "installing pip"); - - run_tool(process_runner(process() - .binary(python_exe()) - .arg("-m", "ensurepip"))); - - run_tool(process_runner(process() - .binary(python_exe()) - .arg("-m pip") - .arg("install") - .arg("--no-warn-script-location") - .arg("--upgrade pip"))); - - // ssl errors while downloading through python without certifi - run_tool(process_runner(process() - .binary(python_exe()) - .arg("-m pip") - .arg("install") - .arg("--no-warn-script-location") - .arg("certifi"))); + run_tool(pip(pip::ensure)); } msbuild python::create_msbuild_tool(msbuild::ops o) diff --git a/src/tools/tools.cpp b/src/tools/tools.cpp index 7568160..b42588c 100644 --- a/src/tools/tools.cpp +++ b/src/tools/tools.cpp @@ -230,30 +230,94 @@ void nuget::do_run() } -pip_install::pip_install() - : basic_process_runner("pip install") +pip::pip(ops op) + : basic_process_runner("pip"), op_(op) { } -pip_install& pip_install::package(const std::string& s) +pip& pip::package(const std::string& s) { package_ = s; return *this; } -pip_install& pip_install::version(const std::string& s) +pip& pip::version(const std::string& s) { version_ = s; return *this; } -pip_install& pip_install::file(const fs::path& p) +pip& pip::file(const fs::path& p) { file_ = p; return *this; } -void pip_install::do_run() +void pip::do_run() +{ + switch (op_) + { + case ensure: + do_ensure(); + break; + + case install: + do_install(); + break; + + default: + cx().bail_out(context::generic, "pip unknown op {}", op_); + } +} + +void pip::do_ensure() +{ + // ensure + // + // this spits out two warnings about not being on PATH and suggests to add + // --no-warn-script-location, but that's not actually a valid command + // line parameter for `ensurepip` and it fails, unlike the `install` + // commands below + // + // so just filter it out + + set_process(process() + .stderr_filter([](auto&& f) + { + if (f.line.find("which is not on PATH") != -1) + f.lv = context::level::debug; + else if (f.line.find("Consider adding this directory")) + f.lv = context::level::debug; + }) + .binary(python::python_exe()) + .arg("-m", "ensurepip")); + + execute_and_join(); + + + // upgrade + set_process(process() + .binary(python::python_exe()) + .arg("-m pip") + .arg("install") + .arg("--no-warn-script-location") + .arg("--upgrade pip")); + + execute_and_join(); + + + // ssl errors while downloading through python without certifi + set_process(process() + .binary(python::python_exe()) + .arg("-m pip") + .arg("install") + .arg("--no-warn-script-location") + .arg("certifi")); + + execute_and_join(); +} + +void pip::do_install() { auto p = process() .binary(python::python_exe()) diff --git a/src/tools/tools.h b/src/tools/tools.h index 6b8f20d..12fe7fc 100644 --- a/src/tools/tools.h +++ b/src/tools/tools.h @@ -590,22 +590,32 @@ private: }; -class pip_install : public basic_process_runner +class pip : public basic_process_runner { public: - pip_install(); + enum ops + { + ensure = 1, + install + }; - pip_install& package(const std::string& s); - pip_install& version(const std::string& s); - pip_install& file(const fs::path& p); + pip(ops o); + + pip& package(const std::string& s); + pip& version(const std::string& s); + pip& file(const fs::path& p); protected: void do_run() override; private: + ops op_; std::string package_; std::string version_; fs::path file_; + + void do_ensure(); + void do_install(); };