Skip to content

Commit 99305f7

Browse files
committed
Removed markdowner and integrated prettier and black
Signed-off-by: Ole Herman Schumacher Elgesem <[email protected]>
1 parent 615b71c commit 99305f7

File tree

3 files changed

+39
-258
lines changed

3 files changed

+39
-258
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies = [
1515
"tree-sitter-cfengine>=1.0.8",
1616
"tree-sitter>=0.23",
1717
"markdown-it-py>=3.0.0",
18+
"black>=25.1.0",
1819
]
1920
classifiers = [
2021
"Development Status :: 3 - Alpha",

src/cfengine_cli/docs.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import markdown_it
1717
from cfbs.pretty import pretty_file
1818

19-
from cfengine_cli.markdowner import markdown_prettify
2019
from cfengine_cli.utils import UserError
2120

2221

@@ -287,19 +286,49 @@ def _markdown_code_checker(
287286
)
288287
if cleanup:
289288
os.remove(snippet_path)
290-
if autoformat:
291-
markdown_prettify(origin_path)
292289

290+
def _run_black():
291+
path = "."
292+
assert os.path.isdir(path)
293+
try:
294+
subprocess.run(
295+
["black", path],
296+
capture_output=True,
297+
text=True,
298+
check=True,
299+
cwd=path,
300+
)
301+
except:
302+
raise UserError("Encountered an error running prettier")
303+
304+
305+
def _run_prettier():
306+
path = "."
307+
assert os.path.isdir(path)
308+
try:
309+
subprocess.run(
310+
["prettier", "--write", "**.markdown", "**.md"],
311+
capture_output=True,
312+
text=True,
313+
check=True,
314+
cwd=path,
315+
)
316+
except:
317+
raise UserError("Encountered an error running prettier")
293318

294319
def update_docs() -> int:
295320
"""
296-
Iterate through entire docs repo (.), autoformatting all JSONs.
297-
298-
Will be expanded to more types of formatting in the future.
321+
Iterate through entire docs repo (.), autoformatting as much as possible:
322+
- python code with black
323+
- markdown files with prettier
324+
- code blocks inside markdown files are formatted for the formats supported by prettier
325+
- JSON code blocks are re-formatted by cfbs pretty (we plan to expand this to CFEngine code blocks)
299326
300327
Run by the command:
301328
cfengine dev docs-format
302329
"""
330+
_run_black()
331+
_run_prettier()
303332
_markdown_code_checker(
304333
path=".",
305334
syntax_check=False,
@@ -314,7 +343,9 @@ def update_docs() -> int:
314343

315344

316345
def check_docs() -> int:
317-
"""Entry point to be called by other files
346+
"""
347+
Run checks / tests on docs.
348+
Currently only JSON syntax checking.
318349
319350
Run by the command:
320351
cfengine dev docs-checking"""

src/cfengine_cli/markdowner.py

Lines changed: 0 additions & 251 deletions
This file was deleted.

0 commit comments

Comments
 (0)