Skip to content

Commit 59afecd

Browse files
committed
Build links to the Flows IDE for rendered pages
Update the `build-doc-bundle` script to create a gzip-encoded link to the example flows in the Flows IDE. The IDE link is passed to the asciidoc content by setting it as an attribute of the doc, which the content can then reference in a `link:` directive. For now, as a simple matter of simplicity and uniformity, the link is dropped, unadorned, at the top of each page where it is supported. Because the compute examples contain multiple definitions and therefore can't build simple links, an exclude config is supported to disable the links for these examples.
1 parent b6fb134 commit 59afecd

File tree

10 files changed

+67
-12
lines changed

10 files changed

+67
-12
lines changed

compute_transfer_examples/tar_and_transfer/.doc_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ short_description: |
77
Two examples are included here, one in which the files are located on the
88
server which runs Globus Compute, and one in which the files are on a user's
99
machine and must be moved to the Compute host.
10+
include_ide_link: false
1011

1112
example_dir: 'compute_tar_and_transfer'
1213
append_source_blocks: false

compute_transfer_examples/tar_and_transfer/collection_transfer_requires_flow/.doc_config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ short_description: |
1212
They are expected to be invoked from the Globus webapp when initating a transfer
1313
where the source / destination collections have an `associated_flow_policy`
1414
with this flow.
15+
include_ide_link: false
1516

1617
example_dir: 'collection_transfer_requires_flow'
1718
append_source_blocks: false
@@ -29,4 +30,4 @@ include_files:
2930
- 'compute_transfer_example_2_schema.json'
3031
- 'register_compute_function.py'
3132

32-
menu_weight: 400
33+
menu_weight: 400

support/build-doc-bundle.py

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77

88
from __future__ import annotations
99

10+
import base64
1011
import dataclasses
1112
import glob
13+
import gzip
1214
import io
15+
import json
1316
import os
1417
import pathlib
1518
import tarfile
1619
import textwrap
1720
import typing as t
21+
import urllib.parse
1822

1923
try:
2024
import click
@@ -83,6 +87,24 @@ def find_build_configs() -> t.Iterator[pathlib.Path]:
8387
yield pathlib.Path(item)
8488

8589

90+
def build_ide_link(source_dir: pathlib.Path) -> str:
91+
definition = _encode_link_part(source_dir / "definition.json")
92+
input_schema = _encode_link_part(source_dir / "input_schema.json")
93+
return (
94+
"https://globus.github.io/flows-ide?format=gzip&"
95+
f"d={definition}&s={input_schema}"
96+
)
97+
98+
99+
def _encode_link_part(source_path: pathlib.Path) -> str:
100+
# load and dump JSON to strip whitespace
101+
loaded_doc = json.loads(source_path.read_bytes())
102+
doc_bytes = json.dumps(loaded_doc, separators=(",", ":")).encode("utf-8")
103+
gzipped_doc = gzip.compress(doc_bytes)
104+
b64_gzipped_doc = base64.b64encode(gzipped_doc)
105+
return urllib.parse.quote_from_bytes(b64_gzipped_doc.rstrip(b"="))
106+
107+
86108
def render_example_index_doc(
87109
source_dir: pathlib.Path, config: ExampleDocBuildConfig
88110
) -> bytes:
@@ -103,23 +125,37 @@ def render_example_index_doc(
103125

104126
if config.append_source_blocks:
105127
content = append_source_blocks(content)
106-
content = prepend_preamble(config, content)
128+
129+
ide_link: str | None = None
130+
if config.include_ide_link:
131+
ide_link = build_ide_link(source_dir)
132+
133+
content = prepend_preamble(config, ide_link, content)
107134
return content
108135

109136

110-
def prepend_preamble(config: ExampleDocBuildConfig, content: bytes) -> bytes:
111-
return (
112-
textwrap.dedent(
113-
f"""\
114-
---
115-
menu_weight: {config.menu_weight}
116-
---
137+
def prepend_preamble(
138+
config: ExampleDocBuildConfig, ide_link: str | None, content: bytes
139+
) -> bytes:
140+
preamble = textwrap.dedent(
141+
f"""\
142+
---
143+
menu_weight: {config.menu_weight}
144+
---
117145
118-
"""
119-
).encode("utf-8")
120-
+ content
146+
"""
121147
)
122148

149+
if ide_link is not None:
150+
preamble += textwrap.dedent(
151+
f"""
152+
:flows_ide_link: {ide_link}
153+
154+
"""
155+
)
156+
157+
return preamble.encode("utf-8") + content
158+
123159

124160
def append_source_blocks(content: bytes) -> bytes:
125161
return (
@@ -208,6 +244,7 @@ class ExampleDocBuildConfig:
208244
index_source: IndexSourceConfig
209245
append_source_blocks: bool
210246
menu_weight: int
247+
include_ide_link: bool
211248
include_files: list[str]
212249

213250
@classmethod
@@ -220,6 +257,7 @@ def _load(cls, data: dict[str, t.Any]) -> t.Self:
220257
index_source=IndexSourceConfig._load(data["index_source"]),
221258
append_source_blocks=data["append_source_blocks"],
222259
menu_weight=data["menu_weight"],
260+
include_ide_link=data.get("include_ide_link", True),
223261
# fill the default files to include if not present
224262
include_files=data.get(
225263
"include_files",

support/doc_config_schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
},
3131
"menu_weight": {
3232
"type": "integer"
33+
},
34+
"include_ide_link": {
35+
"type": "boolean"
3336
}
3437
},
3538
"required": [

transfer_examples/looping_batched_move/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
= Looping Batched Move
22

3+
link:{flows_ide_link}[Try it out in the Flows IDE.^]
4+
35
[TIP]
46
=====
57
This example is a demonstration of looping in a **flow**.

transfer_examples/move/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
= Move (copy and delete) files
22

3+
link:{flows_ide_link}[Try it out in the Flows IDE.^]
4+
35
== Description
46

57
Perform a 'move' operation on a directory by first transferring from a source to a destination and then deleting from the source.

transfer_examples/simple/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
= Simple Transfer
22

3+
link:{flows_ide_link}[Try it out in the Flows IDE.^]
4+
35
== Description
46

57
Do a single file or directory transfer with a 15 minute time limit.

transfer_examples/transfer_after_approval/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
= Transfer After Approval
22

3+
link:{flows_ide_link}[Try it out in the Flows IDE.^]
4+
35
== Description
46

57
Allow users to submit an approval request to transfer a file to a destination Guest Collection.

transfer_examples/transfer_share/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
= Transfer and Share Files
22

3+
link:{flows_ide_link}[Try it out in the Flows IDE.^]
4+
35
== Description
46

57
Move and share files by transferring them to a Guest Collection.

transfer_examples/two_hop/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
= Two Stage Globus Transfer
22

3+
link:{flows_ide_link}[Try it out in the Flows IDE.^]
4+
35
== Description
46

57
Transfer from source to intermediate and then from intermediate to destination.

0 commit comments

Comments
 (0)