Add .find_python() method. Supersedes #777.

pull/787/head
Jussi Pakkanen 8 years ago
parent fbabe8ad85
commit 6ac9a8e738
  1. 11
      mesonbuild/interpreter.py
  2. 8
      mesonbuild/modules/python3.py
  3. 3
      test cases/python3/1 basic/meson.build
  4. 5
      test cases/python3/1 basic/subdir/meson.build
  5. 4
      test cases/python3/2 extmodule/meson.build
  6. 10
      test cases/python3/3 cython/libdir/meson.build
  7. 4
      test cases/python3/3 cython/meson.build

@ -1013,11 +1013,12 @@ class ModuleHolder(InterpreterObject):
state.target_machine = self.interpreter.builtin['target_machine'].held_object
if self.held_object.is_snippet(method_name):
value = fn(self.interpreter, state, args, kwargs)
return self.interpreter.holderify(value)
else:
value = fn(state, args, kwargs)
if num_targets != len(self.interpreter.build.targets):
raise InterpreterException('Extension module altered internal state illegally.')
return self.interpreter.module_method_callback(value)
return self.interpreter.module_method_callback(value)
class MesonMain(InterpreterObject):
def __init__(self, build, interpreter):
@ -1275,8 +1276,11 @@ class Interpreter(InterpreterBase):
return DataHolder(item)
elif isinstance(item, dependencies.InternalDependency):
return InternalDependencyHolder(item)
elif isinstance(item, dependencies.ExternalProgram):
return ExternalProgramHolder(item)
elif hasattr(item, 'held_object'):
return item
else:
print(item)
raise InterpreterException('Module returned a value of unknown type.')
def process_new_values(self, invalues):
@ -1293,6 +1297,8 @@ class Interpreter(InterpreterBase):
self.build.install_scripts.append(v)
elif isinstance(v, build.Data):
self.build.data.append(v)
elif isinstance(v, dependencies.ExternalProgram):
return ExternalProgramHolder(v)
elif isinstance(v, dependencies.InternalDependency):
# FIXME: This is special cased and not ideal:
# The first source is our new VapiTarget, the rest are deps
@ -1304,7 +1310,6 @@ class Interpreter(InterpreterBase):
def module_method_callback(self, return_object):
if not isinstance(return_object, ModuleReturnValue):
print(return_object)
assert(False)
raise InterpreterException('Bug in module, it returned an invalid object')
invalues = return_object.new_objects

@ -12,9 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from .. import mesonlib
import sys
from .. import mesonlib, dependencies
from . import ExtensionModule
from mesonbuild.modules import ModuleReturnValue
class Python3Module(ExtensionModule):
def __init__(self):
@ -39,5 +41,9 @@ class Python3Module(ExtensionModule):
kwargs['name_suffix'] = suffix
return interpreter.func_shared_module(None, args, kwargs)
def find_python(self, state, args, kwargs):
py3 = dependencies.ExternalProgram('python3', sys.executable, silent=True)
return ModuleReturnValue(py3, [py3])
def initialize():
return Python3Module()

@ -1,6 +1,7 @@
project('python sample', 'c')
py3 = find_program('python3')
py3_mod = import('python3')
py3 = py3_mod.find_python()
main = files('prog.py')

@ -1,5 +1,4 @@
submain = find_program('subprog.py')
test('subdir',
submain,
py3,
args : files('subprog.py'),
env : 'PYTHONPATH=' + meson.source_root())

@ -4,13 +4,15 @@ project('Python extension module', 'c',
# we must build this project the same way.
py3_mod = import('python3')
py3 = py3_mod.find_python()
py3_dep = dependency('python3', required : false)
if py3_dep.found()
subdir('ext')
test('extmod',
find_program('blaster.py'),
py3,
args : files('blaster.py'),
env : ['PYTHONPATH=' + pypathdir])
else
error('MESON_SKIP_TEST: Python3 libraries not found, skipping test.')

@ -1,13 +1,3 @@
if host_machine.system() == 'darwin'
# Default suffix is 'dylib' but Python does not use for extensions.
suffix = 'so'
elif host_machine.system() == 'windows'
# On Windows the extension is pyd for some unexplainable reason.
suffix = 'pyd'
else
suffix = []
endif
pyx_c = custom_target('storer_pyx',
output : 'storer_pyx.c',
input : 'storer.pyx',

@ -7,10 +7,12 @@ py3_dep = dependency('python3', required : false)
if cython.found() and py3_dep.found()
py3_dep = dependency('python3')
py3_mod = import('python3')
py3 = py3_mod.find_python()
subdir('libdir')
test('cython tester',
find_program('cytest.py'),
py3,
args : files('cytest.py'),
env : ['PYTHONPATH=' + pydir]
)
else

Loading…
Cancel
Save