Skip to content

Commit c3110e5

Browse files
committed
feat(tools): add a retry tool for launcher
1 parent e89182a commit c3110e5

4 files changed

Lines changed: 84 additions & 20 deletions

File tree

docs/api/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Welcome to Trame's documentation!
4040

4141
tools.www
4242
tools.app
43+
tools.retry
4344
tools.widgets
4445
tools.serve
4546
tools.vtk

docs/api/source/tools.retry.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Update launcher retry array
2+
==============================
3+
4+
This small utility let you run a command line to update an existing HTML file
5+
with a new launcher-retry content.
6+
7+
In order to use that tool, you will need to provide the path of the base
8+
application to use as template along with the content of the launcher-retry.
9+
This tool will then update the HTML file provided.
10+
11+
12+
.. code-block:: bash
13+
14+
python -m trame.tools.retry --input ./www-content/index.html --retry "[3000, 2000, 1000]"
15+
# => Update ./www-content/index.html using data-launcher-retry="[3000, 2000, 1000]" instead of the default empty array.

pyproject.toml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
name = "trame"
33
version = "3.11.0"
44
description = "Trame, a framework to build applications in plain Python"
5-
authors = [
6-
{name = "Kitware Inc."},
7-
]
5+
authors = [{ name = "Kitware Inc." }]
86
dependencies = [
97
"trame-server>=3.4,<4",
10-
"trame-client>=3.8,<4",
8+
"trame-client>=3.10.1,<4",
119
"trame-common>=1,<2",
1210
"wslink>=2.3.3",
13-
"pyyaml", # for trame.tools.widgets
11+
"pyyaml", # for trame.tools.widgets
1412
]
1513
requires-python = ">=3.9"
1614
readme = "README.rst"
17-
license = {text = "Apache License 2.0"}
15+
license = { text = "Apache License 2.0" }
1816
keywords = ["Python", "Interactive", "Web", "Application", "Framework"]
1917
classifiers = [
2018
"Development Status :: 5 - Production/Stable",
@@ -28,17 +26,9 @@ classifiers = [
2826
]
2927

3028
[project.optional-dependencies]
31-
app = [
32-
"pywebview",
33-
]
34-
jupyter = [
35-
"jupyterlab",
36-
]
37-
dev = [
38-
"pre-commit",
39-
"ruff",
40-
"pytest",
41-
]
29+
app = ["pywebview"]
30+
jupyter = ["jupyterlab"]
31+
dev = ["pre-commit", "ruff", "pytest"]
4232

4333
[build-system]
4434
requires = ['setuptools', 'wheel']
@@ -51,9 +41,7 @@ where = ["."]
5141

5242

5343
[tool.semantic_release]
54-
version_toml = [
55-
"pyproject.toml:project.version",
56-
]
44+
version_toml = ["pyproject.toml:project.version"]
5745
build_command = """
5846
python -m venv .venv
5947
source .venv/bin/activate

trame/tools/retry.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
r"""
2+
From the directory containing the static content for a trame application to work,
3+
generate another application specific HTML file.
4+
"""
5+
6+
import argparse
7+
import re
8+
import sys
9+
from pathlib import Path
10+
11+
RETRY_PATTERN = re.compile(r'data-launcher-retry=".+"')
12+
13+
14+
def update_retry_file(input_file, output_file, retry_array):
15+
# Read in the file
16+
with open(input_file, "r") as f_in:
17+
content = f_in.read()
18+
patched_content = RETRY_PATTERN.sub(
19+
f'data-launcher-retry="{retry_array}"', content
20+
)
21+
with open(output_file, "w") as f_out:
22+
f_out.write(patched_content)
23+
24+
25+
def main():
26+
parser = argparse.ArgumentParser(
27+
description="HTML app file generator for trame applications"
28+
)
29+
30+
parser.add_argument(
31+
"--retry",
32+
default="[]",
33+
help="Retry array for launcher. Times are in ms.",
34+
)
35+
36+
parser.add_argument(
37+
"--input",
38+
help="Input file to use as template",
39+
)
40+
41+
args, _ = parser.parse_known_args()
42+
43+
# Handle input
44+
input_file = Path(args.input)
45+
if not input_file.exists():
46+
parser.print_help()
47+
sys.exit(0)
48+
49+
if input_file.is_dir():
50+
input_file = input_file / "index.html"
51+
52+
if not input_file.exists():
53+
parser.print_help()
54+
sys.exit(0)
55+
56+
update_retry_file(input_file, input_file, args.retry)
57+
58+
59+
if __name__ == "__main__":
60+
main()

0 commit comments

Comments
 (0)