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 2.1 breaks -- (double-dash) handling #10204

Open
patrikspiess opened this issue Feb 19, 2025 · 5 comments
Open

Poetry 2.1 breaks -- (double-dash) handling #10204

patrikspiess opened this issue Feb 19, 2025 · 5 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@patrikspiess
Copy link

Description

Poetry 2.1 breaks to handling of the -- option.

Example:

Here you can see how Poetry 2.0.1 behaves:

user@host:~$ poetry -V
Poetry (version 2.0.1)

user@host:~$ poetry run tox --version
4.24.1 from /home/user/project/.venv/lib/python3.12/site-packages/tox/__init__.py

user@host:~$ poetry run tox --version --
4.24.1 from /home/user/project/.venv/lib/python3.12/site-packages/tox/__init__.py

This is OK. Even with a -- at the end the --version shows my tox version.

Then I upgrade Poetry to 2.1.1

user@host:~$ pipx upgrade poetry
upgraded package poetry from 2.0.1 to 2.1.1 (location: /home/user/.local/share/pipx/venvs/poetry)

user@host:~$ poetry run tox --version
4.24.1 from /home/user/project/.venv/lib/python3.12/site-packages/tox/__init__.py

user@host:~$ poetry run tox --version --
Poetry (version 2.1.1)

Now, you can see that with the -- option the --version shows the Poetry version instead of the tox Version.


This behaviour breaks our CI/CD pipeline when working with tox {posargs}
For example if we have a tox environment:

[testenv:pytest]
description = do unit tests with pytest
skip_install = true
allowlist_externals = poetry, pytest
commands_pre = poetry install
commands = pytest --basetemp=tests/temp/ {posargs}

When we try to call it with posargs we get the following error:

user@host:~$ poetry run tox -e pytest -- -- --junit-xml=tests.xml
The option "-e" does not exist

This is because the -- option passes the -e option back to Poetry instead leaving it with tox.
This worked pretty well with Poetry 2.1.1

Workarounds

I had to pin the Poetry version back to v2.0.1 in our CI/CD pipeline to make it work again.

Poetry Installation Method

pipx

Operating System

Windows 11 / WSL / Ubuntu 22.04

Poetry Version

Poetry (version 2.1.1)

Poetry Configuration

cache-dir = "/home/user/.cache/pypoetry"
data-dir = "/home/user/.local/share/pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
python.installation-dir = "{data-dir}/python"  # /home/user/.local/share/pypoetry/python
repositories.testpypi.url = "https://test.pypi.org/legacy/"
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/user/.cache/pypoetry/virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Python Sysconfig

sysconfig.log
Paste the output of 'python -m sysconfig', over this line.

Example pyproject.toml

Poetry Runtime Logs

poetry-runtime.log
Paste the output of 'poetry -vvv <command>', over this line.
@patrikspiess patrikspiess added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Feb 19, 2025
@dimbleby
Copy link
Contributor

dimbleby commented Feb 19, 2025

#10021 / #10067 presumably? @abn

@abn
Copy link
Member

abn commented Feb 19, 2025

Correct. More specifically;

if "--" in tokens:
# this means the user has done the right thing and used "poetry run -- echo hello"
# in this case there is not much we need to do, we can skip the rest
return

From my pov, the new behavior is more unexpected than the previous. But nonetheless, it does break what might have worked before by some force fiddling.

@amcinnes
Copy link

This was a breaking change for me too. In our CI pipeline we run something like poetry run python3 -m mypy -- *.py, which works under poetry 2.0.1 but not poetry 2.1.0.

Updating the command to poetry run -- python3 -m mypy -- *.py resolved the problem.

@patrikspiess
Copy link
Author

This was a breaking change for me too. In our CI pipeline we run something like poetry run python3 -m mypy -- *.py, which works under poetry 2.0.1 but not poetry 2.1.0.

Updating the command to poetry run -- python3 -m mypy -- *.py resolved the problem.

Oh, great, thank you. This also works for me with the dashes after the run command.
I just wonder: is it a bug or is this the new expected behaviour?

@abn
Copy link
Member

abn commented Feb 20, 2025

Let's put it this way, the old way of parsing was more error prone than what we have today.

And, if we go by bash docs -- signifies the end of options, this would mean poetry run python -m mypy -- something "should" treat -m as a poetry option. And that should have failed.

I'd say what we need is some update to the doc clarifying this for users who relied on the double dash for the command executed by run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants