Skip to content

Commit

Permalink
Test meson integration
Browse files Browse the repository at this point in the history
Fix #2236
  • Loading branch information
serge-sans-paille committed Sep 22, 2024
1 parent 3a712c9 commit 970132f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Changelog = "https://pythran.readthedocs.io/en/latest/Changelog.html"

[project.optional-dependencies]
doc = ["numpy", "nbsphinx", "scipy", "guzzle_sphinx_theme"]
test = ["ipython", "nbval", "cython", "wheel", "packaging"]
test = ["ipython", "nbval", "cython", "wheel", "packaging", "ninja", "meson",
"meson_python"]

[project.scripts]
pythran = "pythran.run:run"
Expand Down
28 changes: 28 additions & 0 deletions pythran/tests/test_distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,31 @@ def test_setup_bdist_install3(self):
demo_so = find_so(r"a.*\.so", dist_path)
self.assertIsNotNone(demo_so)
shutil.rmtree(dist_path)

try:
check_call(['ninja', '--version'])
has_ninja = True
except:
has_ninja = False

try:
check_call(['meson', '--version'])
has_meson = True
except:
has_meson = False

class TestMeson(unittest.TestCase):

@unittest.skipIf(not has_meson, "meson not found")
@unittest.skipIf(not has_ninja, "ninja not found")
def test_meson_build(self):
srcdir = os.path.join(cwd, 'test_distutils')
builddir = os.path.join(srcdir, '_meson_build')
shutil.rmtree(builddir, ignore_errors=True)
check_call(['meson', 'setup', builddir, '.'],
cwd=srcdir)
check_call(['ninja', '-v'],
cwd=builddir)
check_call([python, '-c', 'import b'],
cwd=builddir)

30 changes: 30 additions & 0 deletions pythran/tests/test_distutils/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
project('pythran-test', 'cpp')
pythran = find_program('pythran', native: true, version: '>=0.14.0')
pythran_cmd = [pythran, '-E', '@INPUT@', '-o', '@OUTPUT@']

pythranrc = join_paths(meson.project_source_root(), 'pythran.rc')

pythran_env = environment()
pythran_env.set('PYTHRANRC', pythranrc)

b_cpp = custom_target(
'b_cpp',
output : 'b.cpp',
input: 'b.py',
command: pythran_cmd,
env: pythran_env,
depend_files: [pythranrc],
)

pythran_config = find_program('pythran-config', native: true, version: '>=0.14.0')
pythran_cppflags = run_command(pythran_config, '--cflags', check:true, env:pythran_env).stdout().strip().split()
pythran_ldflags = run_command(pythran_config, '--libs', check:true, env:pythran_env).stdout().strip().split()

py = import('python').find_installation(pure: false)
py.extension_module(
'b',
b_cpp,
cpp_args: pythran_cppflags,
link_args: pythran_ldflags,
install: true,
)
3 changes: 3 additions & 0 deletions pythran/tests/test_distutils/pythran.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[compiler]
blas=openblas
include_dirs=/usr/include/openblas

0 comments on commit 970132f

Please sign in to comment.