Skip to content

Commit 567ba75

Browse files
2010YOUY01martin-gJefffrey
authored
doc: Add an auto-generated dependency graph for internal crates (#19280)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> A dependency graph for workspace member crates are often needed when doing refactors, I want it to be included in the doc, and have a script to update it automatically. Here is the preview: <img width="1203" height="951" alt="image" src="https://github.com/user-attachments/assets/527c18fc-258e-465f-a150-f2aafe3e6db9" /> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> - adds a script to generate the dependency graph `deps.svg`, and verify if the existing one is up to date. - adds a documentation page in `Contributor Guide` to show this graph - adds a CI job to check if the generated dependency graph is up to date with the code. ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> I tested the dependency graph display locally, see above. Is it possible to see the preview from this PR's change online? I also included a dummy crate in the initial commit, to test if the CI can catch it and throw understandable error message. ## Are there any user-facing changes? No <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com> Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
1 parent 6bf5e98 commit 567ba75

File tree

9 files changed

+308
-3
lines changed

9 files changed

+308
-3
lines changed

.github/workflows/dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ jobs:
6666
- name: Install cargo-machete
6767
run: cargo install cargo-machete --version ^0.9 --locked
6868
- name: Detect unused dependencies
69-
run: cargo machete --with-metadata
69+
run: cargo machete --with-metadata

.github/workflows/docs.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ jobs:
5151
python3 -m venv venv
5252
source venv/bin/activate
5353
pip install -r docs/requirements.txt
54+
- name: Install dependency graph tooling
55+
run: |
56+
set -x
57+
sudo apt-get update
58+
sudo apt-get install -y graphviz
59+
cargo install cargo-depgraph --version ^1.6 --locked
5460
5561
- name: Build docs
5662
run: |

.github/workflows/docs_pr.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,15 @@ jobs:
5454
python3 -m venv venv
5555
source venv/bin/activate
5656
pip install -r docs/requirements.txt
57+
- name: Install dependency graph tooling
58+
run: |
59+
set -x
60+
sudo apt-get update
61+
sudo apt-get install -y graphviz
62+
cargo install cargo-depgraph --version ^1.6 --locked
5763
- name: Build docs html and check for warnings
5864
run: |
5965
set -x
6066
source venv/bin/activate
6167
cd docs
6268
./build.sh # fails on errors
63-

docs/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ build/
2020
venv/
2121
.python-version
2222
__pycache__/
23+
24+
# Generated dependency graph artifacts (produced during docs CI)
25+
source/_static/data/deps.dot
26+
source/_static/data/deps.svg

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ needing to create a virtual environment:
4040
uv run --with-requirements requirements.txt bash build.sh
4141
```
4242

43+
The docs build regenerates the workspace dependency graph via
44+
`docs/scripts/generate_dependency_graph.sh`, so ensure `cargo`, `cargo-depgraph`
45+
(`cargo install cargo-depgraph --version ^1.6 --locked`), and Graphviz `dot`
46+
(`brew install graphviz` or `sudo apt-get install -y graphviz`) are available.
47+
4348
## Build & Preview
4449

4550
Run the provided script to build the HTML pages.

docs/build.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818
# under the License.
1919
#
2020

21-
set -e
21+
set -euo pipefail
22+
23+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24+
cd "${SCRIPT_DIR}"
25+
2226
rm -rf build 2> /dev/null
2327

28+
# Keep the workspace dependency graph in sync with the codebase.
29+
scripts/generate_dependency_graph.sh
30+
2431
make html
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
# See `usage()` for details about this script.
21+
#
22+
# The key commands to generate the dependency graph SVG in this script are:
23+
# cargo depgraph ... | dot -Tsvg > deps.svg
24+
# See below for the exact command used.
25+
26+
set -euo pipefail
27+
28+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
29+
REPO_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)"
30+
OUTPUT_DIR="${REPO_DIR}/docs/source/_static/data"
31+
SVG_OUTPUT="${OUTPUT_DIR}/deps.svg"
32+
33+
usage() {
34+
cat <<EOF
35+
Generate the workspace dependency graph SVG for the docs.
36+
37+
'deps.svg' is embedded in the DataFusion docs (Contributor Guide → Architecture → Workspace Dependency Graph).
38+
39+
Output:
40+
SVG: ${SVG_OUTPUT}
41+
42+
Usage: $(basename "$0")
43+
44+
Options:
45+
-h, --help Show this help message.
46+
EOF
47+
}
48+
49+
while [[ $# -gt 0 ]]; do
50+
case "$1" in
51+
-h|--help)
52+
usage
53+
exit 0
54+
;;
55+
*)
56+
echo "Unknown option: $1" >&2
57+
usage
58+
exit 1
59+
;;
60+
esac
61+
shift
62+
done
63+
64+
if ! command -v cargo >/dev/null 2>&1; then
65+
echo "cargo is required to build the dependency graph." >&2
66+
exit 1
67+
fi
68+
69+
if ! command -v cargo-depgraph > /dev/null 2>&1; then
70+
echo "cargo-depgraph is required (install with: cargo install cargo-depgraph)." >&2
71+
exit 1
72+
fi
73+
74+
if ! command -v dot >/dev/null 2>&1; then
75+
echo "Graphviz 'dot' is required to render the SVG." >&2
76+
exit 1
77+
fi
78+
79+
mkdir -p "${OUTPUT_DIR}"
80+
81+
(
82+
cd "${REPO_DIR}"
83+
# Ignore utility crates only used by internal scripts
84+
cargo depgraph \
85+
--workspace-only \
86+
--all-deps \
87+
--dedup-transitive-deps \
88+
--exclude gen,gen-common \
89+
| dot \
90+
-Grankdir=TB \
91+
-Gconcentrate=true \
92+
-Goverlap=false \
93+
-Tsvg \
94+
> "${SVG_OUTPUT}"
95+
)
96+
97+
echo "Wrote dependency graph SVG to ${SVG_OUTPUT}"
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<!---
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Workspace Dependency Graph
21+
22+
This page shows the dependency relationships between DataFusion's workspace
23+
crates. This only includes internal dependencies, external crates like `Arrow` are not included
24+
25+
The dependency graph is auto-generated by `docs/scripts/generate_dependency_graph.sh` to ensure it stays up-to-date, and the script now runs automatically as part of `docs/build.sh`.
26+
27+
## Dependency Graph for Workspace Crates
28+
29+
<!--
30+
Below is an embedded .svg file, with interactive functionalities like drag/zoom-in/etc.
31+
-->
32+
33+
```{raw} html
34+
<div id="workspace-deps-wrapper" style="border:1px solid #d4d4d8;border-radius:10px;overflow:hidden;background:#fff;">
35+
<div id="workspace-deps-inline" style="min-height:760px;width:100%;background:#f8fafc;overflow:hidden;padding:0;margin:0;">
36+
```
37+
38+
```{eval-rst}
39+
.. raw:: html
40+
:file: ../../_static/data/deps.svg
41+
```
42+
43+
```{raw} html
44+
</div>
45+
<div style="padding:10px 12px;background:#f1f5f9;border-top:1px solid #e5e7eb;display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px;">
46+
<span style="color:#334155;font-size:0.95rem;">Interactive SVG (pan, zoom, search)</span>
47+
<div style="display:flex;align-items:center;gap:6px;">
48+
<button id="workspace-deps-zoom-out" type="button" style="padding:6px 10px;border:1px solid #cbd5e1;border-radius:6px;background:#fff;color:#334155;cursor:pointer;">−</button>
49+
<button id="workspace-deps-zoom-in" type="button" style="padding:6px 10px;border:1px solid #cbd5e1;border-radius:6px;background:#fff;color:#334155;cursor:pointer;">+</button>
50+
</div>
51+
<a href="../../_static/data/deps.svg" target="_blank" rel="noopener"
52+
style="font-weight:600;color:#2563eb;text-decoration:none;">Open SVG ↗</a>
53+
</div>
54+
</div>
55+
<script>
56+
(function () {
57+
const host = document.getElementById("workspace-deps-inline");
58+
if (!host) {
59+
return;
60+
}
61+
62+
const svg = host.querySelector("svg");
63+
if (!svg) {
64+
host.textContent = "Unable to load dependency graph.";
65+
host.style.display = "flex";
66+
host.style.alignItems = "center";
67+
host.style.justifyContent = "center";
68+
host.style.background = "#f8fafc";
69+
return;
70+
}
71+
72+
svg.removeAttribute("width");
73+
svg.removeAttribute("height");
74+
svg.style.width = "100%";
75+
svg.style.height = "100%";
76+
svg.style.cursor = "grab";
77+
svg.style.touchAction = "none";
78+
79+
const rawViewBox = (svg.getAttribute("viewBox") || "").split(/\s+/).map(Number);
80+
if (rawViewBox.length !== 4 || rawViewBox.some((v) => Number.isNaN(v))) {
81+
return;
82+
}
83+
84+
const initial = {
85+
x: rawViewBox[0],
86+
y: rawViewBox[1],
87+
width: rawViewBox[2],
88+
height: rawViewBox[3],
89+
};
90+
91+
const state = { ...initial };
92+
const applyViewBox = () => {
93+
svg.setAttribute("viewBox", `${state.x} ${state.y} ${state.width} ${state.height}`);
94+
};
95+
96+
let isPanning = false;
97+
let last = { x: 0, y: 0 };
98+
99+
svg.addEventListener("pointerdown", (event) => {
100+
isPanning = true;
101+
last = { x: event.clientX, y: event.clientY };
102+
svg.setPointerCapture(event.pointerId);
103+
svg.style.cursor = "grabbing";
104+
});
105+
106+
const endPan = (event) => {
107+
if (event && svg.hasPointerCapture(event.pointerId)) {
108+
svg.releasePointerCapture(event.pointerId);
109+
}
110+
isPanning = false;
111+
svg.style.cursor = "grab";
112+
};
113+
114+
svg.addEventListener("pointerup", endPan);
115+
svg.addEventListener("pointerleave", endPan);
116+
svg.addEventListener("pointercancel", endPan);
117+
118+
const zoomBy = (factor) => {
119+
const targetWidth = state.width * factor;
120+
const targetHeight = state.height * factor;
121+
const minSize = Math.max(initial.width * 0.05, 10);
122+
const maxSize = initial.width * 20;
123+
const clampedWidth = Math.min(Math.max(targetWidth, minSize), maxSize);
124+
const clampedHeight = Math.min(Math.max(targetHeight, minSize), maxSize);
125+
126+
state.x += (state.width - clampedWidth) / 2;
127+
state.y += (state.height - clampedHeight) / 2;
128+
state.width = clampedWidth;
129+
state.height = clampedHeight;
130+
applyViewBox();
131+
};
132+
133+
const normalizeDelta = (deltaY, deltaMode) => {
134+
// Make trackpad/wheel zoom feel smooth across devices.
135+
const multiplier = deltaMode === 1 ? 16 : deltaMode === 2 ? window.innerHeight : 1;
136+
return deltaY * multiplier;
137+
};
138+
139+
svg.addEventListener("pointermove", (event) => {
140+
if (!isPanning) {
141+
return;
142+
}
143+
const scaleX = state.width / svg.clientWidth;
144+
const scaleY = state.height / svg.clientHeight;
145+
state.x -= (event.clientX - last.x) * scaleX;
146+
state.y -= (event.clientY - last.y) * scaleY;
147+
last = { x: event.clientX, y: event.clientY };
148+
applyViewBox();
149+
});
150+
151+
svg.addEventListener("wheel", (event) => {
152+
event.preventDefault();
153+
154+
const delta = normalizeDelta(event.deltaY, event.deltaMode);
155+
const factor = Math.exp(delta * 0.0015); // smaller magnitude for smoother scrolling
156+
zoomBy(factor);
157+
}, { passive: false });
158+
159+
const zoomIn = document.getElementById("workspace-deps-zoom-in");
160+
const zoomOut = document.getElementById("workspace-deps-zoom-out");
161+
if (zoomIn) {
162+
zoomIn.addEventListener("click", () => zoomBy(0.9));
163+
}
164+
if (zoomOut) {
165+
zoomOut.addEventListener("click", () => zoomBy(1.1));
166+
}
167+
})();
168+
</script>
169+
```
170+
171+
### Legend
172+
173+
- black lines: normal dependency
174+
- blue lines: dev-dependency
175+
- green lines: build-dependency
176+
- dotted lines: optional dependency (could be removed by disabling a cargo feature)
177+
178+
Transitive dependencies are intentionally ignored to keep the graph readable.
179+
180+
The dependency graph is generated through `cargo depgraph` by `docs/scripts/generate_dependency_graph.sh`.

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ To get started, see
159159
contributor-guide/communication
160160
contributor-guide/development_environment
161161
contributor-guide/architecture
162+
contributor-guide/architecture/dependency-graph
162163
contributor-guide/testing
163164
contributor-guide/api-health
164165
contributor-guide/howtos

0 commit comments

Comments
 (0)