Skip to content

fix(cli): correct external plugin discovery - #4676

Open
M-Hassan-Raza wants to merge 9 commits into
docling-project:mainfrom
M-Hassan-Raza:fix/plugin-cli-discovery
Open

M-Hassan-Raza wants to merge 9 commits into
docling-project:mainfrom
M-Hassan-Raza:fix/plugin-cli-discovery

Conversation

@M-Hassan-Raza

@M-Hassan-Raza M-Hassan-Raza commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to the focused CLI fixes suggested in #3878.

Discover plugins after parsing the conversion policy, include picture-description engines in the plugin listing, and show each provider's distribution name. Fill default format options and apply the policy before constructing the converter, while preserving existing factory method signatures. Help no longer discovers plugins or lists built-in engine names; the generated CLI reference reflects that change.

230 targeted tests and changed-file checks pass locally. The full model-dependent suite was not run locally.

Signed-off-by: Hassan Raza <raihassanraza10@gmail.com>
Signed-off-by: Hassan Raza <raihassanraza10@gmail.com>
Signed-off-by: Hassan Raza <raihassanraza10@gmail.com>
Signed-off-by: Hassan Raza <raihassanraza10@gmail.com>
Signed-off-by: Hassan Raza <raihassanraza10@gmail.com>
Signed-off-by: Hassan Raza <raihassanraza10@gmail.com>
Signed-off-by: Hassan Raza <raihassanraza10@gmail.com>
Signed-off-by: Hassan Raza <raihassanraza10@gmail.com>
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @M-Hassan-Raza, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) CLI issues related to the command line interface (CLI) enhancement New feature or request error-handling labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 8ec4f69f93. The analysis read the diff only. It did not run code from this pull request.

Fixes external plugin discovery in the CLI: moves plugin loading after argument parsing, adds picture-description engines to `--show-external-plugins`, stores each plugin's distribution name in `FactoryMeta`, propagates `allow_external_plugins` to all format options before constructing `DocumentConverter`, and removes module-import-time factory construction that caused `--help` to load plugins.

CI safety: needs maintainer care before you approve CI.

  • tests/test_factory_plugins.py: The new `_run_cli` helper calls `subprocess.run` with `sys.executable` and passes `**os.environ` to the subprocess, which exposes all CI environment variables (including any secrets) to the child process.
3 related pull request(s) in the same code
PR State Signal Assessment
#4729 open changes the same code related: PR 4729 adds CLI metavar formatting and a `--rapidocr-model-size` option to the same `convert` command. It still depends on the `*_enum_internal` variables that this PR removes. The two PRs modify overlapping lines but solve different problems.
#4560 open changes the same code related: PR 4560 adds progress bars to the CLI and touches the same `convert` function, but it does not change plugin discovery logic. The two PRs are independent features that both edit `docling/cli/main.py`.
#3878 closed referenced as #3878 related: PR 3878 is the earlier closed draft by the same author that this PR explicitly follows up on. Both fix the same plugin-discovery problem, but PR 3878 takes a different approach (a separate `plugin_registry` module and broader `BaseFactory` refactor), while this PR uses a smaller, targeted change. They address the same root cause but are not identical in implementation.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@M-Hassan-Raza M-Hassan-Raza changed the title Fix CLI external plugin discovery fix(cli): correct external plugin discovery Oct 8, 2026
@dolfim-ibm
dolfim-ibm self-requested a review October 9, 2026 06:43
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.69231% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/cli/main.py 31.25% 10 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@dolfim-ibm dolfim-ibm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is right, and the new subprocess tests in tests/test_factory_plugins.py fail on main for the expected reasons. One change requested before merge.

Apply the plugin policy before building the converter, not after.

The loop that sets allow_external_plugins currently runs on doc_converter.format_to_options after DocumentConverter(...) returns. Because of that, every fake converter in tests/test_cli.py and tests/test_ocr_language.py now needs self.format_to_options = format_options: 15 edits that only exist to support the post-construction mutation.

The CLI already knows the full format list: _expand_from_formats returns list(InputFormat) when --from is not given. So the default options can be filled in and the policy applied on the dict that is passed to the converter:

# Apply the CLI policy to every allowed format, including defaults.
for input_format in from_formats:
    if input_format not in format_options:
        format_options[input_format] = _get_default_option(input_format)
for format_option in format_options.values():
    if format_option.pipeline_options is not None:
        format_option.pipeline_options.allow_external_plugins = allow_external_plugins

doc_converter = DocumentConverter(
    allowed_formats=from_formats,
    format_options=format_options,
)

The behavior stays the same: DocumentConverter.__init__ calls _get_default_option for each missing format anyway, and FormatOption.set_optional_field_default fills pipeline_options at creation. The fakes then receive a larger format_options dict. The existing assertions only read specific keys (PDF, IMAGE, AUDIO, VIDEO) and none checks that a key is absent, so the self.format_to_options = format_options edits in both test files can be reverted. test_cli_plugin_discovery still covers the default-format case end to end.

Signed-off-by: Hassan Raza <raihassanraza10@gmail.com>
@github-actions github-actions Bot added ai:ci-needs-care AI triage: check CI-safety findings before you approve CI and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Oct 12, 2026
@M-Hassan-Raza

Copy link
Copy Markdown
Contributor Author

@dolfim-ibm Please check now should be good hopefully

This branch has not been deployed

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

Labels

ai:ci-needs-care AI triage: check CI-safety findings before you approve CI CLI issues related to the command line interface (CLI) enhancement New feature or request error-handling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants