77from typing import Any
88
99from invoke import Context , task
10- from invoke .exceptions import UnexpectedExit
1110
1211CURRENT_DIRECTORY = Path (__file__ ).resolve ()
1312DOCUMENTATION_DIRECTORY = CURRENT_DIRECTORY .parent / "docs"
@@ -270,18 +269,15 @@ def generate_sdk_api_docs(context: Context, output: str | None = None) -> None:
270269
271270 output_dir = Path (output ) if output else DOCUMENTATION_DIRECTORY / "docs" / "python-sdk" / "sdk_ref"
272271
272+ if not is_tool_installed ("mdxify" ):
273+ print (" - mdxify is not installed, skipping documentation generation" )
274+ return
275+
273276 # Create a temporary directory to store the generated documentation
274277 with tempfile .TemporaryDirectory () as tmp_dir :
275278 # Generate the API documentation using mdxify and get flat file structure
276279 exec_cmd = f"mdxify --all --root-module infrahub_sdk --output-dir { tmp_dir } "
277- try :
278- context .run (exec_cmd , pty = True )
279- except UnexpectedExit as e :
280- if e .result .exited == 127 :
281- print (
282- " - mdxify is not installed, probably due to the python version being outside its supported range."
283- )
284- sys .exit (1 )
280+ context .run (exec_cmd , pty = True )
285281
286282 # Remove current obsolete documentation file structure
287283 if (output_dir / "infrahub_sdk" ).exists ():
@@ -304,3 +300,11 @@ def generate_sdk_api_docs(context: Context, output: str | None = None) -> None:
304300
305301 # Move the file to the new location
306302 shutil .move (mdx_file , target_path )
303+
304+ # Fix possible linting issues in the generated documentation
305+ if not is_tool_installed ("markdownlint-cli2" ):
306+ print (" - markdownlint-cli2 is not installed, skipping documentation linting" )
307+ return
308+
309+ exec_cmd = f"markdownlint-cli2 { output_dir } / --fix --config .markdownlint.yaml"
310+ context .run (exec_cmd , pty = True )
0 commit comments