aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-03-28 23:48:46 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-03-29 01:26:18 -0400
commit80192aa577578a094c7da2c3696edbfbd38052cf (patch)
treef3aa638c8f82f26132a133a221fea7869f82399c
parent823da3990947a8f4a2152826f0d7229f8a7a0159 (diff)
downloadmeson-80192aa577578a094c7da2c3696edbfbd38052cf.zip
meson-80192aa577578a094c7da2c3696edbfbd38052cf.tar.gz
meson-80192aa577578a094c7da2c3696edbfbd38052cf.tar.bz2
runpython: support --version
argparse is the gift that keeps on giving, hahaha. Suppress the script argument when --version is specified to avoid "required argument not provided" errors, and print the python version. The version argument is required in order to make this baseline functional as a resolved python for find_program, which may specify a version and expect this to work with python itself. Our incomplete CLI wrapper over the python CLI interface was missing this. Fixes #10162
-rw-r--r--mesonbuild/mesonmain.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
index 89816ec..04ea8f5 100644
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -18,6 +18,7 @@ import sys
sys.modules['pathlib'] = _pathlib
import os.path
+import platform
import importlib
import traceback
import argparse
@@ -93,15 +94,18 @@ class CommandLineParser:
for i in [name] + aliases:
self.commands[i] = p
- def add_runpython_arguments(self, parser):
+ def add_runpython_arguments(self, parser: argparse.ArgumentParser):
parser.add_argument('-c', action='store_true', dest='eval_arg', default=False)
- parser.add_argument('script_file')
+ parser.add_argument('--version', action='store_true')
+ parser.add_argument('script_file', nargs='?')
parser.add_argument('script_args', nargs=argparse.REMAINDER)
def run_runpython_command(self, options):
import runpy
if options.eval_arg:
exec(options.script_file)
+ elif options.version:
+ print(platform.python_version())
else:
sys.argv[1:] = options.script_args
sys.path.insert(0, os.path.dirname(options.script_file))