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

exceptiongroup python version import check not compatible with poetry/virtualenv #10956

Closed
sergioisidoro opened this issue Apr 29, 2023 · 5 comments

Comments

@sergioisidoro
Copy link

I'm hitting a problem where using poetry (together with Tox testing matrix) will fail system checks introduced in #10209

Indeed the python version installed system wide is 3.11, but when testing with multiple python versions with Tox and virtual envs, this fails, because the system installed python and environment python is not the same. So

if sys.version_info[:2] < (3, 11):
    from exceptiongroup import BaseExceptionGroup

Will try to import BaseExceptionGroup even though it's being ran in Python <= 3.10

Is it possible to use env markers instead?
https://peps.python.org/pep-0508/#environment-markers

pytest = "^7.3.1"

Related:
python-poetry/poetry#758

Trace:

Traceback (most recent call last):
  File "/home/runner/.cache/pypoetry/virtualenvs/my-package-koh7-DBw-py3.10/bin/py.test", line 5, in <module>
    from pytest import console_main
  File "/home/runner/.cache/pypoetry/virtualenvs/my-package-koh7-DBw-py3.10/lib/python3.10/site-packages/pytest/__init__.py", line 5, in <module>
    from _pytest._code import ExceptionInfo
  File "/home/runner/.cache/pypoetry/virtualenvs/my-package-koh7-DBw-py3.10/lib/python3.10/site-packages/_pytest/_code/__init__.py", line 2, in <module>
    from .code import Code
  File "/home/runner/.cache/pypoetry/virtualenvs/my-package-koh7-DBw-py3.10/lib/python3.10/site-packages/_pytest/_code/code.py", line 60, in <module>
    from exceptiongroup import BaseExceptionGroup
ModuleNotFoundError: No module named 'exceptiongroup'
Error: Process completed with exit code 1.
@RonnyPfannschmidt
Copy link
Member

You mean https://github.com/pytest-dev/pytest/blob/main/setup.cfg#L51

Please verify if this is a poetry issue

Based on the spec it should work

@sergioisidoro
Copy link
Author

sergioisidoro commented Apr 29, 2023

I don't think it's about the line you mention.
The tests run ok in Py3.11, and fails on all others bellow.
I'm using github actions actions/setup-python@v4.5.0 to set the python version.

I will continue to investigate to check if there's anything I missed in the pipepilne.

@sergioisidoro
Copy link
Author

sergioisidoro commented Apr 29, 2023

Indeed it does not seem to be a problem with pytest. version_info is correct, even in the CI env

import sys
print(sys.version_info)
print(sys.version_info[:2])

> poetry run python echo_py.py
--->
sys.version_info(major=3, minor=10, micro=[11](https://github.com/sergioisidoro/my-package/actions/runs/4838885495/jobs/8623593821?pr=1#step:9:11), releaselevel='final', serial=0)
(3, 10)

Still no idea what's going on...

@RonnyPfannschmidt
Copy link
Member

Is the poetry dependency resolver running on the right python version?

@JamesHutchison
Copy link

I encountered this issue. In my case, I started with a Python 3.11 dev container with poetry pegged to the 3.11 version. I opened up the version to 3.10 but forgot to rebuild the poetry lock file. The fix was to run poetry lock and commit the updated lock file.

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

No branches or pull requests

3 participants