@@ -46,6 +46,11 @@ def get_pybindir():
4646 return sysconfig .get_path ('scripts' , scheme = scheme , vars = {'base' : '' }).strip ('\\ /' )
4747 return sysconfig .get_path ('scripts' , vars = {'base' : '' }).strip ('\\ /' )
4848
49+ def has_python_module (module : str ) -> bool :
50+ result = subprocess .run (python_command + ['-c' , f'import { module } ' ])
51+ return result .returncode == 0
52+
53+
4954class CommandTests (unittest .TestCase ):
5055 '''
5156 Test that running meson in various ways works as expected by checking the
@@ -141,11 +146,17 @@ def test_meson_installed(self):
141146 # distutils complains that prefix isn't contained in PYTHONPATH
142147 os .environ ['PYTHONPATH' ] = os .path .join (str (pylibdir ), '' )
143148 os .environ ['PATH' ] = str (bindir ) + os .pathsep + os .environ ['PATH' ]
144- self ._run (python_command + ['setup.py' , 'install' , '--prefix' , str (prefix )])
145- # Fix importlib-metadata by appending all dirs in pylibdir
146- PYTHONPATHS = [pylibdir ] + [x for x in pylibdir .iterdir () if x .name .endswith ('.egg' )]
147- PYTHONPATHS = [os .path .join (str (x ), '' ) for x in PYTHONPATHS ]
148- os .environ ['PYTHONPATH' ] = os .pathsep .join (PYTHONPATHS )
149+ if has_python_module ('gpep517' ):
150+ self ._run (python_command + ['-m' , 'gpep517' , 'install-from-source' , '--destdir' , '/' , '--prefix' , str (prefix )])
151+ elif has_python_module ('pip' ):
152+ self ._run (python_command + ['-m' , 'pip' , 'install' , '--prefix' , str (prefix ), '.' ])
153+ else :
154+ # Legacy deprecated setuptools command used as fallback
155+ self ._run (python_command + ['setup.py' , 'install' , '--prefix' , str (prefix )])
156+ # Fix importlib-metadata by appending all dirs in pylibdir
157+ PYTHONPATHS = [pylibdir ] + [x for x in pylibdir .iterdir () if x .name .endswith ('.egg' )]
158+ PYTHONPATHS = [os .path .join (str (x ), '' ) for x in PYTHONPATHS ]
159+ os .environ ['PYTHONPATH' ] = os .pathsep .join (PYTHONPATHS )
149160 # Check that all the files were installed correctly
150161 self .assertTrue (bindir .is_dir ())
151162 self .assertTrue (pylibdir .is_dir ())
0 commit comments