Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poetry can get locked into an unusable state with plugins: 'The command "..." already exists' #6456

Open
3 tasks done
mtkennerly opened this issue Sep 8, 2022 · 2 comments
Labels
area/plugin-api Related to plugins/plugin API kind/bug Something isn't working as expected status/confirmed Issue is reproduced and confirmed version/1.2.0

Comments

@mtkennerly
Copy link

mtkennerly commented Sep 8, 2022

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Windows 11
  • Poetry version: 1.2.0
  • Link of a Gist with the contents of your pyproject.toml file: N/A

Issue

If plugins with conflicting commands are installed, Poetry gets locked into an unusable state where even --help fails, and there's no way to recover unless you manually activate Poetry's internal venv and remove the plugins. Someone reported this to me because I had a plugin called poetry-dynamic-versioning-plugin that I've since deprecated and merged into poetry-dynamic-versioning[plugin]. If you still have the deprecated one installed and then install the newly updated one, it breaks Poetry.

$ poetry self add poetry-dynamic-versioning-plugin
Using version ^0.4.0 for poetry-dynamic-versioning-plugin

Updating dependencies
Resolving dependencies... (0.5s)

Writing lock file

Package operations: 4 installs, 0 updates, 0 removals

  • Installing markupsafe (2.1.1)
  • Installing dunamai (1.13.0)
  • Installing jinja2 (3.1.2)
  • Installing poetry-dynamic-versioning-plugin (0.4.0)

$ poetry self add poetry-dynamic-versioning[plugin]
Using version ^0.18.0 for poetry-dynamic-versioning

Updating dependencies
Resolving dependencies... (0.2s)

Writing lock file

Package operations: 1 install, 0 updates, 0 removals

  • Installing poetry-dynamic-versioning (0.18.0)

$ poetry --help

The command "dynamic-versioning" already exists.

With debug mode:

$ poetry --help -vvv

  Stack trace:

  5  ~\.local\pipx\venvs\poetry\lib\site-packages\cleo\application.py:329 in run
      327│
      328│             try:
    → 329│                 exit_code = self._run(io)
      330│             except Exception as e:
      331│                 if not self._catch_exceptions:

  4  ~\.local\pipx\venvs\poetry\lib\site-packages\poetry\console\application.py:183 in _run
      181│         self._disable_cache = io.input.has_parameter_option("--no-cache")
      182│
    → 183│         self._load_plugins(io)
      184│
      185│         exit_code: int = super()._run(io)

  3  ~\.local\pipx\venvs\poetry\lib\site-packages\poetry\console\application.py:349 in _load_plugins
      347│             manager = PluginManager(ApplicationPlugin.group)
      348│             manager.load_plugins()
    → 349│             manager.activate(self)
      350│
      351│         self._plugins_loaded = True

  2  ~\.local\pipx\venvs\poetry\lib\site-packages\poetry\plugins\plugin_manager.py:71 in activate
       69│     def activate(self, *args: Any, **kwargs: Any) -> None:
       70│         for plugin in self._plugins:
    →  71│             plugin.activate(*args, **kwargs)
       72│
       73│     def _load_plugin_entry_point(self, ep: metadata.EntryPoint) -> None:

  1  ~\.local\pipx\venvs\poetry\lib\site-packages\poetry_dynamic_versioning\plugin.py:93 in activate
       91│         self._application = application
       92│
    →  93│         application.command_loader.register_factory(
       94│             "dynamic-versioning", lambda: DynamicVersioningCommand(application)
       95│         )

  LogicException

  The command "dynamic-versioning" already exists.

  at ~\.local\pipx\venvs\poetry\lib\site-packages\poetry\console\command_loader.py:20 in register_factory
       16│     def register_factory(
       17│         self, command_name: str, factory: Callable[[], Command]
       18│     ) -> None:
       19│         if command_name in self._factories:
    →  20│             raise LogicException(f'The command "{command_name}" already exists.')
       21│
       22│         self._factories[command_name] = factory
       23│
@mtkennerly mtkennerly added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Sep 8, 2022
@neersighted neersighted added area/plugin-api Related to plugins/plugin API status/confirmed Issue is reproduced and confirmed version/1.2.0 and removed status/triage This issue needs to be triaged labels Sep 8, 2022
@scatt-nasuni
Copy link

Some additional information:

This bug happens when running poetry self add poetry-dynamic-versioning[plugin] by itself. It seems that the installer installs the following packages, which creates the conflict:

foo@bar ~ % poetry self add "poetry-dynamic-versioning[plugin]"
Using version ^0.21.1 for poetry-dynamic-versioning

Updating dependencies
Resolving dependencies... (0.2s)

Package operations: 5 installs, 11 updates, 0 removals

  • Updating certifi (2022.9.24 -> 2022.6.15)
  • Updating charset-normalizer (2.1.1 -> 2.1.0)
  • Updating idna (3.4 -> 3.3)
  • Updating urllib3 (1.26.13 -> 1.26.11)
  • Updating distlib (0.3.6 -> 0.3.5)
  • Updating filelock (3.8.2 -> 3.7.1)
  • Updating platformdirs (2.6.0 -> 2.5.2)
  • Updating keyring (23.11.0 -> 23.7.0)
  • Installing markupsafe (2.1.1)
  • Updating pkginfo (1.9.2 -> 1.8.3)
  • Updating tomlkit (0.11.6 -> 0.11.1)
  • Updating virtualenv (20.17.1 -> 20.16.0)
  • Installing dunamai (1.15.0)
  • Installing jinja2 (3.1.2)
  • Installing poetry-dynamic-versioning (0.21.1) # THIS ONE IS CORRECT
  • Installing poetry-dynamic-versioning-plugin (0.3.2) # THIS ONE IS DEPRECATED
foo@bar ~ % poetry self show plugins

The command "dynamic-versioning" already exists.

The final two packages install the same command. the -plugin version is deprecated, I believe. I'm not sure if this is a problem with poetry or the plugin itself. However, navigating to the site-package folder of the poetry installation and manually remove the poetry_dynamic_versioning_plugin-0.3.2.dist-info directory does resolve the issue (as a workaround). I have not tested to verify that the plugin still functions after doing this.

@mtkennerly
Copy link
Author

mtkennerly commented Dec 7, 2022

@scatt-nasuni Depending on how you uninstalled the deprecated version of the plugin, it might still be in Poetry's internal pyproject/lock file, causing it to be reinstalled whenever you do a new poetry self add. On Windows, this would be the pyproject/lock file in %APPDATA%\pypoetry. I think I remember running into that while developing the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/plugin-api Related to plugins/plugin API kind/bug Something isn't working as expected status/confirmed Issue is reproduced and confirmed version/1.2.0
Projects
None yet
Development

No branches or pull requests

3 participants