Skip to content

Commit f99699c

Browse files
Upgrade to 1.0.0 (#187)
Major Changes to how docs-as-code is used Co-authored-by: Maximilian Sören Pollak <[email protected]>
1 parent 3e25a49 commit f99699c

File tree

27 files changed

+387
-343
lines changed

27 files changed

+387
-343
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"name": "eclipse-s-core",
33
"image": "ghcr.io/eclipse-score/devcontainer:latest",
44
"initializeCommand": "mkdir -p ${localEnv:HOME}/.cache/bazel",
5-
"updateContentCommand": "bazel run //docs:ide_support"
5+
"updateContentCommand": "bazel run //:ide_support"
66
}

.github/workflows/consumer_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- name: Run Consumer tests
6262
id: consumer_tests
6363
run: |
64-
bazel run //docs:ide_support
64+
bazel run //:ide_support
6565
.venv_docs/bin/python -m pytest -s -v src/tests/
6666
env:
6767
FORCE_COLOR: "1"

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ jobs:
3838
id-token: write
3939

4040
with:
41-
bazel-target: "//docs:incremental_release -- --github_user=${{ github.repository_owner }} --github_repo=${{ github.event.repository.name }}"
41+
bazel-target: "//:docs -- --github_user=${{ github.repository_owner }} --github_repo=${{ github.event.repository.name }}"
4242
retention-days: 3

