pyperformance icon indicating copy to clipboard operation
pyperformance copied to clipboard

pyperformance issue when run in a venv created by virtualenv command

Open vstinner opened this issue 4 years ago • 0 comments

hg_startup failed on the py3 job of Travis CI. I had to disable again this benchmark on Python 3. It's an issue related to virtual environment which is not specific to Mercurial.

Travis CI runs Python in a virtual environment created by the "virtualenv" command which overrides the site.py module.

runtests.py then creates a second virtual environment using "python3 -m venv" but this second venv inherits modules of the first venv, whereas pyperformance requires a virtual environment isolated from the system to get reproducible results.

Example without pyperformance:

# create venv1 and venv2
vstinner@apu$ virtualenv -p python3 venv1
vstinner@apu$ venv1/bin/python -m venv venv2

# install mercurial in venv1
vstinner@apu$ venv1/bin/python -m pip install mercurial # in venv1

# ... it's available in venv2!!!
vstinner@apu$ venv2/bin/python -c 'import mercurial; print(mercurial.__file__)' # in venv2
/home/vstinner/venv1/lib/python3.7/site-packages/mercurial/__init__.py

# venv1 uses /home/vstinner/venv1/lib/python3.7/site-packages path
vstinner@apu$ venv1/bin/python -m site
sys.path = [
    '/home/vstinner',
    '/usr/share/qa-tools/python-modules',
    '/home/vstinner/venv1/lib64/python37.zip',
    '/home/vstinner/venv1/lib64/python3.7',
    '/home/vstinner/venv1/lib64/python3.7/lib-dynload',
    '/usr/lib64/python3.7',
    '/usr/lib/python3.7',
    '/home/vstinner/venv1/lib/python3.7/site-packages',
]
USER_BASE: '/home/vstinner/.local' (exists)
USER_SITE: '/home/vstinner/.local/lib/python3.7/site-packages' (exists)
ENABLE_USER_SITE: False

# venv2 uses /home/vstinner/venv1/lib/python3.7/site-packages path as well!!!
vstinner@apu$ venv2/bin/python -m site
sys.path = [
    '/home/vstinner',
    '/usr/share/qa-tools/python-modules',
    '/home/vstinner/venv1/lib64/python37.zip',
    '/home/vstinner/venv1/lib64/python3.7',
    '/home/vstinner/venv1/lib64/python3.7/lib-dynload',
    '/usr/lib64/python3.7',
    '/usr/lib/python3.7',
    '/home/vstinner/venv1/lib/python3.7/site-packages',
]
USER_BASE: '/home/vstinner/.local' (exists)
USER_SITE: '/home/vstinner/.local/lib/python3.7/site-packages' (exists)
ENABLE_USER_SITE: False

# mercurial is installed in venv1...
vstinner@apu$ venv1/bin/python -m pip list
Package    Version
---------- -------
mercurial  5.0.2  
pip        19.2.1 
setuptools 41.0.1 
wheel      0.33.4 

# ... but it's also "installed" in venv2!!!
vstinner@apu$ venv2/bin/python -m pip list
Package    Version
---------- -------
mercurial  5.0.2  
pip        19.2.1 
setuptools 41.0.1 
wheel      0.33.4 

# it's even considered as a "local" install in venv2
vstinner@apu$ venv2/bin/python -m pip list --local
Package    Version
---------- -------
mercurial  5.0.2  
pip        19.2.1 
setuptools 41.0.1 
wheel      0.33.4 

vstinner avatar Jul 30 '19 12:07 vstinner