poetry icon indicating copy to clipboard operation
poetry copied to clipboard

`poetry.exe` in `.venv\Scripts` Conflicts with Global Install

Open adam-grant-hendry opened this issue 2 years ago • 7 comments

  • Poetry version: 1.5.1
  • Python version: 3.8.10
  • OS version and name: Windows 10 22H2
  • pyproject.toml: N/A
  • [x] I am on the latest stable Poetry version, installed using a recommended method.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have consulted the FAQ and blog for any relevant entries or release notes.
  • [x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

When creating a plugin, some poetry internals are needed:

# Generic plugin
from poetry.plugins.plugin import Plugin
from poetry.poetry import Poetry

# Application plugin
from poetry.plugins.application_plugin import ApplicationPlugin

My plugin project has a local virtual environment in .venv/. When adding poetry as a dependency:

poetry add poetry

the script poetry.exe (on Windows) is added to .venv\Scripts, which conflicts with the default binary (using pipx, this is %USERPROFILE%\.local\bin\poetry.exe).

e.g. When using another plugin for development, say poetry-plugin-sort,

pipx inject poetry poetry-plugin-sort

installs to the plugin to the default binary so that the plugin cannot be used in the virtual environment. Running poetry sort results in

The command "sort" does not exist.

Deleting the binary from .venv\Scripts temporarily solves the problem, but the binary is re-added to Scripts when poetry update updates poetry to a new version.

adam-grant-hendry avatar Aug 13 '23 21:08 adam-grant-hendry

what do you propose should be done? Both poetrys are supposed to be there!

If you want to use either one or the other then you had better say which one (or set up your path accordingly). But whichever choice you are making at any given moment, someone else - or future-you - might prefer the other for whatever they happen to be doing.

(similar occasionally happens when working on the poetry codebase: I have my regular poetry installation, but while in the poetry development venv I also have that poetry. If I want the "other" one I type the full path).

Struggling to see how this is a bug? You've activated a virtual environment, installed a package, and that has worked exactly as expected?

dimbleby avatar Aug 13 '23 22:08 dimbleby

Struggling to see how this is a bug?

Only poetry self add poetry-plugin-sort works, not pipx inject poetry poetry-plugin-sort. Otherwise, I have to remove the local poetry.exe, which only works temporarily.

pipx doesn't respect the $POETRY environment variables, so things like $POETRY_VIRTUALENVS_IN_PROJECT are ignored. I can only install the plugin for the local instance of poetry.exe with the poetry self add ... method.

Both poetrys are supposed to be there!

I don't understand why. Can you please explain? I know the entrypoint script is added because it is listed in the pyproject.toml and that's what makes pip install poetry work.

adam-grant-hendry avatar Aug 13 '23 22:08 adam-grant-hendry

there's the pipx-managed poetry which I suppose is your "main" poetry. And then there's the poetry that you added to your virtual environment when you typed poetry add poetry (ie you used the first poetry to create the second).

This all is working exactly as it should.

dimbleby avatar Aug 13 '23 23:08 dimbleby

This all is working exactly as it should.

The documentation is unclear and could use a little TLC. It would be worthwhile to add a small note that the pipx inject method won't work when doing local development. The pip method and poetry self add method will work, but not the pipx inject method.

adam-grant-hendry avatar Aug 13 '23 23:08 adam-grant-hendry

The pipx inject method will work fine, it will do what pipx does, which is make changes to the pipx-managed poetry.

If you are seeing it "not work" that's surely because your virtual environment is active and so when you type poetry you are not getting the pipx-managed poetry

dimbleby avatar Aug 13 '23 23:08 dimbleby

...it will do what pipx does, which is make changes to the pipx-managed poetry.

If you are seeing it "not work" that's surely because your virtual environment is active and so when you type poetry you are not getting the pipx-managed poetry

Precisely, but you can't type pipx inject ... in your local virtual environment and have it affect the local environment whereas you can with the others.

My recommendation is just a simple addition to the docs. Would you be willing to accept a PR that adds the following to the docs under Plugins/Using plugins:

# With `pipx inject`

If you used `pipx` to install Poetry you can add the plugin packages via the `pipx inject` command.

> pipx inject poetry poetry-plugin

If you want to uninstall a plugin, you can run:

> pipx runpip poetry uninstall poetry-plugin

**NOTE:** This method only modifies the (global) poetry installation managed by `pipx`. If you are developing a plugin and use a local virtual environment for your project, use the `poetry self add` or `pip` methods to modify the local version of `poetry`.

adam-grant-hendry avatar Aug 14 '23 02:08 adam-grant-hendry

Accepting MRs is not within my power.

I am confused by your confusion! but clearly it's real and perhaps others will experience the same, so if you think that a note in the docs would have helped you then that seems sensible.

I'd suggest that a note aimed at plugin developers would fit better in the section about plugin development.

dimbleby avatar Aug 14 '23 07:08 dimbleby