Skip to content

Commit

Permalink
Merge remote-tracking branch 'template/main' into upstream-template
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumWalley committed Sep 25, 2024
2 parents 8bca5ee + 14090d8 commit a392061
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"column": 4,
"endLine": 5,
"message": 7,
"loop": true
},
"owner": "proselint",
"fileLocation": "autoDetect",
Expand Down Expand Up @@ -94,7 +95,7 @@
"column": 4,
"endColumn": 5,
"line": 6,
"message": 7
"message": 7,
},
"owner": "test-build",
"fileLocation": [
Expand Down
42 changes: 23 additions & 19 deletions checks/run_meta_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def main():
_nav_check()
with open(input_path, "r") as f:
print(f"Checking meta for {f.name}")
try:
if 1:
contents = f.read()
match = re.match(r"---\n([\s\S]*?)---", contents, re.MULTILINE)
if not match:
Expand Down Expand Up @@ -93,13 +93,15 @@ def main():
_run_check(check)
for check in ENDCHECKS:
_run_check(check)
except Exception as e:
print(f"::error file={input_path},title=misc,col=0,endColumn=0,line=1 ::{e}")
# except Exception as e:
# print(f"::error file={input_path},title=misc,col=0,endColumn=0,line=1 ::{e}")

def _run_check(f):
for r in f():
print(f"::{r.get('level', 'warning')} file={input_path},title={f.__name__},col={r.get('col', 0)},endColumn={r.get('endColumn', 99)},line={r.get('line', 1)}::{r.get('message', 'something wrong')}")
sys.stdout.flush()
time.sleep(0.01)



def _title_from_filename():
Expand Down Expand Up @@ -136,26 +138,29 @@ def _unpack(toc, a):
return toc[a[0]]
return _unpack(toc[a[0]]["children"], a[1:])

if in_code_block:
return
try:
if in_code_block:
return

header_match = re.match(r"^(#+)\s*(.*)$", line)
header_match = re.match(r"^(#+)\s*(.*)$", line)

if not header_match:
return

header_level = len(header_match.group(1))
header_name = header_match.group(2)
if not header_match:
return
header_level = len(header_match.group(1))
header_name = header_match.group(2)

if header_level == 1:
toc = {header_name: {"lineno": lineno, "children": {}}}
toc_parents = [header_name]
if header_level == 1:
toc = {header_name: {"lineno": lineno, "children": {}}}
toc_parents = [header_name]

while header_level < len(toc_parents)+1:
toc_parents.pop(-1)
while header_level < len(toc_parents)+1:
toc_parents.pop(-1)

_unpack(toc, toc_parents)["children"][header_name] = {"level": header_level, "lineno": lineno, "children": {}}
toc_parents += [header_name]
_unpack(toc, toc_parents)["children"][header_name] = {"level": header_level, "lineno": lineno, "children": {}}
toc_parents += [header_name]
except Exception:
print(f"::error file={input_path},title=misc-nav,col=0,endColumn=0,line=1 ::Failed to parse Nav tree. Something is wrong.")


def _nav_check():
Expand Down Expand Up @@ -268,4 +273,3 @@ def _count_children(d):

# FIXME terrible hack to make VSCode in codespace capture the error messages
# see https://github.com/microsoft/vscode/issues/92868 as a tentative explanation
time.sleep(5)
4 changes: 3 additions & 1 deletion checks/run_proselint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import sys
from pathlib import Path
import time

import proselint
from proselint import config, tools
Expand All @@ -22,10 +23,11 @@
for file in files:
print(f"Running proselint on {file}")
content = Path(file).read_text(encoding="utf8")
fails = proselint.tools.lint(content, config=config_custom)
for notice in proselint.tools.lint(content, config=config_custom):
print(
f"::{notice[7]} file={file},line={notice[2]+1},"
f"col={notice[3]+2},endColumn={notice[2]+notice[6]+1},"
f"title={notice[0]}::'{notice[1]}'",
flush=True,
)
time.sleep(0.01)
13 changes: 12 additions & 1 deletion checks/run_test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import logging
import sys
import re
import time


"""
This doesnt work and I have no idea why.
This works but is a bit messy
"""


def parse_macro(record):

# These are not useful messages
Expand All @@ -29,6 +32,13 @@ def parse_macro(record):
record.name = g["title"]
record.filename = g["file"]
record.msg = g["message"]

# Does not give correct path to file in question in 'title'.
# Infer from message.
m = re.search(r"'(.*?\.md)'", record.msg)
if m:
record.filename = m.group(1)

return True


Expand All @@ -42,3 +52,4 @@ def parse_macro(record):
log.addHandler(sh)
config = load_config(config_file_path="./mkdocs.yml")
build.build(config)
time.sleep(5)
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ pygments==2.18.0
pyjwt[crypto]==2.9.0
# via pygithub
pymdown-extensions==10.9
# via
# -r requirements.in
# mkdocs-material
# via mkdocs-material
pynacl==1.5.0
# via pygithub
pyproject-hooks==1.1.0
Expand Down

0 comments on commit a392061

Please sign in to comment.