Skip to content

perf: skip plugin loading for version requests#10902

Open
Sean-Kenneth-Doherty wants to merge 1 commit into
python-poetry:mainfrom
Sean-Kenneth-Doherty:perf/version-skips-plugin-loading
Open

perf: skip plugin loading for version requests#10902
Sean-Kenneth-Doherty wants to merge 1 commit into
python-poetry:mainfrom
Sean-Kenneth-Doherty:perf/version-skips-plugin-loading

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

Fixes #10625.

Summary

  • Treat --version and -V like --no-plugins when deciding whether to load application plugins.
  • Keep the change in _load_plugins() instead of adding another fast path to _run().
  • Add regression coverage that asserts plugin discovery/activation is not invoked for both version option spellings.

Tests

  • .venv/bin/python -m pytest tests/console/test_application.py::test_application_version_does_not_load_plugins -q
  • .venv/bin/python -m pytest tests/console/test_application.py -q
  • .venv/bin/python -m pytest tests/console/test_application.py tests/console/test_application_global_options.py -q
  • .venv/bin/python -m poetry --version && .venv/bin/python -m poetry --version --no-plugins
  • .venv/bin/ruff check src/poetry/console/application.py tests/console/test_application.py
  • .venv/bin/ruff format --check src/poetry/console/application.py tests/console/test_application.py
  • .venv/bin/mypy src/poetry/console/application.py tests/console/test_application.py
  • git diff --check

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Overloading _disable_plugins to also cover --version/-V makes the flag semantics less clear; consider introducing a separate local variable or helper (e.g. _should_load_plugins(io)) so that skipping plugins for version requests is explicit and easier to reason about.
  • The has_parameter_option call now takes a list of options; if there are other global options that should also bypass plugin loading in the future, consider centralizing the list (e.g. a constant or method) so it doesn’t become scattered magic values.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Overloading `_disable_plugins` to also cover `--version`/`-V` makes the flag semantics less clear; consider introducing a separate local variable or helper (e.g. `_should_load_plugins(io)`) so that skipping plugins for version requests is explicit and easier to reason about.
- The `has_parameter_option` call now takes a list of options; if there are other global options that should also bypass plugin loading in the future, consider centralizing the list (e.g. a constant or method) so it doesn’t become scattered magic values.

## Individual Comments

### Comment 1
<location path="src/poetry/console/application.py" line_range="627-628" />
<code_context>
             return

-        self._disable_plugins = io.input.has_parameter_option("--no-plugins")
+        self._disable_plugins = io.input.has_parameter_option(
+            ["--no-plugins", "--version", "-V"], only_params=True
+        )

</code_context>
<issue_to_address>
**issue:** Using `only_params=True` changes how `--no-plugins` behaves after `--`, which might be a breaking change.

Previously, `has_parameter_option("--no-plugins")` also matched `--no-plugins` after a `--` argument terminator; with `only_params=True`, those occurrences are now ignored. This risks breaking workflows that disable plugins while forwarding options after `--`. Consider preserving the old behavior for `--no-plugins` (e.g., a separate `has_parameter_option("--no-plugins")` call without `only_params`) while still using `only_params` to avoid loading plugins for `--version` / `-V`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/poetry/console/application.py Outdated
@Sean-Kenneth-Doherty Sean-Kenneth-Doherty force-pushed the perf/version-skips-plugin-loading branch from 0aedbb0 to 427da14 Compare May 17, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

poetry --version is slower than it could be

1 participant