Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77d19bb

Browse files
authored
Merge pull request #17 from gvwilson/mkdocs-conversion
feat: allow `--schema path` option to code generation
2 parents 4154910 + df9cc3a commit 77d19bb

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

‎bin/codegen/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
from pathlib import Path
34
import shutil
45
import sys
56

@@ -27,6 +28,11 @@
2728
)
2829

2930

31+
PROJECT_ROOT = Path(__file__).parent.parent.parent
32+
PLOT_SCHEMA_RELATIVE = Path("resources") / "plot-schema.json"
33+
PLOT_SCHEMA = PROJECT_ROOT / PLOT_SCHEMA_RELATIVE
34+
35+
3036
# Import notes
3137
# ------------
3238
# Nothing from the plotly/ package should be imported during code
@@ -94,7 +100,7 @@ def make_paths(codedir):
94100
return validators_dir, graph_objects_dir, graph_objs_path
95101

96102

97-
def perform_codegen(codedir, noformat=False):
103+
def perform_codegen(codedir, noformat=False, schema=PLOT_SCHEMA):
98104
"""Generate code."""
99105

100106
# Get paths
@@ -108,8 +114,7 @@ def perform_codegen(codedir, noformat=False):
108114

109115
# Load plotly schema
110116
project_root = codedir.parent
111-
plot_schema_path = project_root / "resources" / "plot-schema.json"
112-
with open(plot_schema_path, "r") as f:
117+
with open(schema, "r") as f:
113118
plotly_schema = json.load(f)
114119

115120
# Preprocess Schema
@@ -284,7 +289,9 @@ def __getattr__(import_name):
284289
init_extra = optional_figure_widget_import
285290
else:
286291
init_extra = ""
287-
write_init_py(graph_objects_pkg, path_parts, rel_modules, rel_classes, init_extra)
292+
write_init_py(
293+
graph_objects_pkg, path_parts, rel_modules, rel_classes, init_extra
294+
)
288295

289296
# Output graph_objs.py alias
290297
graph_objs_rel_classes = [
@@ -303,7 +310,7 @@ def __getattr__(import_name):
303310
)
304311
graph_objs_path = codedir / "graph_objs"
305312
graph_objs_path.mkdir(parents=True, exist_ok=True)
306-
graph_objs_path /= "__init__.py"
313+
graph_objs_path /= "__init__.py"
307314
with open(graph_objs_path, "wt") as f:
308315
f.write("# ruff: noqa: F401\n")
309316
f.write(graph_objs_init_source)

‎bin/generate_code.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ def main():
1111

1212
args = parse_args()
1313
codedir = utils.select_code_directory(args)
14-
utils.perform_codegen(codedir, noformat=args.noformat)
14+
utils.perform_codegen(codedir, noformat=args.noformat, schema=args.schema)
1515

1616

1717
def parse_args():
1818
"""Parse command-line arguments."""
1919

2020
parser = argparse.ArgumentParser()
21-
parser.add_argument("--noformat", action="store_true", help="prevent reformatting")
2221
parser.add_argument("--codedir", type=Path, help="code directory")
22+
parser.add_argument("--noformat", action="store_true", help="prevent reformatting")
23+
parser.add_argument(
24+
"--schema",
25+
type=Path,
26+
default=utils.PLOT_SCHEMA,
27+
help=f"schema file (default {utils.PLOT_SCHEMA})",
28+
)
2329
return parser.parse_args()
2430

2531

‎bin/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
import logging
44
import json
55
import os
6-
from pathlib import Path
76
import platform
87
import requests
98
import shutil
109
from subprocess import check_call
1110
import sys
1211
import time
1312

14-
from codegen import perform_codegen
15-
13+
from codegen import (
14+
perform_codegen,
15+
PROJECT_ROOT,
16+
PLOT_SCHEMA,
17+
)
1618

1719
LOGGER = logging.getLogger(__name__)
18-
PROJECT_ROOT = Path(__file__).parent.parent
1920
NODE_ROOT = PROJECT_ROOT / "js"
2021
NODE_MODULES = NODE_ROOT / "node_modules"
21-
PLOT_SCHEMA = PROJECT_ROOT / "resources" / "plot-schema.json"
2222
WIDGET_TARGETS = [PROJECT_ROOT / "plotly" / "package_data" / "widgetbundle.js"]
2323
NPM_PATH = os.pathsep.join(
2424
[

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /