Skip to content

Commit

Permalink
Make test_pip_upgrade_from_source xdist-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Jan 1, 2021
1 parent 6f85928 commit 0e3f505
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions setuptools/tests/test_virtualenv.py
@@ -1,6 +1,8 @@
import glob
import os
import shutil
import sys
import subprocess

import pathlib

Expand Down Expand Up @@ -85,32 +87,46 @@ def _get_pip_versions():


@pytest.mark.parametrize('pip_version', _get_pip_versions())
def test_pip_upgrade_from_source(pip_version, virtualenv):
def test_pip_upgrade_from_source(pip_version, tmp_path, virtualenv):
"""
Check pip can upgrade setuptools from source.
"""
dist_dir = virtualenv.workspace
venv_python = virtualenv.python
venv_pip = f'{venv_python} -m pip'

# NOTE: The source dir is copied so that multiple parallel runs
# NOTE: of `setup.py sdist/bdist_wheel` don't remove each other's
# NOTE: egg directories.
tmp_src = tmp_path / 'src'
shutil.copytree(SOURCE_DIR, tmp_src)

# Install pip/wheel, and remove setuptools (as it
# should not be needed for bootstraping from source)
if pip_version is None:
upgrade_pip = ()
else:
upgrade_pip = ('python -m pip install -U {pip_version} --retries=1',)
virtualenv.run(' && '.join((
'pip uninstall -y setuptools',
'pip install -U wheel',
) + upgrade_pip).format(pip_version=pip_version))
dist_dir = virtualenv.workspace
upgrade_pip = () if pip_version is None else (
f'{venv_pip} install -U {pip_version} --retries=1',
)
subprocess.check_call(' && '.join((
f'{venv_pip} uninstall -y setuptools',
f'{venv_pip} install -U wheel',
*upgrade_pip,
)), shell=True)

# Generate source distribution / wheel.
virtualenv.run(' && '.join((
'python setup.py -q sdist -d {dist}',
'python setup.py -q bdist_wheel -d {dist}',
)).format(dist=dist_dir), cd=SOURCE_DIR)
subprocess.check_call(' && '.join((
f'{venv_python} setup.py -q sdist -d {dist_dir}',
f'{venv_python} setup.py -q bdist_wheel -d {dist_dir}',
)), shell=True, cwd=tmp_src)
sdist = glob.glob(os.path.join(dist_dir, '*.zip'))[0]
wheel = glob.glob(os.path.join(dist_dir, '*.whl'))[0]

# Then update from wheel.
virtualenv.run('pip install ' + wheel)
subprocess.check_call(f'{venv_pip} install {wheel}', shell=True)
# And finally try to upgrade from source.
virtualenv.run('pip install --no-cache-dir --upgrade ' + sdist)
subprocess.check_call(
f'{venv_pip} install --no-cache-dir --upgrade {sdist}',
shell=True,
)


def _check_test_command_install_requirements(virtualenv, tmpdir):
Expand Down

0 comments on commit 0e3f505

Please sign in to comment.