@@ -42,7 +42,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4242#include " mkn/kul/except.hpp" // for Exception, KEXCEPT, KTHROW
4343#include " mkn/kul/string.hpp" // for String
4444
45- #include < memory> // for shared_ptr, make_shared
4645#include < string> // for basic_string, string
4746#include < vector> // for vector
4847#include < stdlib.h> // for exit
@@ -54,54 +53,72 @@ class Node;
5453namespace mkn {
5554namespace python3 {
5655
56+ // kul::File find_python3() KTHROW(std::exception) {
57+ // //
58+ // std::string bin = "python3";
59+
60+ // return std::string{};
61+ // }
62+
63+ std::string pyexec_for_string (std::string const & cmd) {
64+ mkn::kul::Process p (" python3" );
65+ mkn::kul::ProcessCapture pc (p);
66+ p << " -c" << cmd;
67+ p.start ();
68+ return pc.outs ();
69+ }
70+
5771class ModuleMaker : public maiken ::Module {
5872 public:
59- void init (maiken::Application& a, YAML::Node const & /* node*/ ) KTHROW(std::exception) override {
60- if (!kul::env::WHICH (PY.c_str ())) PY = " python" ;
61- PYTHON = mkn::kul::env::GET (" PYTHON" );
62- if (!PYTHON.empty ()) PY = PYTHON;
73+ // ModuleMaker() : PY{find_python3()} {}
74+ void init (maiken::Application& a, YAML::Node const & /* node*/ ) KTHROW(std::exception) override ;
75+
76+ private:
77+ auto python3_executable () const { return pyexec_for_string (" import sys; print(sys.executable)" ); }
78+ auto python3_extension_suffix () const {
79+ return pyexec_for_string (" \" import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))\" " );
80+ }
81+
82+ // auto static find_python3();
83+
84+ // std::string const PY = find_python3();
85+ // std::string HOME, PY = "python3", PYTHON, PATH = mkn::kul::env::GET("PATH");
86+ // mkn::kul::Dir bin;
87+ };
88+
89+ void ModuleMaker::init (maiken::Application& a, YAML::Node const & /* node*/ )
90+ KTHROW(std::exception) { /*
91+ if (!kul::env::WHICH(PY.c_str())) PY = "python";
92+ PYTHON = mkn::kul::env::GET("PYTHON");
93+ if (!PYTHON.empty()) PY = PYTHON;
6394#if defined(_WIN32)
64- if (PY.rfind (" .exe" ) == std::string::npos) PY += " .exe" ;
95+ if (PY.rfind(".exe") == std::string::npos) PY += ".exe";
6596#endif
66- mkn::kul::Process p (PY);
67- mkn::kul::ProcessCapture pc (p);
68- HOME = mkn::kul::env::GET (" PYTHON3_HOME" );
69- if (!HOME.empty ()) {
97+ mkn::kul::Process p(PY);
98+ mkn::kul::ProcessCapture pc(p);
99+ HOME = mkn::kul::env::GET("PYTHON3_HOME");
100+ if (!HOME.empty()) {
70101#if defined(_WIN32)
71- bin = mkn::kul::Dir (HOME);
72- if (!bin) KEXCEPT (kul::Exception, " $PYTHON3_HOME does not exist" );
102+ bin = mkn::kul::Dir(HOME);
103+ if (!bin) KEXCEPT(kul::Exception, "$PYTHON3_HOME does not exist");
73104#else
74- bin = mkn::kul::Dir (" bin" , HOME);
75- if (!bin) KEXCEPT (kul::Exception, " $PYTHON3_HOME/bin does not exist" );
105+ bin = mkn::kul::Dir("bin", HOME);
106+ if (!bin) KEXCEPT(kul::Exception, "$PYTHON3_HOME/bin does not exist");
76107#endif
77- path_var =
78- std::make_shared<kul::cli::EnvVar>(" PATH" , bin.real (), mkn::kul::cli::EnvVarMode::PREP);
79- mkn::kul::env::SET (path_var->name (), path_var->toString ().c_str ());
80- p.var (path_var->name (), path_var->toString ());
81- };
82-
83- auto const extension =
84- pyexec_for_string (" \" import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))\" " );
85-
86- a.m_cInfo .lib_ext = mkn::kul::String::LINES (extension)[0 ]; // drop EOL
87- a.m_cInfo .lib_prefix = " " ;
88- a.mode (maiken::compiler::Mode::SHAR);
89- }
108+ kul::cli::EnvVar const path_var{"PATH", bin.real(), mkn::kul::cli::EnvVarMode::PREP};
90109
91- private:
92- std::string pyexec_for_string (std::string const & cmd) {
93- mkn::kul::Process p (PY);
94- mkn::kul::ProcessCapture pc (p);
95- p << " -c" << cmd;
96- p.start ();
97- return pc.outs ();
98- }
110+ mkn::kul::env::SET(path_var.name(), path_var.toString().c_str());
111+ p.var(path_var.name(), path_var.toString());
112+ }*/
113+
114+ auto const extension =
115+ pyexec_for_string (" \" import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))\" " );
116+
117+ a.m_cInfo .lib_ext = mkn::kul::String::LINES (extension)[0 ]; // drop EOL
118+ a.m_cInfo .lib_prefix = " " ;
119+ a.mode (maiken::compiler::Mode::SHAR);
120+ }
99121
100- std::string HOME, PY = " python3" , PYTHON, PY_CONFIG = " python-config" ,
101- PY3_CONFIG = " python3-config" , PATH = mkn::kul::env::GET(" PATH" );
102- mkn::kul::Dir bin;
103- std::shared_ptr<kul::cli::EnvVar> path_var;
104- };
105122} // namespace python3
106123} // namespace mkn
107124
0 commit comments