aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--[-rwxr-xr-x]project/ctest_driver.py (renamed from tools/ctest-driver.py)76
-rw-r--r--project/format.py1
-rw-r--r--pyproject.toml6
3 files changed, 29 insertions, 54 deletions
diff --git a/tools/ctest-driver.py b/project/ctest_driver.py
index a2151c5..5484d51 100755..100644
--- a/tools/ctest-driver.py
+++ b/project/ctest_driver.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2021 Egor Tensin <egor@tensin.name>
# This file is part of the "cmake-common" project.
# For details, see https://github.com/egor-tensin/cmake-common
@@ -17,20 +15,12 @@ This script tries to fix them.
"""
import argparse
-import os
+import logging
import re
import subprocess
import sys
-SCRIPT_NAME = os.path.basename(__file__)
-
-
-def dump(msg, **kwargs):
- print(f"{SCRIPT_NAME}: {msg}", **kwargs)
-
-
-def err(msg):
- dump(msg, file=sys.stderr)
+from project import utils
def read_file(path):
@@ -38,40 +28,28 @@ def read_file(path):
return fd.read()
-def run(cmd_line, exit_codes=[0]):
+def _run_exit_if_invalid_code(actual, expected):
+ if actual in expected:
+ return
+ logging.error(
+ "Actual exit code %d is not among the allowed codes %s", actual, str(expected)
+ )
+ sys.exit(actual)
+
+
+def run(cmd_line, exit_codes=(0,)):
try:
- result = subprocess.run(
- cmd_line,
- check=True,
- universal_newlines=True,
- stderr=subprocess.STDOUT,
- stdout=subprocess.PIPE,
- )
- assert result.returncode == 0
- return result.stdout
+ return utils.run_capture(cmd_line)
except subprocess.CalledProcessError as e:
- if e.returncode not in exit_codes:
- err(
- f"Actual exit code {e.returncode} is not among the allowed codes {exit_codes}"
- )
- sys.stdout.write(e.output)
- sys.exit(e.returncode)
- return e.output
+ _run_exit_if_invalid_code(e.returncode, exit_codes)
+ return e.stdout
-def run_new_window(cmd_line, exit_codes=[0]):
+def run_new_window(cmd_line, exit_codes=(0,)):
try:
- result = subprocess.run(
- cmd_line, check=True, creationflags=subprocess.CREATE_NEW_CONSOLE
- )
- assert result.returncode == 0
+ utils.run(cmd_line, creationflags=subprocess.CREATE_NEW_CONSOLE)
except subprocess.CalledProcessError as e:
- if e.returncode not in exit_codes:
- err(
- f"Actual exit code {e.returncode} is not among the allowed codes {exit_codes}"
- )
- sys.exit(e.returncode)
- return None
+ _run_exit_if_invalid_code(e.returncode, exit_codes)
def match(s, regex):
@@ -90,12 +68,11 @@ def match_pass_regexes(output, regexes):
if not regexes:
return
if not match_all(output, regexes):
- err(
- "Couldn't match test program's output against all of the"
- " regular expressions:"
+ logging.error(
+ "Couldn't match test program's output against all of the regular expressions:"
)
for regex in regexes:
- err(f"\t{regex}")
+ logging.error(" %s", regex)
sys.exit(1)
@@ -103,9 +80,11 @@ def match_fail_regexes(output, regexes):
if not regexes:
return
if match_any(output, regexes):
- err("Matched test program's output against some of the regular" " expressions:")
+ logging.error(
+ "Matched test program's output against some of the regular expressions:"
+ )
for regex in regexes:
- err(f"\t{regex}")
+ logging.error(" %s", regex)
sys.exit(1)
@@ -116,9 +95,10 @@ def run_actual_test_driver(args):
run_func = run_new_window
output = run_func(cmd_line, args.exit_codes)
if args.new_window and (args.pass_regexes or args.fail_regexes):
- err("Cannot launch child process in a new window and capture its output")
+ logging.error(
+ "Cannot launch child process in a new window and capture its output"
+ )
if output is not None:
- sys.stdout.write(output)
match_pass_regexes(output, args.pass_regexes)
match_fail_regexes(output, args.fail_regexes)
diff --git a/project/format.py b/project/format.py
index 5f24062..e1897db 100644
--- a/project/format.py
+++ b/project/format.py
@@ -12,7 +12,6 @@ formatting the files in-place.
import argparse
import difflib
-import logging
import os
import sys
diff --git a/pyproject.toml b/pyproject.toml
index 7fd21f8..b68ca10 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -31,10 +31,6 @@ boost-build = "project.boost.build:_main"
boost-download = "project.boost.download:_main"
project-build = "project.build:main"
project-format = "project.format:main"
-
-[tool.setuptools]
-script-files = [
- "tools/ctest-driver.py",
-]
+project-ctest-driver = "project.ctest_driver:main"
[tool.setuptools_scm]