Skip to content

doc: fix autogenerated Python examples for required options without defaults#6987

Open
sakirr05 wants to merge 1 commit intoOSGeo:mainfrom
sakirr05:fix-doc-python-example-required-options
Open

doc: fix autogenerated Python examples for required options without defaults#6987
sakirr05 wants to merge 1 commit intoOSGeo:mainfrom
sakirr05:fix-doc-python-example-required-options

Conversation

@sakirr05
Copy link
Contributor

@sakirr05 sakirr05 commented Jan 28, 2026

Fixes #5580.

Improves autogenerated Python documentation examples for required options
with multiple valid values but no default.

The documentation generator now selects the first valid option instead of
using a placeholder string, ensuring Python examples are runnable.
This change only affects documentation generation.

before change

    // Get example value from allowed values, but only for
    // strings because numbers may have ranges...
    char **tokens;
    tokens = G_tokenize(opt->options, delm);
    if (tokens[0]) {
        value = G_store(tokens[0]);
    }
}

after change

    // Get example value from allowed values...
    char **tokens;
    tokens = G_tokenize(opt->options, delm);
    if (tokens[0] && tokens[0][0] != '\0') {  // ← Better check!
        if (opt->type == TYPE_STRING) {        // ← Guaranteed!
            value = G_store(tokens[0]);
        }
    }
}

@sakirr05 sakirr05 force-pushed the fix-doc-python-example-required-options branch from 0d9f65f to 2b44912 Compare January 28, 2026 12:17
@wenzeslaus
Copy link
Member

Please add screenshots before and after the change.

Also, no need to use new PRs, updating the branch is usually enough (looking at your previous PR).

@github-actions github-actions bot added C Related code is in C libraries labels Jan 28, 2026
@sakirr05
Copy link
Contributor Author

Hi @wenzeslaus,
Thanks for the feedback. I've added code screenshots showing the before/after changes in lib/gis/parser_md_python.c.
Note on the screenshots:
I provided code screenshots (showing the code changes) rather than output screenshots because when running v.generalize --md-description on both upstream/main and this branch, both correctly generate method="douglas" in the Python example. The output is identical, so output screenshots wouldn't show the difference.

@wenzeslaus
Copy link
Member

Please clarify how this relates to the issue this is claiming to fix? I'm reluctant to merge just a code reshuffle.

@sakirr05
Copy link
Contributor Author

hey @wenzeslaus
When an option is required, has multiple valid choices, and no default, the autogenerated Python example currently falls back to an invalid placeholder (like method="string"), which can be confusing when copying the example.

This change makes sure a valid option is used instead, so the generated example reflects a real, runnable invocation rather than a placeholder.

@wenzeslaus
Copy link
Member

Can you please show a screenshot of the build documentation in the state before and after?

@sakirr05
Copy link
Contributor Author

sakirr05 commented Jan 31, 2026

hey @wenzeslaus here's the comparison

**BEFORE **
image

**AFTER **
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] doc: improve python example when a required parameter has multiple options but no default

2 participants