Skip to content

Commit

Permalink
run pre-commit on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Nov 29, 2024
1 parent 51a08b4 commit 88c687e
Show file tree
Hide file tree
Showing 1,150 changed files with 183,280 additions and 97,511 deletions.
96 changes: 53 additions & 43 deletions .ci/ctest2ci.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
***************************************************************************
Expand All @@ -18,51 +17,56 @@
***************************************************************************
"""

__author__ = 'Matthias Kuhn'
__date__ = 'March 2017'
__copyright__ = '(C) 2017, Matthias Kuhn'
__author__ = "Matthias Kuhn"
__date__ = "March 2017"
__copyright__ = "(C) 2017, Matthias Kuhn"

# This script parses output from ctest and injects
#
# - Colors for failing unit tests and test cases
# - Group control sequences to hide uninteresting output by default

import sys
import re
import string
import subprocess
import sys

from termcolor import colored
import string

fold_stack = list()
printable = set(string.printable)


def start_fold(tag):
sys.stdout.write('::group::{}\n'.format(tag))
sys.stdout.write(f"::group::{tag}\n")
fold_stack.append(tag)


def end_fold():
try:
tag = fold_stack.pop()
sys.stdout.write('::endgroup::\n')
sys.stdout.write("::endgroup::\n")
except IndexError:
updated_line = colored("======================", 'magenta')
updated_line += colored("ctest2ci error when processing the following line:", 'magenta')
updated_line += colored("----------------------", 'magenta')
updated_line += colored(updated_line, 'magenta')
updated_line += colored("----------------------", 'magenta')
updated_line += colored("Tried to end fold, but fold was never started.", 'magenta')
updated_line += colored("======================", 'magenta')
updated_line = colored("======================", "magenta")
updated_line += colored(
"ctest2ci error when processing the following line:", "magenta"
)
updated_line += colored("----------------------", "magenta")
updated_line += colored(updated_line, "magenta")
updated_line += colored("----------------------", "magenta")
updated_line += colored(
"Tried to end fold, but fold was never started.", "magenta"
)
updated_line += colored("======================", "magenta")


test_count = 0


def start_test_fold():
global test_count
sys.stdout.write('Running tests\n')
start_fold('test.{}'.format(test_count))
sys.stdout.write("Running tests\n")
start_fold(f"test.{test_count}")
test_count += 1


Expand All @@ -72,55 +76,61 @@ def start_test_fold():
p = subprocess.Popen(sys.argv[1:], stdout=subprocess.PIPE)

for line in p.stdout:
updated_line = line.decode('utf-8')
updated_line = line.decode("utf-8")
# remove non printable characters https://stackoverflow.com/a/8689826/1548052
filter(lambda x: x in printable, updated_line)
if re.match('Run dashboard with model Experimental', updated_line):
start_fold('Run tests')
updated_line = '{title}\n{line}'.format(title=colored('Running tests...', 'yellow', attrs=['bold']),
line=updated_line)

elif re.match('Test project /home/runner/QGIS/QGIS/build', updated_line):
if re.match("Run dashboard with model Experimental", updated_line):
start_fold("Run tests")
updated_line = "{title}\n{line}".format(
title=colored("Running tests...", "yellow", attrs=["bold"]),
line=updated_line,
)

elif re.match("Test project /home/runner/QGIS/QGIS/build", updated_line):
end_fold() # tag=Run tests
start_test_fold()

if re.search(r'\*\*\*Failed', updated_line) or re.search(r'\*\*\*Timeout', updated_line):
if re.search(r"\*\*\*Failed", updated_line) or re.search(
r"\*\*\*Timeout", updated_line
):
end_fold()
updated_line = colored(updated_line, 'red')
updated_line = colored(updated_line, "red")
in_failing_test = True

if in_failing_test:
if re.match(' Start', updated_line):
if re.match(" Start", updated_line):
start_test_fold()
in_failing_test = False
elif in_failure:
if re.match('PASS', updated_line) or re.match('Ran', updated_line):
if re.match("PASS", updated_line) or re.match("Ran", updated_line):
in_failure = False
else:
updated_line = colored(updated_line, 'yellow')
elif re.search(r'\*\*\* Segmentation fault', updated_line):
start_fold('segfault')
updated_line = colored(updated_line, 'magenta')
elif re.match(' Test failed: Segmentation fault', updated_line):
updated_line = colored(updated_line, "yellow")
elif re.search(r"\*\*\* Segmentation fault", updated_line):
start_fold("segfault")
updated_line = colored(updated_line, "magenta")
elif re.match(" Test failed: Segmentation fault", updated_line):
end_fold()

else:
if re.match(r'(FAIL|ERROR)[:\!].*', updated_line):
updated_line = colored(updated_line, 'yellow')
if re.match(r"(FAIL|ERROR)[:\!].*", updated_line):
updated_line = colored(updated_line, "yellow")
in_failure = True

if not in_failing_test and re.search('[0-9]+% tests passed, [0-9]+ tests failed out of', updated_line):
tests_failing = re.match(r'.* ([0-9]+) tests failed', updated_line).group(1)
if not in_failing_test and re.search(
"[0-9]+% tests passed, [0-9]+ tests failed out of", updated_line
):
tests_failing = re.match(r".* ([0-9]+) tests failed", updated_line).group(1)
# updated_line += '\n::set-output name=TESTS_FAILING::{}'.format(tests_failing)
end_fold()

if re.search('100% tests passed', updated_line):
updated_line = colored(updated_line, 'green')
if re.search("100% tests passed", updated_line):
updated_line = colored(updated_line, "green")

if re.match('Submit files', updated_line):
start_fold('submit')
elif re.search('Test results submitted to', updated_line):
cdash_url = re.match(r'.*(http.*)$', updated_line).group(1)
if re.match("Submit files", updated_line):
start_fold("submit")
elif re.search("Test results submitted to", updated_line):
cdash_url = re.match(r".*(http.*)$", updated_line).group(1)
# updated_line += '\n::set-output name=CDASH_URL::{}'.format(cdash_url)
end_fold()

Expand Down
29 changes: 16 additions & 13 deletions .ci/pr_has_label.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
#!/usr/bin/env python3

import sys
import argparse
import json
from urllib.request import urlopen # using urllib since it is a standard module (vs. requests)
import sys

from urllib.error import URLError
import argparse
from urllib.request import ( # using urllib since it is a standard module (vs. requests)
urlopen,
)

parser = argparse.ArgumentParser(description='Determines if a pull request has a defined label')
parser.add_argument('pull_request', type=str,
help='pull request id')
parser.add_argument('label', type=int,
help='label ID')
parser = argparse.ArgumentParser(
description="Determines if a pull request has a defined label"
)
parser.add_argument("pull_request", type=str, help="pull request id")
parser.add_argument("label", type=int, help="label ID")

args = parser.parse_args()

if args.pull_request == 'false':
if args.pull_request == "false":
print("false")
sys.exit(1)

url = "https://api.github.com/repos/qgis/QGIS/pulls/{}".format(args.pull_request)
url = f"https://api.github.com/repos/qgis/QGIS/pulls/{args.pull_request}"

try:
data = urlopen(url).read().decode('utf-8')
data = urlopen(url).read().decode("utf-8")
except URLError as err:
print("URLError: {}".format(err.reason))
print(f"URLError: {err.reason}")
sys.exit(1)

obj = json.loads(data)

for label in obj['labels']:
for label in obj["labels"]:
if label["id"] == args.label:
print("true")
sys.exit(0)
Expand Down
10 changes: 6 additions & 4 deletions .docker/qgis_resources/test_runner/qgis_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
~/.qgis3/python/startup.py
"""
from qgis.core import Qgis
from qgis import utils

