Skip to content

Commit fea201f

Browse files
committed
fix linting
1 parent 57e7600 commit fea201f

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

tasks/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from invoke import Collection, Context, task # type: ignore
1+
from invoke import Collection, Context, task # type: ignore
22

33
from . import docusaurus, linter, schemas
44

@@ -18,6 +18,7 @@ def lint_all(context: Context) -> None:
1818
def format(context: Context) -> None:
1919
linter.format(context)
2020

21+
2122
# @task(name="docusaurus")
2223
# def docusaurus(context: Context) -> None:
2324
# docusaurus.docusaurus(context)

tasks/docusaurus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from pathlib import Path
3-
from invoke import Context, task # type: ignore
3+
from invoke import Context, task # type: ignore
44

55
CURRENT_DIRECTORY = Path(__file__).parent.resolve()
66
DOCUMENTATION_DIRECTORY = CURRENT_DIRECTORY.parent / "docs"

tasks/linter.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
2-
import yaml # type: ignore
2+
import yaml # type: ignore
33
from collections import OrderedDict
4-
from invoke import Context, task # type: ignore
4+
from invoke import Context, task # type: ignore
55

66
CURRENT_DIRECTORY = Path(__file__).resolve()
77
DOCUMENTATION_DIRECTORY = CURRENT_DIRECTORY.parent / "docs"
@@ -27,6 +27,7 @@ def lint_yaml(context: Context) -> None:
2727
with context.cd(MAIN_DIRECTORY_PATH):
2828
context.run(exec_cmd)
2929

30+
3031
@task
3132
def lint_mypy(context: Context) -> None:
3233
"""Run Linter to check all Python files."""
@@ -53,6 +54,7 @@ def lint_all(context: Context) -> None:
5354
lint_ruff(context)
5455
# lint_mypy(context)
5556

57+
5658
def sort_dict(d):
5759
"""
5860
Recursively sort a dictionary by keys.
@@ -63,6 +65,7 @@ def sort_dict(d):
6365
return [sort_dict(item) for item in d]
6466
return d
6567

68+
6669
class PreserveLiteralStyleDumper(yaml.SafeDumper):
6770
"""
6871
Custom Dumper to preserve the literal style for multiline strings.
@@ -76,6 +79,7 @@ def represent_scalar(self, tag, value, style=None):
7679
style = "|"
7780
return super().represent_scalar(tag, value, style=style)
7881

82+
7983
@task(name="sort-metadata")
8084
def sort_metadata(context: Context) -> None:
8185
print(f" - Sort {METADATA_FILE}")
@@ -84,4 +88,11 @@ def sort_metadata(context: Context) -> None:
8488

8589
with open(METADATA_FILE, "w", encoding="utf-8") as f:
8690
f.write("---\n")
87-
yaml.dump(metadata, f, Dumper=PreserveLiteralStyleDumper, default_flow_style=False, sort_keys=True, allow_unicode=True)
91+
yaml.dump(
92+
metadata,
93+
f,
94+
Dumper=PreserveLiteralStyleDumper,
95+
default_flow_style=False,
96+
sort_keys=True,
97+
allow_unicode=True,
98+
)

tasks/schemas.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
from pathlib import Path
3-
import yaml # type: ignore
3+
import yaml # type: ignore
44
from invoke import Context, task # type: ignore
55

66
# If no version is indicated, we will take the latest
@@ -13,6 +13,7 @@
1313

1414
METADATA_FILE = CURRENT_DIRECTORY.parent / ".metadata.yml"
1515

16+
1617
def _parse_and_load_extensions(
1718
context: Context, extensions_path: Path, allowed_to_fail: bool
1819
) -> None:
@@ -85,10 +86,10 @@ def generate_readme(schema, extension_dir: Path) -> list:
8586
# f"{schema.get('description', '')}\n",
8687
# ]
8788

88-
description = schema.get('description', '')
89+
description = schema.get("description", "")
8990
content = [
9091
f"# {schema.get('name', '')}\n",
91-
f"{description}\n" if not description.endswith('\n') else description
92+
f"{description}\n" if not description.endswith("\n") else description,
9293
]
9394

9495
if dependencies := schema.get("dependencies", []):
@@ -99,12 +100,28 @@ def generate_readme(schema, extension_dir: Path) -> list:
99100

100101
def format_table(headers: list, rows: list):
101102
"""Generate a Markdown table."""
103+
102104
def escape_markdown(text: str) -> str:
103105
# Escape special markdown characters
104-
special_chars = ['|', '_', '*', '`', '[', ']', '(', ')', '#', '+', '-', '.', '!', '$']
106+
special_chars = [
107+
"|",
108+
"_",
109+
"*",
110+
"`",
111+
"[",
112+
"]",
113+
"(",
114+
")",
115+
"#",
116+
"+",
117+
"-",
118+
".",
119+
"!",
120+
"$",
121+
]
105122

106123
for char in special_chars:
107-
text = text.replace(char, f'\\{char}')
124+
text = text.replace(char, f"\\{char}")
108125
return text
109126

110127
table = f"\n| {' | '.join(headers)} |\n"
@@ -155,10 +172,10 @@ def generate_node_data(node: dict):
155172
if node.get("order_by") or node.get("uniqueness_constraints"):
156173
node_markdown.append("#### Ordering and Constraints\n")
157174
node_markdown.append(
158-
f"- **Order By:**{', ' .join(node.get('order_by', []))}"
175+
f"- **Order By:**{', '.join(node.get('order_by', []))}"
159176
)
160177
node_markdown.append(
161-
f"- **Uniqueness Constraints:**{', ' .join([' + '.join(c) for c in node.get('uniqueness_constraints', [])])}\n"
178+
f"- **Uniqueness Constraints:**{', '.join([' + '.join(c) for c in node.get('uniqueness_constraints', [])])}\n"
162179
)
163180
# node_markdown.append("\n")
164181

@@ -224,7 +241,9 @@ def build(context: Context) -> None:
224241
consolidated_doc = schema_docs_dir / "schema-library.mdx"
225242

226243
all_content = []
227-
all_content.append("---\ntitle: Schema Library Documentation\n---\n<!-- markdownlint-disable-file MD025 -->\n")
244+
all_content.append(
245+
"---\ntitle: Schema Library Documentation\n---\n<!-- markdownlint-disable-file MD025 -->\n"
246+
)
228247

229248
with open(METADATA_FILE, "r", encoding="utf-8") as f:
230249
schema = yaml.safe_load(f)
@@ -261,4 +280,3 @@ def build(context: Context) -> None:
261280
# generate_readme(schema[str(path)], path)
262281
# except KeyError:
263282
# print(f"Schema `{path}` is not added to the {METADATA_FILE} file")
264-

0 commit comments

Comments
 (0)