From 5604406fa44e2ed40450ee812ee3145ae3765cda Mon Sep 17 00:00:00 2001 From: Lukas Krupcik <lukas.krupcik@vsb.cz> Date: Tue, 10 Sep 2024 08:10:07 +0200 Subject: [PATCH] modified: .gitlab-ci.yml modified: .spelling modified: scripts/titlemd.py --- .gitlab-ci.yml | 2 ++ .spelling | 2 +- scripts/titlemd.py | 40 ++++++++++++++-------------------------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 65498def7..855a29c9e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,9 +34,11 @@ pysafety: capitalize: stage: test image: it4innovations/docker-mkdocscheck:latest + allow_failure: true before_script: - source /opt/.venv3/bin/activate - python -V # debug + - pip list | grep titlecase script: - find mkdocs.yml docs.it4i/ \( -name '*.md' -o -name '*.yml' \) -print0 | xargs -0 -n1 scripts/titlemd.py --test diff --git a/.spelling b/.spelling index 5448dbdfb..d1add769e 100644 --- a/.spelling +++ b/.spelling @@ -835,4 +835,4 @@ it4ifree it4ifsusage it4iuserfsusage it4iprojectfsusage -it4imotd \ No newline at end of file +it4imotd diff --git a/scripts/titlemd.py b/scripts/titlemd.py index 73520c6b4..5e2c07394 100755 --- a/scripts/titlemd.py +++ b/scripts/titlemd.py @@ -1,9 +1,7 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ titlemd """ -from __future__ import print_function - import argparse import sys @@ -30,16 +28,14 @@ def arg_parse(): def mkdocs_available(location): """ Is mkdocs.yml available? """ - if location.find("mkdocs.yml") != -1: - return True - return False + return "mkdocs.yml" in location def linestart(line, disabled, test, prev_line=None): """ linestart """ if test: if (line.startswith("``") or line.startswith("extra:")) and not disabled: return True - if (line.startswith("``") or prev_line.startswith("pages:")) and disabled: + if (line.startswith("``") or (prev_line and prev_line.startswith("pages:"))) and disabled: return False else: if line.startswith("``") and not disabled: @@ -54,7 +50,6 @@ def testdata(arg): with open('.spelling') as fdata: spelling = fdata.readlines() - # pylint: disable=unused-argument,inconsistent-return-statements def abbreviations(word, **kwargs): """ abbreviations """ if word+"\n" in spelling: @@ -67,7 +62,7 @@ def testdata(arg): # Loop through the list of lines and titlecase # any line beginning with '#'. return_value = 0 - prev_line = lines[0] + prev_line = lines[0] if lines else "" echo_filename = False disabled = mkdocs_available(arg.location) for line in lines: @@ -76,34 +71,30 @@ def testdata(arg): if line != titlecase(line[:(line.find("]"))], callback=abbreviations)+line[(line.find("]")):]: if return_value == 0 and not echo_filename: - print("%s" % arg.location) + print(f"{arg.location}") echo_filename = True - print("-"+line, end="") - print("+"+titlecase(line[:(line.find("]"))], - callback=abbreviations)+line[(line.find("]")):], end="") + print(f"-{line}", end="") + print(f"+{titlecase(line[:(line.find(']'))], callback=abbreviations)}{line[(line.find(']')):]}", end="") print() return_value = 1 if (line.startswith('---') or line.startswith('===')) and not disabled: if prev_line != titlecase(prev_line[:(prev_line.find("]"))], callback=abbreviations)+prev_line[(prev_line.find("]")):]: if return_value == 0 and not echo_filename: - print("%s" % arg.location) + print(f"{arg.location}") echo_filename = True - print("-"+prev_line, end="") - print("+"+titlecase(prev_line[:(prev_line.find("]"))], - callback=abbreviations)+prev_line[(prev_line.find("]")):], - end="") + print(f"-{prev_line}", end="") + print(f"+{titlecase(prev_line[:(prev_line.find(']'))], callback=abbreviations)}{prev_line[(prev_line.find(']')):]}", end="") print() return_value = 1 if (mkdocs_available(arg.location) and not line.startswith('#') and not disabled): if line != titlecase(line[:(line.find(":"))], callback=abbreviations)+line[(line.find(":")):]: if return_value == 0 and not echo_filename: - print("%s" % arg.location) + print(f"{arg.location}") echo_filename = True - print("-"+line, end="") - print("+"+titlecase(line[:(line.find(":"))], - callback=abbreviations)+line[(line.find(":")):], end="") + print(f"-{line}", end="") + print(f"+{titlecase(line[:(line.find(':'))], callback=abbreviations)}{line[(line.find(':')):]}", end="") print() return_value = 1 prev_line = line @@ -115,7 +106,6 @@ def writedata(arg): with open('.spelling') as fdata: spelling = fdata.readlines() - # pylint: disable=unused-argument,inconsistent-return-statements def abbreviations(word, **kwargs): """ abbreviations """ if word+"\n" in spelling: @@ -126,9 +116,7 @@ def writedata(arg): lines = fdata.readlines() with open(arg.location, 'w') as fdata: - # Loop through the list of lines and titlecase - # any line beginning with '#'. - prev_line = lines[0] + prev_line = lines[0] if lines else "" disabled = False for line in lines: disabled = linestart(line, disabled, arg.test) -- GitLab