.github/workflows/format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jobs:
3737
bazelisk-cache: true
3838
- name: Run formatting checks
3939
run: |
40-
bazel run //docs:ide_support
40+
bazel run //:ide_support
4141
bazel test //src:format.check

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jobs:
3737
bazelisk-cache: true
3838
- name: Run test targets
3939
run: |
40-
bazel run //docs:ide_support
40+
bazel run //:ide_support
4141
bazel test //src/...

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"esbonio.sphinx.buildCommand": [
6969
"docs",
7070
"_build",
71-
"-T", // show details in case of errors in extensions
71+
"-T", // show more details in case of errors
7272
"--jobs",
7373
"auto",
7474
"--conf-dir",

BUILD

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# *******************************************************************************
1313

1414
load("@score_cr_checker//:cr_checker.bzl", "copyright_checker")
15+
load("//:docs.bzl", "docs")
1516

1617
package(default_visibility = ["//visibility:public"])
1718

@@ -27,7 +28,9 @@ copyright_checker(
2728
visibility = ["//visibility:public"],
2829
)
2930

30-
exports_files([
31-
"MODULE.bazel",
32-
"BUILD",
33-
])
31+
docs(
32+
data = [
33+
"@score_process//:needs_json",
34+
],
35+
source_dir = "docs",
36+
)

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
module(
1515
name = "score_docs_as_code",
16-
version = "0.5.0",
17-
compatibility_level = 0,
16+
version = "1.0.0-RC1",
17+
compatibility_level = 1,
1818
)
1919

2020
###############################################################################

README.md

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,30 @@
22

33
Docs-as-code tooling for Eclipse S-CORE
44

5-
## Overview
6-
7-
The S-CORE docs Sphinx configuration and build code.
5+
Full documentation is on [GitHub Pages](https://eclipse-score.github.io/docs-as-code/).
86

97
> [!NOTE]
108
> This repository offers a [DevContainer](https://containers.dev/).
119
> For setting this up read [eclipse-score/devcontainer/README.md#inside-the-container](https://github.com/eclipse-score/devcontainer/blob/main/README.md#inside-the-container).
1210
13-
## Building documentation
14-
15-
#### Run a documentation build:
16-
17-
#### Integrate latest score main branch
18-
19-
```bash
20-
bazel run //docs:incremental_latest
21-
```
22-
23-
#### Access your documentation at:
24-
25-
- `_build/` for incremental
11+
## Development of docs-as-code
2612

27-
#### Getting IDE support
13+
### Getting IDE support for docs-as-code development
2814

29-
Create the virtual environment via `bazel run //docs:ide_support`.\
15+
Create the virtual environment via `bazel run //:ide_support`.
3016
If your IDE does not automatically ask you to activate the newly created environment you can activate it.
3117

3218
- In VSCode via `ctrl+p` => `Select Python Interpreter` then select `.venv_docs/bin/python`
33-
- In the terminal via `source .venv_docs/bin/activate`
19+
- In the terminal via `. .venv_docs/bin/activate`
3420

35-
#### Format your documentation with:
21+
### Format your documentation with:
3622

3723
```bash
3824
bazel test //src:format.check
3925
bazel run //src:format.fix
4026
```
4127

42-
#### Find & fix missing copyright
28+
### Find & fix missing copyright
4329

4430
```bash
4531
bazel run //:copyright-check

docs.bzl

Lines changed: 45 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -46,151 +46,72 @@ load("@rules_python//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs
4646
load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
4747
load("@score_python_basics//:defs.bzl", "score_virtualenv")
4848

49-
sphinx_requirements = all_requirements + [
50-
"@score_docs_as_code//src:plantuml_for_python",
51-
"@score_docs_as_code//src/extensions:score_plantuml",
52-
"@score_docs_as_code//src/find_runfiles:find_runfiles",
53-
"@score_docs_as_code//src/extensions/score_draw_uml_funcs:score_draw_uml_funcs",
54-
"@score_docs_as_code//src/extensions/score_header_service:score_header_service",
55-
"@score_docs_as_code//src/extensions/score_layout:score_layout",
56-
"@score_docs_as_code//src/extensions/score_metamodel:score_metamodel",
57-
"@score_docs_as_code//src/extensions/score_source_code_linker:score_source_code_linker",
58-
]
59-
60-
def docs(source_files_to_scan_for_needs_links = None, source_dir = "docs", conf_dir = "docs", build_dir_for_incremental = "_build", docs_targets = [], deps = []):
49+
def docs(source_dir = "docs", data = [], deps = []):
6150
"""
6251
Creates all targets related to documentation.
6352
By using this function, you'll get any and all updates for documentation targets in one place.
64-
Current restrictions:
65-
* only callable from 'docs/BUILD'
6653
"""
6754

68-
# We are iterating over all provided 'targets' in order to allow for automatic generation of them without
69-
# needing to modify the underlying 'docs.bzl' file.
70-
for target in docs_targets:
71-
suffix = "_" + target["suffix"] if target["suffix"] else ""
72-
external_needs_deps = target.get("target", [])
73-
external_needs_def = target.get("external_needs_info", [])
74-
75-
sphinx_build_binary(
76-
name = "sphinx_build" + suffix,
77-
visibility = ["//visibility:public"],
78-
data = ["@score_docs_as_code//src:docs_assets", "@score_docs_as_code//src:docs_as_code_py_modules"] + external_needs_deps,
79-
deps = sphinx_requirements + deps,
80-
)
81-
_incremental(
82-
incremental_name = "incremental" + suffix,
83-
live_name = "live_preview" + suffix,
84-
conf_dir = conf_dir,
85-
source_dir = source_dir,
86-
build_dir = build_dir_for_incremental,
87-
external_needs_deps = external_needs_deps,
88-
external_needs_def = external_needs_def,
89-
extra_dependencies = deps,
90-
)
91-
_docs(
92-
name = "docs" + suffix,
93-
suffix = suffix,
94-
format = "html",
95-
external_needs_deps = external_needs_deps,
96-
external_needs_def = external_needs_def,
97-
)
98-
_docs(
99-
name = "docs_needs" + suffix,
100-
suffix = suffix,
101-
format = "needs",
102-
external_needs_deps = external_needs_deps,
103-
external_needs_def = external_needs_def,
104-
)
105-
106-
# Virtual python environment for working on the documentation (esbonio).
107-
# incl. python support when working on conf.py and sphinx extensions.
108-
# creates :ide_support target for virtualenv
109-
_ide_support(deps)
110-
111-
# creates 'needs.json' build target
112-
113-
def _incremental(incremental_name = "incremental", live_name = "live_preview", source_dir = "docs", conf_dir = "docs", build_dir = "_build", extra_dependencies = list(), external_needs_deps = list(), external_needs_def = None):
114-
"""
115-
A target for building docs incrementally at runtime, incl live preview.
116-
Args:
117-
source_code_linker: The source code linker target to be used for linking source code to documentation.
118-
source_code_links: The output from the source code linker.
119-
source_dir: Directory containing the source files for documentation.
120-
conf_dir: Directory containing the Sphinx configuration.
121-
build_dir: Directory to output the built documentation.
122-
extra_dependencies: Additional dependencies besides the centrally maintained "sphinx_requirements".
123-
"""
124-
125-
dependencies = sphinx_requirements + extra_dependencies + ["@rules_python//python/runfiles"]
126-
127-
# Create description tags for the incremental targets.
128-
call_path = native.package_name()
129-
incremental_tag = "cli_help=Build documentation incrementally:\nbazel run //" + call_path + ":" + incremental_name
130-
131-
if incremental_name == "incremental_latest":
132-
incremental_tag = (
133-
"cli_help=Build documentation incrementally (use current main branch of imported docs repositories " +
134-
"(e.g. process_description)):\n" +
135-
"bazel run //" + call_path + ":incremental_latest"
136-
)
137-
elif incremental_name == "incremental_release":
138-
incremental_tag = (
139-
"cli_help=Build documentation incrementally (use release version imported in MODULE.bazel):\n" +
140-
"bazel run //" + call_path + ":incremental_release"
141-
)
55+
data = data + ["@score_docs_as_code//src:docs_assets"]
56+
57+
deps = deps + all_requirements + [
58+
"@score_docs_as_code//src:plantuml_for_python",
59+
"@score_docs_as_code//src/extensions:score_plantuml",
60+
"@score_docs_as_code//src/find_runfiles:find_runfiles",
61+
"@score_docs_as_code//src/extensions/score_draw_uml_funcs:score_draw_uml_funcs",
62+
"@score_docs_as_code//src/extensions/score_header_service:score_header_service",
63+
"@score_docs_as_code//src/extensions/score_layout:score_layout",
64+
"@score_docs_as_code//src/extensions/score_metamodel:score_metamodel",
65+
"@score_docs_as_code//src/extensions/score_source_code_linker:score_source_code_linker",
66+
]
67+
68+
sphinx_build_binary(
69+
name = "sphinx_build",
70+
visibility = ["//visibility:private"],
71+
data = data,
72+
deps = deps,
73+
)
14274

14375
py_binary(
144-
name = incremental_name,
76+
name = "docs",
77+
tags = ["cli_help=Build documentation [run]"],
14578
srcs = ["@score_docs_as_code//src:incremental.py"],
146-
deps = dependencies,
147-
# TODO: Figure out if we need all dependencies as data here or not.
148-
data = ["@score_docs_as_code//src:plantuml", "@score_docs_as_code//src:docs_assets"] + dependencies + external_needs_deps,
79+
data = data,
80+
deps = deps,
14981
env = {
15082
"SOURCE_DIRECTORY": source_dir,
151-
"CONF_DIRECTORY": conf_dir,
152-
"BUILD_DIRECTORY": build_dir,
153-
"EXTERNAL_NEEDS_INFO": json.encode(external_needs_def),
83+
"DATA": str(data),
15484
"ACTION": "incremental",
15585
},
156-
tags = [incremental_tag],
15786
)
15887

15988
py_binary(
160-
name = live_name,
89+
name = "live_preview",
90+
tags = ["cli_help=Live preview documentation in the browser [run]"],
16191
srcs = ["@score_docs_as_code//src:incremental.py"],
162-
deps = dependencies,
163-
data = ["@score_docs_as_code//src:plantuml", "@score_docs_as_code//src:docs_assets"] + dependencies + external_needs_deps,
92+
data = data,
93+
deps = deps,
16494
env = {
16595
"SOURCE_DIRECTORY": source_dir,
166-
"CONF_DIRECTORY": conf_dir,
167-
"BUILD_DIRECTORY": build_dir,
168-
"EXTERNAL_NEEDS_INFO": json.encode(external_needs_def),
96+
"DATA": str(data),
16997
"ACTION": "live_preview",
17098
},
17199
)
172100

173-
def _ide_support(extra_dependencies):
174-
call_path = native.package_name()
175101
score_virtualenv(
176102
name = "ide_support",
103+
tags = ["cli_help=Create virtual environment (.venv_docs) for documentation support [run]"],
177104
venv_name = ".venv_docs",
178-
reqs = sphinx_requirements + extra_dependencies,
179-
tags = [
180-
"cli_help=Create virtual environment for documentation:\n" +
181-
"bazel run //" + call_path + ":ide_support",
182-
],
105+
reqs = deps,
106+
# Add dependencies to ide_support, so esbonio has access to them.
107+
data = data,
183108
)
184109

185-
def _docs(name = "docs", suffix = "", format = "html", external_needs_deps = list(), external_needs_def = list()):
186-
ext_needs_arg = "--define=external_needs_source=" + json.encode(external_needs_def)
187-
188-
# Clean suffix used in all generated target names
189-
target_suffix = "" if name == "docs" else "_" + name[len("docs"):]
190-
110+
# creates 'needs.json' build target
191111
sphinx_docs(
192-
name = name,
112+
name = "needs_json",
193113
srcs = native.glob([
114+
# TODO: we do not need images etc to generate the json file.
194115
"**/*.png",
195116
"**/*.svg",
196117
"**/*.md",
@@ -206,43 +127,16 @@ def _docs(name = "docs", suffix = "", format = "html", external_needs_deps = lis
206127
"**/*.csv",
207128
"**/*.inc",
208129
], exclude = ["**/tests/*"], allow_empty = True),
209-
config = ":conf.py",
130+
config = ":" + source_dir + "/conf.py",
210131
extra_opts = [
211132
"-W",
212133
"--keep-going",
213-
] + [ext_needs_arg],
214-
formats = [
215-
format,
134+
"-T", # show more details in case of errors
135+
"--jobs",
136+
"auto",
137+
"--define=external_needs_source=" + str(data),
216138
],
217-
sphinx = ":sphinx_build" + suffix,
218-
tags = [
219-
"manual",
220-
],
221-
tools = [
222-
"@score_docs_as_code//src:plantuml",
223-
"@score_docs_as_code//src:docs_assets",
224-
] + external_needs_deps,
225-
visibility = ["//visibility:public"],
226-
)
227-
228-
native.filegroup(
229-
name = "assets" + target_suffix,
230-
srcs = native.glob(["_assets/**"], allow_empty = True),
231-
visibility = ["//visibility:public"],
232-
)
233-
234-
native.filegroup(
235-
name = "html" + target_suffix,
236-
srcs = [":" + name],
237-
visibility = ["//visibility:public"],
238-
)
239-
240-
pkg_files(
241-
name = "html_files" + target_suffix,
242-
srcs = [":html" + target_suffix],
243-
)
244-
245-
pkg_tar(
246-
name = "github_pages" + target_suffix,
247-
srcs = [":html_files" + target_suffix],
139+
formats = ["needs"],
140+
sphinx = ":sphinx_build",
141+
tools = data,
248142
)

0 commit comments

Comments
 (0)