import traceback

from qgis import utils
from qgis.core import Qgis


def _showException(type, value, tb, msg, messagebar=False, level=Qgis.Warning):
print(msg)
logmessage = ''
logmessage = ""
for s in traceback.format_exception(type, value, tb):
logmessage += s.decode('utf-8', 'replace') if hasattr(s, 'decode') else s
logmessage += s.decode("utf-8", "replace") if hasattr(s, "decode") else s
print(logmessage)


Expand Down
61 changes: 36 additions & 25 deletions .docker/qgis_resources/test_runner/qgis_testrunner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
***************************************************************************
Expand Down Expand Up @@ -42,18 +41,19 @@
***************************************************************************
"""

__author__ = 'Alessandro Pasotti'
__date__ = 'May 2016'
__author__ = "Alessandro Pasotti"
__date__ = "May 2016"

import importlib
import os
import re
import signal
import sys
import traceback
import signal
import importlib
from pexpect import run
from pipes import quote

from shlex import quote

from pexpect import run
from qgis.utils import iface


Expand All @@ -68,14 +68,17 @@ def __get_test_function(test_module_name):
print("QGIS Test Runner - Trying to import %s" % test_module_name)
try:
test_module = importlib.import_module(test_module_name)
function_name = 'run_all'
function_name = "run_all"
except ImportError as e:
# traceback.print_exc(file=sys.stdout)
# Strip latest name
pos = test_module_name.rfind('.')
pos = test_module_name.rfind(".")
if pos <= 0:
raise e
test_module_name, function_name = test_module_name[:pos], test_module_name[pos + 1:]
test_module_name, function_name = (
test_module_name[:pos],
test_module_name[pos + 1 :],
)
print("QGIS Test Runner - Trying to import %s" % test_module_name)
sys.stdout.flush()
try:
Expand All @@ -93,47 +96,55 @@ def __get_test_function(test_module_name):
sys.path.append(os.getcwd())
test_module_name = sys.argv[-1]
if __get_test_function(test_module_name) is None:
print("QGIS Test Runner - [ERROR] cannot load test function from %s" % test_module_name)
print(
"QGIS Test Runner - [ERROR] cannot load test function from %s"
% test_module_name
)
sys.exit(1)
try:
me = __file__
except NameError:
me = sys.argv[0]
os.environ['QGIS_DEBUG'] = '1'
os.environ["QGIS_DEBUG"] = "1"
args = [
'qgis',
os.environ.get('QGIS_EXTRA_OPTIONS', ''),
'--nologo',
'--noversioncheck',
'--code',
"qgis",
os.environ.get("QGIS_EXTRA_OPTIONS", ""),
"--nologo",
"--noversioncheck",
"--code",
me,
test_module_name, # Must be the last one!
]
command_line = ' '.join(args)
command_line = " ".join(args)
print("QGIS Test Runner - launching QGIS as %s ..." % command_line)
out, returncode = run("sh -c " + quote(command_line), withexitstatus=1)
if isinstance(out, bytes):
out = out.decode("utf-8")
assert returncode is not None
print("QGIS Test Runner - QGIS exited.")
ok = out.find('(failures=') < 0 and \
len(re.findall(r'Ran \d+ tests in\s',
out, re.MULTILINE)) > 0
print('=' * 60)
ok = (
out.find("(failures=") < 0
and len(re.findall(r"Ran \d+ tests in\s", out, re.MULTILINE)) > 0
)
print("=" * 60)
if not ok:
print(out)
else:
eprint(out)
if len(out) == 0:
print("QGIS Test Runner - [WARNING] subprocess returned no output")
print('=' * 60)
print("=" * 60)

print("QGIS Test Runner - %s bytes returned and finished with exit code: %s" % (len(out), 0 if ok else 1))
print(
"QGIS Test Runner - {} bytes returned and finished with exit code: {}".format(
len(out), 0 if ok else 1
)
)
sys.exit(0 if ok else 1)

else: # We are inside QGIS!
# Start as soon as the initializationCompleted signal is fired
from qgis.core import QgsApplication, QgsProjectBadLayerHandler, QgsProject
from qgis.core import QgsApplication, QgsProject, QgsProjectBadLayerHandler
from qgis.PyQt.QtCore import QDir
from qgis.utils import iface

Expand Down
2 changes: 1 addition & 1 deletion .github/actions/vcpkg_update_report/vcpkg-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def read_file(file_path):
"""
Read the content of a file.
"""
with open(file_path, "r") as file:
with open(file_path) as file:
return file.read()


Expand Down
Loading

0 comments on commit 88c687e

Please sign in to comment.