lib/pycall/libpython/finder.rb in pycall-1.1.0.rc1 vs lib/pycall/libpython/finder.rb in pycall-1.2.0.beta1

- old
+ new

@@ -17,29 +17,30 @@ LIBPREFIX = libprefix || 'lib' LIBSUFFIX = libsuffix || 'so' class << self + DEFAULT_PYTHON = [ + -'python3', + -'python', + ].freeze + + def find_python_config(python = nil) + python ||= DEFAULT_PYTHON + Array(python).each do |python_cmd| + python_config = investigate_python_config(python_cmd) + return [python_cmd, python_config] unless python_config.empty? + end + rescue + raise ::PyCall::PythonNotFound + else + raise ::PyCall::PythonNotFound + end + def find_libpython(python = nil) debug_report("find_libpython(#{python.inspect})") - if python - begin - python_config = investigate_python_config(python) - rescue - raise ::PyCall::PythonNotFound - end - else - %w[python python3].each do |python_cmd| - begin - python_config = investigate_python_config(python_cmd) - python = python_cmd - break - rescue - raise ::PyCall::PythonNotFound - end - end - end + python, python_config = find_python_config(python) set_PYTHONHOME(python_config) libs = make_libs(python_config) libpaths = make_libpaths(python_config) @@ -99,9 +100,10 @@ python_env = { 'PYTHONIOENCODING' => 'UTF-8' } debug_report("investigate_python_config(#{python.inspect})") IO.popen(python_env, [python, python_investigator_py], 'r') do |io| {}.tap do |config| io.each_line do |line| + next unless line =~ /: / key, value = line.chomp.split(': ', 2) case value when 'True', 'true', 'False', 'false' value = (value == 'True' || value == 'true') end