Open AThePeanut4 opened 3 weeks ago
Right, that makes sense. Is there anyway we can know if it is externally managed?
I don't think there's a super straightforward way, but I think this should do the trick (at least on Linux/macOS, not sure how things work on Windows):
poetry
wrapper script on PATH
, and parse out the Python interpreter it uses from the shebang line. This is simply #!/usr/bin/python
for me, and will be something like #!/home/user/.local/share/pipx/venvs/poetry/bin/python
if installed using pipx.import sys; import sysconfig; from os import path; from poetry import poetry; stdlib = sysconfig.get_path('stdlib'); print('Y') if (poetry.__file__.startswith(stdlib) and path.isfile(path.join(stdlib, 'EXTERNALLY-MANAGED'))) or path.isfile(path.join(sys.prefix, 'pipx_metadata.json')) else print('N')
(modified version of the script used in the pip step). If poetry is installed under the stdlib path and that path is externally managed, or if it is installed a pipx venv, then it will print Y
, and N
otherwise. pipx adds a pipx_metadata.json
file to the venv so I'm using that.It's a bit convoluted, but it seems to work with me just running the script manually on installations through pacman, pipx, and the official install script.
Didn't see that the official poetry installer adds a poetry_env
file to its venv, so checking for that is probably the easiest solution - this much simpler script does that: import sys; print('Y') if path.isfile(path.join(sys.prefix, 'poetry_env')) else print('N')
. The self-update would then only be run if the official installer was used, so it might be useful to add a config option of some sort to bypass the check for those using some kind of exotic setup but still want it to self-update.
This approach looks viable.
so it might be useful to add a config option of some sort to bypass the check for those using some kind of exotic setup but still want it to self-update.
You mean the users who want to update poetry with external tools? One can do this by disabling the poetry
step.
And, just to confirm, that solution would also work on Windows, right?
You mean the users who want to update poetry with external tools? One can do this by disabling the
poetry
step.
I mean those that didn't install poetry through the official installer but still want topgrade to run poetry self update
- perhaps they installed manually. Effectively an override to skip the check and revert to topgrade's current behaviour of running poetry self update
unconditionally.
And, just to confirm, that solution would also work on Windows, right?
I don't think so, because Windows won't have the shebang line which gives the path to the python interpreter that the script needs to be run with. Windows also doesn't have "text" scripts you can run directly, it would have to be some kind of (binary) exe. The actual check for the poetry_env
file I imagine should be fine. I'll boot into windows later and try figure something out.
I mean those that didn't install poetry through the official installer but still want topgrade to run poetry self update - perhaps they installed manually. Effectively an override to skip the check and revert to topgrade's current behaviour of running poetry self update unconditionally.
Thanks for the explanation, I wonder can do poetry self update
to installations done by the official script and the manual one, will this command break manual installations?
I don't think so, because Windows won't have the shebang line which gives the path to the python interpreter that the script needs to be run with. Windows also doesn't have "text" scripts you can run directly, it would have to be some kind of (binary) exe. The actual check for the poetry_env file I imagine should be fine. I'll boot into windows later and try figure something out.
Thanks, appreciate the work.
Apologies for the delay, I had figured it out a while ago, but got busy and didn't get around to replying. I was going to explain the process here, but I decided to just go ahead and actually implement it in #989, it wasn't particularly difficult.
Thanks for the explanation, I wonder can do
poetry self update
to installations done by the official script and the manual one, will this command break manual installations?
It shouldn't break manual installations no - it's running the equivalent of pip install --upgrade
inside the poetry venv. A manual installation is basically the same as an official install, installing manually is "essentially performing the steps carried out by the official installer" (from here).
Erroneous Behavior
Topgrade is attempting to run
poetry self update
, which fails with externally-managed-environment errors because I've installed poetry through pacman.Expected Behavior
poetry self update
should be skipped when poetry is installed into an externally managed environment, similar to the way the pip self-upgrade step is skipped. I believepoetry self update
probably also shouldn't be run if poetry is installed through pipx - the docs imply that poetry should be upgraded usingpipx upgrade poetry
in that case, which would be handled by the pipx step in topgrade.Steps to reproduce
topgrade --only poetry
Problem persists without calling from topgrade
N/A
Did you run topgrade through
Remote Execution
Configuration file (Optional)
N/A
Additional Details
Operation System/Version Arch Linux
Installation AUR - topgrade
Topgrade version (
topgrade -V
) topgrade 16.0.1Verbose Output (
topgrade -v
)