summaryrefslogtreecommitdiffstats
path: root/toolkit/components/glean/sphinx/glean.py
blob: fb11dacb6ecf46a2296e271b85122718ebfc22ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
from pathlib import Path
import sys


def setup(app):
    from moztreedocs import manager

    # Import the list of metrics and ping files
    glean_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
    sys.path.append(glean_dir)
    from metrics_index import metrics_yamls, pings_yamls

    # Import the custom version expiry code.
    glean_parser_ext_dir = os.path.abspath(
        Path(glean_dir) / "build_scripts" / "glean_parser_ext"
    )
    sys.path.append(glean_parser_ext_dir)
    from run_glean_parser import get_parser_options

    firefox_version = "4.0a1"  # TODO: bug 1676416 - Get the real app version.
    parser_config = get_parser_options(firefox_version)

    input_files = [Path(os.path.join(manager.topsrcdir, x)) for x in metrics_yamls]
    input_files += [Path(os.path.join(manager.topsrcdir, x)) for x in pings_yamls]

    # Generate the autodocs.
    from glean_parser import translate

    out_path = Path(os.path.join(manager.staging_dir, "metrics"))
    translate.translate(
        input_files, "markdown", out_path, {"project_title": "Firefox"}, parser_config
    )

    # Rename the generated docfile to index so Sphinx finds it
    os.rename(os.path.join(out_path, "metrics.md"), os.path.join(out_path, "index.md"))