From ab72f52743518915c7602f6d3631b9cb8080e0e2 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sun, 12 Jul 2020 09:01:55 -0400 Subject: [PATCH 1/6] setuptools is not stdlib, but distutils is --- test cases/python/5 modules kwarg/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test cases/python/5 modules kwarg/meson.build b/test cases/python/5 modules kwarg/meson.build index 3c9d54fc9..9751adaab 100644 --- a/test cases/python/5 modules kwarg/meson.build +++ b/test cases/python/5 modules kwarg/meson.build @@ -1,7 +1,7 @@ project('python kwarg') py = import('python') -prog_python = py.find_installation('python3', modules : ['setuptools']) +prog_python = py.find_installation('python3', modules : ['distutils']) assert(prog_python.found() == true, 'python not found when should be') prog_python = py.find_installation('python3', modules : ['thisbetternotexistmod'], required : false) assert(prog_python.found() == false, 'python not found but reported as found') From 173d1624cb82f213d1e4fd738874c4de49f9bf47 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sun, 12 Jul 2020 09:04:59 -0400 Subject: [PATCH 2/6] c lang not needed for this test --- test cases/python/1 basic/meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test cases/python/1 basic/meson.build b/test cases/python/1 basic/meson.build index 9c3af10c6..bd9a65c81 100644 --- a/test cases/python/1 basic/meson.build +++ b/test cases/python/1 basic/meson.build @@ -1,4 +1,4 @@ -project('python sample', 'c') +project('python sample') py_mod = import('python') py = py_mod.find_installation('python3') @@ -12,6 +12,7 @@ py_purelib = py.get_path('purelib') if not py_purelib.endswith('site-packages') error('Python3 purelib path seems invalid? ' + py_purelib) endif +message('Python purelib path:', py_purelib) # could be 'lib64' or 'Lib' on some systems py_platlib = py.get_path('platlib') From 4f1a240bc2c2029f281330c13273bfc876219c45 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sun, 12 Jul 2020 09:08:04 -0400 Subject: [PATCH 3/6] raise SystemExit() generally preferred to sys.exit(1) --- test cases/python/1 basic/prog.py | 3 +-- test cases/python/1 basic/subdir/subprog.py | 3 +-- test cases/python/2 extmodule/blaster.py | 7 ++----- test cases/python/3 cython/cytest.py | 10 +++------- .../4 custom target depends extmodule/blaster.py | 6 ++---- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/test cases/python/1 basic/prog.py b/test cases/python/1 basic/prog.py index 9d95aea27..720fdb18b 100755 --- a/test cases/python/1 basic/prog.py +++ b/test cases/python/1 basic/prog.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 from gluon import gluonator -import sys print('Running mainprog from root dir.') if gluonator.gluoninate() != 42: - sys.exit(1) + raise ValueError("!= 42") diff --git a/test cases/python/1 basic/subdir/subprog.py b/test cases/python/1 basic/subdir/subprog.py index 08652f084..54178e5f4 100755 --- a/test cases/python/1 basic/subdir/subprog.py +++ b/test cases/python/1 basic/subdir/subprog.py @@ -4,9 +4,8 @@ # point to source root. from gluon import gluonator -import sys print('Running mainprog from subdir.') if gluonator.gluoninate() != 42: - sys.exit(1) + raise ValueError("!= 42") diff --git a/test cases/python/2 extmodule/blaster.py b/test cases/python/2 extmodule/blaster.py index 7e1eae63a..1f0187645 100755 --- a/test cases/python/2 extmodule/blaster.py +++ b/test cases/python/2 extmodule/blaster.py @@ -1,14 +1,11 @@ #!/usr/bin/env python3 import tachyon -import sys result = tachyon.phaserize('shoot') if not isinstance(result, int): - print('Returned result not an integer.') - sys.exit(1) + raise SystemExit('Returned result not an integer.') if result != 1: - print('Returned result {} is not 1.'.format(result)) - sys.exit(1) + raise SystemExit('Returned result {} is not 1.'.format(result)) diff --git a/test cases/python/3 cython/cytest.py b/test cases/python/3 cython/cytest.py index 43443dc66..c08ffeed3 100755 --- a/test cases/python/3 cython/cytest.py +++ b/test cases/python/3 cython/cytest.py @@ -1,23 +1,19 @@ #!/usr/bin/env python3 from storer import Storer -import sys s = Storer() if s.get_value() != 0: - print('Initial value incorrect.') - sys.exit(1) + raise SystemExit('Initial value incorrect.') s.set_value(42) if s.get_value() != 42: - print('Setting value failed.') - sys.exit(1) + raise SystemExit('Setting value failed.') try: s.set_value('not a number') - print('Using wrong argument type did not fail.') - sys.exit(1) + raise SystemExit('Using wrong argument type did not fail.') except TypeError: pass diff --git a/test cases/python/4 custom target depends extmodule/blaster.py b/test cases/python/4 custom target depends extmodule/blaster.py index 6106f6ba0..09039cbc9 100644 --- a/test cases/python/4 custom target depends extmodule/blaster.py +++ b/test cases/python/4 custom target depends extmodule/blaster.py @@ -24,9 +24,7 @@ if options.output: f.write('success') if not isinstance(result, int): - print('Returned result not an integer.') - sys.exit(1) + raise SystemExit('Returned result not an integer.') if result != 1: - print('Returned result {} is not 1.'.format(result)) - sys.exit(1) + raise SystemExit('Returned result {} is not 1.'.format(result)) From 895de87b9069d1fca51c3550fe7d113a43f9e586 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sun, 12 Jul 2020 09:12:16 -0400 Subject: [PATCH 4/6] some python test cases don't care about backend, so run them in any case --- run_project_tests.py | 2 +- test cases/python/2 extmodule/meson.build | 4 +++ test cases/python/3 cython/meson.build | 35 +++++++++++-------- .../meson.build | 4 +++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/run_project_tests.py b/run_project_tests.py index c36825339..5445e0137 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -939,7 +939,7 @@ def detect_tests_to_run(only: T.List[str], use_tmp: bool) -> T.List[T.Tuple[str, # CUDA tests on Windows: use Ninja backend: python run_project_tests.py --only cuda --backend ninja TestCategory('cuda', 'cuda', backend not in (Backend.ninja, Backend.xcode) or not shutil.which('nvcc')), TestCategory('python3', 'python3', backend is not Backend.ninja), - TestCategory('python', 'python', backend is not Backend.ninja), + TestCategory('python', 'python'), TestCategory('fpga', 'fpga', shutil.which('yosys') is None), TestCategory('frameworks', 'frameworks'), TestCategory('nasm', 'nasm'), diff --git a/test cases/python/2 extmodule/meson.build b/test cases/python/2 extmodule/meson.build index b4eb96039..54c50b4be 100644 --- a/test cases/python/2 extmodule/meson.build +++ b/test cases/python/2 extmodule/meson.build @@ -3,6 +3,10 @@ project('Python extension module', 'c', # Because Windows Python ships only with optimized libs, # we must build this project the same way. +if meson.backend() != 'ninja' + error('MESON_SKIP_TEST: Ninja backend required') +endif + py_mod = import('python') py = py_mod.find_installation() py_dep = py.dependency() diff --git a/test cases/python/3 cython/meson.build b/test cases/python/3 cython/meson.build index 194920bd8..18c05d4d5 100644 --- a/test cases/python/3 cython/meson.build +++ b/test cases/python/3 cython/meson.build @@ -1,20 +1,27 @@ project('cython', 'c', default_options : ['warning_level=3']) -cython = find_program('cython3', required : false) -py3_dep = dependency('python3', required : false) +if meson.backend() != 'ninja' + error('MESON_SKIP_TEST: Ninja backend required') +endif -if cython.found() and py3_dep.found() - py_mod = import('python') - py3 = py_mod.find_installation() - py3_dep = py3.dependency() - subdir('libdir') +cython = find_program('cython', required : false) +if not cython.found() + error('MESON_SKIP_TEST: Cython3 not found.') +endif - test('cython tester', - py3, - args : files('cytest.py'), - env : ['PYTHONPATH=' + pydir] - ) -else - error('MESON_SKIP_TEST: Cython3 or Python3 libraries not found, skipping test.') +py3_dep = dependency('python3', required : false) +if not py3_dep.found() + error('MESON_SKIP_TEST: Python library not found.') endif + +py_mod = import('python') +py3 = py_mod.find_installation() +py3_dep = py3.dependency() +subdir('libdir') + +test('cython tester', + py3, + args : files('cytest.py'), + env : ['PYTHONPATH=' + pydir] +) diff --git a/test cases/python/4 custom target depends extmodule/meson.build b/test cases/python/4 custom target depends extmodule/meson.build index 38353772c..ccccdafbe 100644 --- a/test cases/python/4 custom target depends extmodule/meson.build +++ b/test cases/python/4 custom target depends extmodule/meson.build @@ -3,6 +3,10 @@ project('Python extension module', 'c', # Because Windows Python ships only with optimized libs, # we must build this project the same way. +if meson.backend() != 'ninja' + error('MESON_SKIP_TEST: Ninja backend required') +endif + py_mod = import('python') py3 = py_mod.find_installation() py3_dep = py3.dependency(required : false) From 7851495064521b179b2fd02fdc73e3d55da4ae86 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sun, 12 Jul 2020 09:13:00 -0400 Subject: [PATCH 5/6] remove redundant syntax --- run_project_tests.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/run_project_tests.py b/run_project_tests.py index 5445e0137..793c844e7 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -361,11 +361,10 @@ def _run_ci_include(args: T.List[str]) -> str: if not args: return 'At least one parameter required' try: - file_path = Path(args[0]) - data = file_path.open(errors='ignore', encoding='utf-8').read() + data = Path(args[0]).read_text(errors='ignore', encoding='utf-8') return 'Included file {}:\n{}\n'.format(args[0], data) except Exception: - return 'Failed to open {} ({})'.format(args[0]) + return 'Failed to open {}'.format(args[0]) ci_commands = { 'ci_include': _run_ci_include From c9d8d4628e4ae4409d09f255cc18517cdd5f1fbe Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sun, 12 Jul 2020 09:53:17 -0400 Subject: [PATCH 6/6] simplify/correct test logic before this, tests were being skipped on Ubuntu 20.04 with Anaconda Python Now, all 5 tests success --- test cases/python/2 extmodule/meson.build | 27 +++++++------- test cases/python/3 cython/meson.build | 7 ++-- .../meson.build | 35 ++++++++++--------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/test cases/python/2 extmodule/meson.build b/test cases/python/2 extmodule/meson.build index 54c50b4be..18d70c895 100644 --- a/test cases/python/2 extmodule/meson.build +++ b/test cases/python/2 extmodule/meson.build @@ -7,26 +7,29 @@ if meson.backend() != 'ninja' error('MESON_SKIP_TEST: Ninja backend required') endif + py_mod = import('python') py = py_mod.find_installation() -py_dep = py.dependency() +py_dep = py.dependency(required: false) -if py_dep.found() - subdir('ext') +if not py_dep.found() + error('MESON_SKIP_TEST: Python libraries not found.') +endif - test('extmod', - py, - args : files('blaster.py'), - env : ['PYTHONPATH=' + pypathdir]) +subdir('ext') - # Check we can apply a version constraint - dependency('python3', version: '>=@0@'.format(py_dep.version())) +test('extmod', + py, + args : files('blaster.py'), + env : ['PYTHONPATH=' + pypathdir]) -else - error('MESON_SKIP_TEST: Python3 libraries not found, skipping test.') -endif py3_pkg_dep = dependency('python3', method: 'pkg-config', required : false) if py3_pkg_dep.found() python_lib_dir = py3_pkg_dep.get_pkgconfig_variable('libdir') + + # Check we can apply a version constraint + dependency('python3', version: '>=@0@'.format(py_dep.version())) +else + message('Skipped python3 pkg-config test') endif diff --git a/test cases/python/3 cython/meson.build b/test cases/python/3 cython/meson.build index 18c05d4d5..5fc07a882 100644 --- a/test cases/python/3 cython/meson.build +++ b/test cases/python/3 cython/meson.build @@ -10,14 +10,13 @@ if not cython.found() error('MESON_SKIP_TEST: Cython3 not found.') endif -py3_dep = dependency('python3', required : false) +py_mod = import('python') +py3 = py_mod.find_installation() +py3_dep = py3.dependency(required: false) if not py3_dep.found() error('MESON_SKIP_TEST: Python library not found.') endif -py_mod = import('python') -py3 = py_mod.find_installation() -py3_dep = py3.dependency() subdir('libdir') test('cython tester', diff --git a/test cases/python/4 custom target depends extmodule/meson.build b/test cases/python/4 custom target depends extmodule/meson.build index ccccdafbe..d8a62ed25 100644 --- a/test cases/python/4 custom target depends extmodule/meson.build +++ b/test cases/python/4 custom target depends extmodule/meson.build @@ -12,6 +12,10 @@ py3 = py_mod.find_installation() py3_dep = py3.dependency(required : false) cc = meson.get_compiler('c') +if not py3_dep.found() + error('MESON_SKIP_TEST: Python3 libraries not found, skipping test.') +endif + # Copy to the builddir so that blaster.py can find the built tachyon module # FIXME: We should automatically detect this case and append the correct paths # to PYTHONLIBDIR @@ -24,21 +28,18 @@ import os, sys with open(sys.argv[1], 'rb') as f: assert(f.read() == b'success') ''' -if py3_dep.found() - message('Detected Python version: ' + py3_dep.version()) - if py3_dep.version().version_compare('>=3.8') and cc.get_id() == 'msvc' and cc.version().version_compare('<=19.00.24215.1') - error('MESON_SKIP_TEST: Python modules do not work with Python 3.8 and VS2015 or earlier.') - endif - subdir('ext') - - out_txt = custom_target('tachyon flux', - input : blaster_py, - output : 'out.txt', - command : [py3, '@INPUT@', '-o', '@OUTPUT@'], - depends : pylib, - build_by_default: true) - - test('flux', py3, args : ['-c', check_exists, out_txt]) -else - error('MESON_SKIP_TEST: Python3 libraries not found, skipping test.') + +message('Detected Python version: ' + py3_dep.version()) +if py3_dep.version().version_compare('>=3.8') and cc.get_id() == 'msvc' and cc.version().version_compare('<=19.00.24215.1') + error('MESON_SKIP_TEST: Python modules do not work with Python 3.8 and VS2015 or earlier.') endif +subdir('ext') + +out_txt = custom_target('tachyon flux', + input : blaster_py, + output : 'out.txt', + command : [py3, '@INPUT@', '-o', '@OUTPUT@'], + depends : pylib, + build_by_default: true) + +test('flux', py3, args : ['-c', check_exists, out_txt])