in src/doc_builder/commands/convert_doc_file.py [0:0]
def convert_command(args):
source_file = Path(args.source_file).absolute()
if source_file.suffix not in [".rst", ".py"]:
raise ValueError(f"This script only converts rst files. Got {source_file}.")
if args.package_name is None:
git_folder = find_root_git(source_file)
if git_folder is None:
raise ValueError(
"Cannot determine a default for package_name as the file passed is not in a git directory. "
"Please pass along a package_name."
)
package_name = git_folder.name
else:
package_name = args.package_name
if args.output_file is None:
output_file = source_file.with_suffix(".mdx") if source_file.suffix == ".rst" else source_file
else:
output_file = args.output_file
page_info = {"package_name": package_name, "no_prefix": True}
if source_file.suffix == ".py":
convert_rst_docstrings_in_file(source_file, output_file, page_info)
else:
if args.doc_folder is None:
git_folder = find_root_git(source_file)
if git_folder is None:
raise ValueError(
"Cannot determine a default for package_name as the file passed is not in a git directory. "
"Please pass along a package_name."
)
doc_folder = (git_folder / "docs") / "source"
if doc_folder / source_file.relative_to(doc_folder) != source_file:
raise ValueError(
f"The default found for `doc_folder` is {doc_folder} but it does not look like {source_file} is "
"inside it."
)
else:
doc_folder = args.doc_folder
page_info["page"] = source_file.with_suffix(".html").relative_to(doc_folder)
convert_rst_file(source_file, output_file, page_info)