Skip to content

Commit 298fd25

Browse files
committed
Formatted with black
Signed-off-by: Ole Herman Schumacher Elgesem <[email protected]>
1 parent a7ec5ca commit 298fd25

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/cfengine_cli/docs.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ def fn_extract(origin_path, snippet_path, _language, first_line, last_line):
110110
raise UserError(f"Couldn't open '{origin_path}' or '{snippet_path}'")
111111

112112

113-
def fn_check_syntax(origin_path, snippet_path, language, first_line, _last_line, snippet_number):
113+
def fn_check_syntax(
114+
origin_path, snippet_path, language, first_line, _last_line, snippet_number
115+
):
114116
snippet_abs_path = os.path.abspath(snippet_path)
115117

116118
if not os.path.exists(snippet_path):
@@ -120,7 +122,9 @@ def fn_check_syntax(origin_path, snippet_path, language, first_line, _last_line,
120122

121123
match language:
122124
case "cf":
123-
r = lint_policy_file(snippet_abs_path, origin_path, first_line + 1, snippet_number)
125+
r = lint_policy_file(
126+
snippet_abs_path, origin_path, first_line + 1, snippet_number
127+
)
124128
if r != 0:
125129
raise UserError(f"Error when checking '{origin_path}'")
126130
case "json":
@@ -183,6 +187,7 @@ def fn_autoformat(_origin_path, snippet_path, language, _first_line, _last_line)
183187
except json.decoder.JSONDecodeError:
184188
raise UserError(f"Invalid json in '{snippet_path}'")
185189

190+
186191
def _translate_language(x):
187192
if x == "cf3" or x == "cfengine3":
188193
return "cf"
@@ -193,6 +198,7 @@ def _translate_language(x):
193198

194199
SUPPORTED_LANGUAGES = ["cf", "cfengine3", "cf3", "json", "yml", "yaml"]
195200

201+
196202
def _process_markdown_code_blocks(
197203
path, languages, extract, syntax_check, output_check, autoformat, replace, cleanup
198204
):
@@ -282,6 +288,7 @@ def _process_markdown_code_blocks(
282288
if cleanup:
283289
os.remove(snippet_path)
284290

291+
285292
def _run_black():
286293
path = "."
287294
assert os.path.isdir(path)
@@ -294,7 +301,9 @@ def _run_black():
294301
cwd=path,
295302
)
296303
except:
297-
raise UserError("Encountered an error running black\nInstall: pipx install black")
304+
raise UserError(
305+
"Encountered an error running black\nInstall: pipx install black"
306+
)
298307

299308

300309
def _run_prettier():
@@ -309,7 +318,10 @@ def _run_prettier():
309318
cwd=path,
310319
)
311320
except:
312-
raise UserError("Encountered an error running prettier\nInstall: npm install --global prettier")
321+
raise UserError(
322+
"Encountered an error running prettier\nInstall: npm install --global prettier"
323+
)
324+
313325

314326
def update_docs() -> int:
315327
"""
@@ -329,7 +341,7 @@ def update_docs() -> int:
329341
print("Formatting markdown code blocks according to our rules...")
330342
_process_markdown_code_blocks(
331343
path=".",
332-
languages=["json"], # TODO: Add cfengine3 here
344+
languages=["json"], # TODO: Add cfengine3 here
333345
extract=True,
334346
syntax_check=False,
335347
output_check=False,

src/cfengine_cli/lint.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,17 @@ def _walk(filename, lines, node) -> int:
9797
return errors
9898

9999

100-
def lint_policy_file(filename, original_filename=None, original_line=None, snippet=None):
100+
def lint_policy_file(
101+
filename, original_filename=None, original_line=None, snippet=None
102+
):
101103
assert original_filename is None or type(original_filename) is str
102104
assert original_line is None or type(original_line) is int
103105
assert snippet is None or type(snippet) is int
104-
if original_filename is not None or original_line is not None or snippet is not None:
106+
if (
107+
original_filename is not None
108+
or original_line is not None
109+
or snippet is not None
110+
):
105111
assert original_filename and os.path.isfile(original_filename)
106112
assert original_line and original_line > 0
107113
assert snippet and snippet > 0
@@ -121,7 +127,9 @@ def lint_policy_file(filename, original_filename=None, original_line=None, snipp
121127
if not root_node.children:
122128
if snippet:
123129
assert original_filename and original_line
124-
print(f"Error: Empty policy snippet {snippet} at '{original_filename}:{original_line}'")
130+
print(
131+
f"Error: Empty policy snippet {snippet} at '{original_filename}:{original_line}'"
132+
)
125133
else:
126134
print(f"Error: Empty policy file '{filename}'")
127135
errors += 1

0 commit comments

Comments
 (0)