alan-turing-institute / bio-Turing-Way

Experimenting with JupyterBooks, Sphinx, and training materials for biomed/life sciences from the Turing Way.
https://the-turing-way-personas.netlify.app/welcome
Other
4 stars 5 forks source link

Explore program flow #5

Closed myyong closed 2 years ago

myyong commented 2 years ago

In main.py we enter using the Build Project branch of the if statement:

if not PATH_SRC_FOLDER.is_dir():
        # it is a single file
    # Build Project
    else:
        print("Build Project: ",PATH_SRC_FOLDER.is_dir())
        build_type = "book"
        PAGE_NAME = None
        BUILD_PATH = Path(BUILD_PATH).joinpath("_build")
        :
myyong commented 2 years ago

We call Sphinx in main.py

result = build_sphinx(
        PATH_SRC_FOLDER,
        OUTPUT_PATH,
        use_external_toc=use_external_toc,
        noconfig=True,
        path_config=path_config,
        confoverrides=config_overrides,
        builder=BUILDER_OPTS[builder],
        warningiserror=warningiserror,
        keep_going=keep_going,
        freshenv=freshenv,
        verbosity=verbose,
        quiet=quiet > 0,
        really_quiet=quiet > 1,
    )

This triggers the instantiation of the Sphinx app in sphinx.py:

app = Sphinx(
                srcdir=sourcedir,
                confdir=confdir,
                outdir=outputdir,
                doctreedir=doctreedir,
                buildername=builder,
                confoverrides=sphinx_config,
                status=status,
                warning=warning,
                freshenv=freshenv,
                warningiserror=warningiserror,
                tags=tags,
                verbosity=verbosity,
                parallel=jobs,
                keep_going=keep_going,
            )

After some stuff, the function build_sphinx returns a status code which, in main.py is referred to as result.

myyong commented 2 years ago

Once we have the Sphinx object we go into builder_specific_actions back in main.py We check the config to see that

MY: builder is set to: html MY: cmd_type is set to: book

So we end up in this branch:

elif cmd_type == "book":
            path_output_rel = Path(op.relpath(output_path, Path()))
            path_index = path_output_rel.joinpath("index.html")
            _message_box(
                f"""\
            Finished generating HTML for {cmd_type}.
            Your book's HTML pages are here:
                {path_output_rel}{os.sep}
            You can look at your book by opening this file in a browser:
                {path_index}
            Or paste this line directly into your browser bar:
                file://{path_index.resolve()}\
            """
            )