Skip to content

Commit 92e4818

Browse files
authored
📝 Optimize MLIR documentation setup (#1216)
## Description This PR optimizes the MLIR documentation setup: - adds a dedicated and newly-created `mlir-pygments` package to provide syntax highlighting for MLIR code blocks - fixes a link in the MLIR docs - moves the cleanup logic from the RtD setup to the CMake setup so that it can be replicated locally - optimizes the page display for the MLIR docs pages. ## Checklist: <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are focused and relevant to this change. - [x] I have added appropriate tests that cover the new/changed functionality. - [x] I have updated the documentation to reflect these changes. - [x] I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals. - [x] I have added migration instructions to the upgrade guide (if needed). - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes. --------- Signed-off-by: burgholzer <burgholzer@me.com>
1 parent 4466944 commit 92e4818

File tree

8 files changed

+53
-22
lines changed

8 files changed

+53
-22
lines changed

.readthedocs.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ build:
3737
# Build the MLIR documentation
3838
- uvx cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_MQT_CORE_MLIR=ON -DMQT_MLIR_MIN_VERSION=19.0 -DMLIR_DIR=/usr/lib/llvm-19/lib/cmake/mlir -DLLVM_DIR=/usr/lib/llvm-19/lib/cmake/llvm
3939
- uvx cmake --build build --target mlir-doc
40-
# Remove unwanted artifacts from the MLIR documentation
41-
- 'find docs/mlir -name "*.md" -exec sed -i "s@\[TOC\]@@g" {} \;'
42-
- 'find docs/mlir -name "*.md" -exec sed -i "s@\[source\](https://github.com/llvm/llvm-project/.*)@@g" {} \;'
4340
build:
4441
html:
4542
- uv run --frozen --no-dev --group docs -m sphinx -T -b html -d docs/_build/doctrees -D language=en docs $READTHEDOCS_OUTPUT/html

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ if(BUILD_MQT_CORE_MLIR)
128128
POST_BUILD
129129
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/docs/
130130
${CMAKE_CURRENT_SOURCE_DIR}/docs/mlir/
131-
COMMENT "Copying generated MLIR documentation")
131+
COMMAND ${CMAKE_COMMAND} -D DOCS_DIR:PATH=${CMAKE_CURRENT_SOURCE_DIR}/docs/mlir -P
132+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/CleanMLIRDocs.cmake
133+
COMMENT "Copying and cleaning up generated MLIR documentation"
134+
VERBATIM)
135+
132136
endif()
133137

134138
if(MQT_CORE_MASTER_PROJECT)

cmake/CleanMLIRDocs.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
2+
# Copyright (c) 2025 Munich Quantum Software Company GmbH
3+
# All rights reserved.
4+
#
5+
# SPDX-License-Identifier: MIT
6+
#
7+
# Licensed under the MIT License
8+
9+
if(NOT DEFINED DOCS_DIR)
10+
message(FATAL_ERROR "DOCS_DIR is not defined!")
11+
endif()
12+
13+
file(GLOB_RECURSE MD_FILES "${DOCS_DIR}/*.md")
14+
foreach(MD_FILE ${MD_FILES})
15+
# Read the entire file content into a single variable.
16+
file(READ ${MD_FILE} CONTENT)
17+
18+
# Replace lines that only contain [TOC], allowing for whitespace.
19+
string(REGEX REPLACE "\n\\[TOC\\]\n" "" CONTENT "${CONTENT}")
20+
21+
# Replace lines that only contain an llvm-project source link, allowing for whitespace.
22+
string(REGEX REPLACE "\n\\[source\\]\\(https://github.com/llvm/llvm-project/blob/main.*\.td\\)\n"
23+
"" CONTENT "${CONTENT}")
24+
25+
# Write the processed content back to the file.
26+
file(WRITE ${MD_FILE} "${CONTENT}")
27+
endforeach()

docs/mlir/MQTOpt.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
hide-toc: true
2+
tocdepth: 3
33
---
44

55
# MQTOpt Dialect
@@ -9,13 +9,6 @@ hide-toc: true
99
:end-before: "## Operations"
1010
```
1111

12-
```{contents}
13-
:depth: 1
14-
:local:
15-
:backlinks:
16-
:class: this-will-duplicate-information-and-it-is-still-useful-here
17-
```
18-
1912
## Operations
2013

2114
```{include} Dialects/MLIRMQTOptDialect.md

docs/mlir/MQTRef.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
hide-toc: true
2+
tocdepth: 3
33
---
44

55
# MQTRef Dialect
@@ -9,13 +9,6 @@ hide-toc: true
99
:end-before: "## Operations"
1010
```
1111

12-
```{contents}
13-
:depth: 1
14-
:local:
15-
:backlinks:
16-
:class: this-will-duplicate-information-and-it-is-still-useful-here
17-
```
18-
1912
## Operations
2013

2114
```{include} Dialects/MLIRMQTRefDialect.md

docs/mlir/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Conversions
2525
This page is a work in progress.
2626
The content is not yet complete and subject to change.
2727
Contributions are welcome.
28-
See the {doc}`contribution guide <contributing>` for more information.
28+
See the {doc}`contribution guide <../contributing>` for more information.
2929
:::
3030

3131
## Classical Result Semantics

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ repair-wheel-command = "delvewheel repair -w {dest_dir} {wheel} --namespace-pkg
297297

298298
[tool.uv]
299299
required-version = ">=0.5.20"
300-
reinstall-package = ["mqt-core"]
301300

302301
[tool.uv.sources]
303302
mqt-core = { workspace = true }
@@ -325,6 +324,7 @@ docs = [
325324
"graphviz>=0.20.3",
326325
"sphinx>=8.1.3",
327326
"sphinx>=8.2.3; python_version >= '3.11'",
327+
"mlir-pygments>=1.0.0",
328328
]
329329
test = [
330330
"pytest>=8.3.5",

uv.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)