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

usercustomize.py starting with print statement crashes tox env creation with sitepackages = True #1569

Closed
Cielquan opened this issue Apr 26, 2020 · 1 comment
Labels
bug:normal affects many people or has quite an impact

Comments

@Cielquan
Copy link

Cielquan commented Apr 26, 2020

Hi,
I found a bug but I'm not sure if tox or maybe virtualenv is guilty. I use python 3.8 but I'm sure the bug will also happen in other versions.

I started to use the site module of python because I found the devtools package and in the docs of it the site module was mentioned as a way to globally import the toolset or more specifically the debug() function which then can be used like print(). Instead of a sitecustomize.py file I use a usercustomize.py file. I don't know if this makes a difference but I don't think so.

working usercustomize.py file:

try:
    from devtools import debug
except ImportError:
    pass
else:
    __builtins__['debug'] = debug

I use tox to setup my dev venv and to be able to use this 'global import' of debug() I set sitepackages = True for the dev venv which in itself works but can create another bug #1570.

For information I added print('### Load User Customization') at the top of the usercustomize.py file which triggers the bug. You can see that at the 2nd line starting with ERROR: in the error output below. Somehow the output of the print gets appended to the path for the sys.prefix.

To recreate the bug you only need two files:

An usercustomize.py file at the right place with a print() statement printing something except an empty string. To find the right place call python -m site. The second last line starting with USER_SITE shows the path were to put the file.

Second you need a tox.ini (simplified to the issue):

[tox]
skipsdist = True

[testenv:dev]
basepython = python3.8
sitepackages = True

Then you can create the error message:

$ tox -rvv -e dev

using tox.ini: /home/krys/Python_Projects/.testing/tox.ini (pid 112413)
  removing /home/krys/Python_Projects/.testing/.tox/log
using tox-3.14.6 from /home/krys/.venvs/tox/lib/python3.8/site-packages/tox/__init__.py (pid 112413)
skipping sdist step
dev start: getenv /home/krys/Python_Projects/.testing/.tox/dev
dev cannot reuse: -r flag
dev create: /home/krys/Python_Projects/.testing/.tox/dev
dev uses /home/krys/.venvs/tox/bin/python3.8
  removing /home/krys/Python_Projects/.testing/.tox/dev
setting PATH=/home/krys/Python_Projects/.testing/.tox/dev/bin:/home/krys/bin:/home/krys/.local/bin:/home/krys/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
[112417] /home/krys/Python_Projects/.testing/.tox$ /home/krys/.venvs/tox/bin/python3.8 -m virtualenv --system-site-packages --no-download --python /home/krys/.venvs/tox/bin/python3.8 dev
Already using interpreter /home/krys/.venvs/tox/bin/python3.8
Using base prefix '/usr'
New python executable in /home/krys/Python_Projects/.testing/.tox/dev/bin/python3.8
Also creating executable in /home/krys/Python_Projects/.testing/.tox/dev/bin/python
ERROR: The executable /home/krys/Python_Projects/.testing/.tox/dev/bin/python3.8 is not functioning
ERROR: It thinks sys.prefix is '/home/krys/Python_Projects/.testing/.tox/dev### Load User Customization' (should be '/home/krys/Python_Projects/.testing/.tox/dev')
ERROR: virtualenv is not compatible with this system or executable
ERROR: invocation failed (exit code 100)
ERROR: InvocationError for command /home/krys/.venvs/tox/bin/python3.8 -m virtualenv --system-site-packages --no-download --python /home/krys/.venvs/tox/bin/python3.8 dev (exited with code 100)
dev finish: getenv /home/krys/Python_Projects/.testing/.tox/dev after 0.09 seconds
___________________________________ summary ____________________________________
ERROR:   dev: InvocationError for command /home/krys/.venvs/tox/bin/python3.8 -m virtualenv --system-site-packages --no-download --python /home/krys/.venvs/tox/bin/python3.8 dev (exited with code 100)
*** Exit Code: 1 ***
@Cielquan Cielquan added the bug:normal affects many people or has quite an impact label Apr 26, 2020
@Cielquan Cielquan changed the title usercustomize.py with print statement crashes tox env creation with sitepackages = True usercustomize.py starting with print statement crashes tox env creation with sitepackages = True Apr 26, 2020
@gaborbernat
Copy link
Member

This should no longer be the case with tox version 4 and virtualenv 20 and later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:normal affects many people or has quite an impact
Projects
None yet
Development

No branches or pull requests

2 participants