Skip to content

Commit f02eeb3

Browse files
bruchar1eli-schwartz
authored andcommitted
Replace deprecated setup.py install command
In `run_meson_command_tests.py`. Replace it with `pip install .` if `pip` is available. Replace it with 'gpep517 install-from-source` if available. Else keep the old behaviour. Fixes mesonbuild#14522. (cherry picked from commit b4d3276)
1 parent 90c1a71 commit f02eeb3

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

run_meson_command_tests.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4954
class 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

Comments
 (0)