Skip to content

docs: don't abort the docs build when BUILD_PREVIEW/BUILD_LATEST is set but empty - #2567

Open
LeSingh1 wants to merge 1 commit into
NVIDIA:mainfrom
LeSingh1:docs-conf-env-flag
Open

docs: don't abort the docs build when BUILD_PREVIEW/BUILD_LATEST is set but empty#2567
LeSingh1 wants to merge 1 commit into
NVIDIA:mainfrom
LeSingh1:docs-conf-env-flag

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Problem

Both Sphinx configs read the two docs-build flags with a bare int():

# cuda_core/docs/source/conf.py  (6 call sites)
# cuda_python/docs/source/conf.py (4 call sites)
if int(os.environ.get("BUILD_PREVIEW", 0)):
    ...

os.environ.get(name, default) returns the empty string, not the default, when a variable is exported but empty. And the build scripts that drive these configs already treat that state as "not set":

# cuda_core/docs/build_docs.sh:27, cuda_python/docs/build_docs.sh:28
if [[ "${LATEST_ONLY}" == "1" && -z "${BUILD_PREVIEW:-}" && -z "${BUILD_LATEST:-}" ]]; then
    export BUILD_LATEST=1
fi

-z is explicit: empty means unset. Then conf.py disagrees and raises:

$ BUILD_PREVIEW= ./build_docs.sh latest-only
  File ".../docs/source/conf.py", line 33, in _github_examples_ref
    if int(os.environ.get("BUILD_PREVIEW", 0)) or int(os.environ.get("BUILD_LATEST", 0)):
ValueError: invalid literal for int() with base 10: ''

That kills the docs build from inside conf.py, before any page is rendered. Measured against the exact expression on main:

BUILD_PREVIEW result on main
unset False
"1" True
"0" False
"" ValueError
" " ValueError
"true" ValueError

BUILD_PREVIEW / BUILD_LATEST are set to "1" by .github/actions/get_pr_number, so CI does not hit this today — it bites anyone driving the scripts by hand or from a wrapper that exports the variable unconditionally, which is precisely the case build_docs.sh wrote a -z test for.

Fix

Add an _env_flag helper to each config and route all ten call sites through it. Unset, empty, whitespace-only and "0" are false; any other value is true, so BUILD_LATEST=true is honoured rather than aborting the build. Integer values keep their exact current meaning.

The helper is duplicated across the two configs deliberately — they already duplicate _html_baseurl between them, and a shared module would mean restructuring cuda_python/docs/exts/, which is more churn than this warrants.

Verification

conf.py has no test home in this repo (nothing imports or exercises either file outside a Sphinx run), so this ships without a unit test — I want to be explicit about that rather than invent a contrived one. What I did verify:

  • Extracted _env_flag from each committed config via AST and exercised it directly, then reverted both files to upstream/main and ran the same probe against the original expression:
--- WITH FIX (HEAD) ---
  cuda_core    ''->False  '  '->False  'true'->True
  cuda_python  ''->False  '  '->False  'true'->True
--- upstream/main ---
  cuda_core    ''->ValueError  '  '->ValueError  'true'->ValueError
  cuda_python  ''->ValueError  '  '->ValueError  'true'->ValueError
  • ruff check / ruff format --check and python -m py_compile clean on both files.
  • The revert/restore ran commit-first: the fix was committed, the files reverted from upstream/main for the probe, then restored with git restore --source=HEAD --worktree, wrapped in try/finally. git diff --cached and git diff both empty afterwards.

If you would rather have this as a shared helper under cuda_python/docs/exts/ with a test, say the word and I will restructure it.

…mpty

Both Sphinx configs read the two docs-build flags with a bare int():

    if int(os.environ.get("BUILD_PREVIEW", 0)):

os.environ.get returns the empty string, not the default, when a variable is
exported but empty -- and the build scripts that drive these configs already
treat that state as "not set":

    # cuda_core/docs/build_docs.sh, cuda_python/docs/build_docs.sh
    if [[ "${LATEST_ONLY}" == "1" && -z "${BUILD_PREVIEW:-}" && -z "${BUILD_LATEST:-}" ]]; then
        export BUILD_LATEST=1
    fi

So the shell layer says empty means unset, then conf.py raises on it:

    ValueError: invalid literal for int() with base 10: ''

taking down the whole docs build from inside conf.py, before any page is
rendered. `BUILD_PREVIEW= ./build_docs.sh latest-only` is enough to hit it.

Add an _env_flag helper to each config and route all ten call sites through
it (six in cuda_core, four in cuda_python). Unset, empty, whitespace-only and
"0" are all false; any other value is true, so a non-numeric spelling such as
BUILD_LATEST=true is honoured rather than aborting the build.

The helper is duplicated across the two configs deliberately, matching the
existing duplication of _html_baseurl between them.
@copy-pr-bot

copy-pr-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant