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

Virtualenv pinned to <20 #10407

Closed
freundTech opened this issue May 3, 2021 · 10 comments · Fixed by #10855
Closed

Virtualenv pinned to <20 #10407

freundTech opened this issue May 3, 2021 · 10 comments · Fixed by #10855
Assignees
Labels
bug mypy got something wrong

Comments

@freundTech
Copy link
Contributor

In #8387 virtualenv was pinned to <20 to fix failing tests.

virtualenv <20 will be broken by python 3.10. Therefor I tried to unpin it. I haven't quite managed to make it work yet, but found the cause of the problem and wanted to document my findings.

testpep561 creates a virtualenv, installs some packages into it and then runs mypy, while telling it to search for stub packages in that virtualenv.

At first I couldn't reproduce the error. As it turns out it is related to the patches debian (and it's derivates) apply to python.

virtualenv<20 ships it's own site.py file to build sys.path. This site.py file doesn't contain the getsitepackages and getusersitepackages methods, causing mypy's sitepkgs.py to fall back to using distutils to get the python library path.
This works.

virtualenv>=20 doesn't ship it's own site.py file, so the python site.py file is used. Debian patches this file to return paths ending in dist-packages instead of site-packages. Pip in a virtualenv however still installs to site-packages, causing mypy to not find the installed packages.

This is only a problem with python2. Debian doesn't seem to patch python3 site.py in this way.

@freundTech
Copy link
Contributor Author

I got two patches into virtualenv to fix this and using virtualenv>=20.4.6 should no longer break on debian.

Tests are still broken on windows. If I get that fixed virtualenv will no longer have to be pinned to <20

@hauntsaninja
Copy link
Collaborator

Thanks for working on this!

@ethanhs
Copy link
Collaborator

ethanhs commented May 6, 2021

@freundTech if you open a PR I can look at the Windows errors if you want.

@freundTech
Copy link
Contributor Author

I'd prefer to not open a PR yet, as I regularly force-push to my branch to test things on the CI. You can however look at the branch directly. CI is enabled on my fork.
https://github.com/freundTech/mypy/tree/unpin-virtualenv

The tests on windows output "C:\Users\RUNNER~1\AppData\Local\Temp<random characters> is in the PYTHONPATH. Please change directory so it is not." to stderr and quit running after that.
This message comes from mypy/mypy/modulefinder.py, line 722. The directory is probably the virtualenv created by the test.

That's as far as I have currently investigated.

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 15, 2021

Are there any updates on this? Perhaps somebody could help, as this seems to be one of the biggest remaining issues blocking 3.10 support, I think.

@ethanhs
Copy link
Collaborator

ethanhs commented Jul 15, 2021

This is only a problem with python2. Debian doesn't seem to patch python3 site.py in this way.

Personally, I'd prefer we just skip these tests on Python 2 since it seems that is the "issue". Our Python 2 support is pretty much best efforts anyway, and I don't think we should bend over backwards for a test that is broken because of Python 2 weirdness.

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 15, 2021

Personally, I'd prefer we just skip these tests on Python 2 since it seems that is the "issue".

Yeah, this sounds reasonable. This only seem to affect a specific Python 2 use case only. Installing packages in the same virtualenv that runs mypy still works, and I'd expect to be the most common use case by far. If users complain about this, we can consider fixing this.

Would anybody want to create PR that switches to a more recent virtualenv and skips the relevant tests?

@ethanhs
Copy link
Collaborator

ethanhs commented Jul 15, 2021

Oh hm, looking closer it seems the issue on Windows may not be Python 2 related and probably deserves actually being looked into. I'll try to get to this sometime today.

@ethanhs ethanhs self-assigned this Jul 15, 2021
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jul 21, 2021

Well-timed, looks like something has started causing these tests to fail on master (e.g., see #10845). Looked at a couple different packages and didn't see any incriminating releases in the relevant timeframe.

hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this issue Jul 21, 2021
Resolves python#10407 as well as the mysteriously suddenly broken tests on
master.
@pranavrajpal
Copy link
Contributor

I think I know why those tests started failing suddenly. virtualenv released version 16.7.11 today, which bumped the versions of pip, setuptools, and wheel (see pypa/virtualenv@ca04bf7).

That appears to bump pip from 19.3.1 to 21.1.3, which breaks on python 2 by requiring the typing module (see pypa/pip@0945809), which is where the 'No module named typing' error is coming from.

That still leaves some unanswered questions though:

  1. That virtualenv commit also included a copy of pip 20.3.4, presumably so that it could keep python 2 support. Why isn't that being used here?
  2. The Travis CI setup appears to install typing on python2, so why isn't python finding that when pip imports typing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants