Skip to content

Commit e726066

Browse files
fix command line argument for live_preview (#15)
1 parent 300b13f commit e726066

2 files changed

Lines changed: 10 additions & 33 deletions

File tree

src/extensions/score_source_code_linker/__init__.py

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,27 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
import json
14-
import os
1514
from copy import deepcopy
1615
from pathlib import Path
17-
from pprint import pprint
1816

19-
from src.extensions.score_source_code_linker.parse_source_files import GITHUB_BASE_URL
2017
from sphinx.application import Sphinx
2118
from sphinx.environment import BuildEnvironment
2219
from sphinx_needs.data import SphinxNeedsData
2320
from sphinx_needs.logging import get_logger
2421

22+
from src.extensions.score_source_code_linker.parse_source_files import GITHUB_BASE_URL
23+
2524
LOGGER = get_logger(__name__)
2625
LOGGER.setLevel("DEBUG")
2726

2827

2928
def setup(app: Sphinx) -> dict[str, str | bool]:
3029
# Extension: score_source_code_linker
31-
app.add_config_value("disable_source_code_linker", False, rebuild="env")
32-
app.add_config_value("score_source_code_linker_file_overwrite", "", rebuild="env")
3330
# TODO: can we detect live_preview & esbonio here? Until then we have a flag:
31+
app.add_config_value("disable_source_code_linker", False, rebuild="env", types=bool)
32+
app.add_config_value(
33+
"score_source_code_linker_file_overwrite", "", rebuild="env", types=str
34+
)
3435

3536
# Define need_string_links here to not have it in conf.py
3637
app.config.needs_string_links = {
@@ -73,40 +74,17 @@ def add_source_link(app: Sphinx, env: BuildEnvironment) -> None:
7374
Needs_Data = SphinxNeedsData(env)
7475
needs = Needs_Data.get_needs_mutable()
7576
needs_copy = deepcopy(needs)
76-
# bazel-out/k8-fastbuild/bin/process-docs/incremental.runfiles/_main/process-docs/score_source_code_parser.json
77-
# bazel-out/k8-fastbuild/bin/process-docs/incremental.runfiles/_main/tooling/extensions/score_source_code_linker/__init__.py
78-
# bazel-out/k8-fastbuild/bin/process-docs/score_source_code_parser.json
79-
# /home/vscode/.cache/bazel/_bazel_vscode/6084288f00f33db17acb4220ce8f1999/execroot/_main/bazel-out/k8-fastbuild/bin/process-docs/incremental.runfiles/score_source_code_parser.json
80-
#
81-
82-
## -> build:
83-
84-
# bazel-out/k8-opt-exec-ST-d57f47055a04/bin/tooling/sphinx_build.runfiles/_main/tooling/extensions/score_source_code_linker/__init__.py
85-
86-
# Tried with build
87-
# bazel-out/k8-fastbuild/bin/process-docs/_docs/_sources/process-docs/score_source_code_parser.json
88-
89-
# SEARCHING:
90-
# bazel-out/k8-opt-exec-ST-d57f47055a04/bin/process-docs/score_source_code_parser.json
9177
p5 = Path(__file__).parents[5]
9278

93-
# bazel-out/k8-opt-exec-ST-d57f47055a04/bin/tooling
94-
# LOGGER.info("DEBUG: ============= CONF DIR===========")
95-
# LOGGER.info(f"DEBUG: {Path(app.confdir).name}")
96-
# LOGGER.info("DEBUG: =============================")
9779
if str(p5).endswith("src"):
9880
LOGGER.info("DEBUG: WE ARE IN THE IF")
9981
path = str(p5.parent / Path(app.confdir).name / "score_source_code_parser.json")
10082
else:
10183
LOGGER.info("DEBUG: WE ARE IN THE ELSE")
10284
path = str(p5 / "score_source_code_parser.json")
103-
# LOGGER.info("DEBUG============= FILE PATH OF JSON (where we search)===========")
104-
# LOGGER.info(f"DEBUG: {path}")
105-
# LOGGER.info("DEBUG: =============================")
85+
10686
if app.config.score_source_code_linker_file_overwrite:
10787
path = app.config.score_source_code_linker_file_overwrite
108-
# json_paths = [str(Path(__file__).parent.parent.parent.parent.parent.parent/"score_source_code_parser.json")]
109-
# json_paths = [app.config.source_code_linker_file]
11088

11189
try:
11290
with open(path) as f:

src/incremental.py

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

1414
import argparse
15+
import json
1516
import logging
1617
import os
17-
import json
18-
from typing import Any
1918

2019
import debugpy
21-
2220
from sphinx.cmd.build import main as sphinx_main
2321
from sphinx_autobuild.__main__ import main as sphinx_autobuild_main
2422

@@ -92,7 +90,8 @@ def transform_env_str_to_dict(external_needs_source: str) -> list[dict[str, str]
9290
action = get_env("ACTION")
9391
if action == "live_preview":
9492
sphinx_autobuild_main(
95-
base_arguments + ["--define=disable_source_code_linker=True"]
93+
# Note: bools need to be passed via '0' and '1' from the command line.
94+
base_arguments + ["--define=disable_source_code_linker=1"]
9695
)
9796
else:
9897
sphinx_main(base_arguments)

0 commit comments

Comments
 (0)