Skip to content

Commit

Permalink
Convert virtualenv usages in test to 20+ API
Browse files Browse the repository at this point in the history
virtualenv 20.0+ completely revamps its API:

* There's no path_locations() anymore. Stdlib sysconfig can replace it
  completely.
* The Python API to create an environment is split into several pieces.
  Use the entry point function for now to provide the functionality.
  • Loading branch information
uranusjr committed Feb 12, 2020
1 parent 3decd9d commit 4eae4ac
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions tests/lib/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import compileall
import shutil
import sys
import sysconfig
import textwrap

import six
import virtualenv as _virtualenv
import virtualenv.run as _virtualenv_run

from .path import Path

Expand All @@ -32,16 +32,13 @@ def __init__(self, location, template=None, venv_type=None):
self._create()

def _update_paths(self):
home, lib, inc, bin = _virtualenv.path_locations(self.location)
self.bin = Path(bin)
self.site = Path(lib) / 'site-packages'
# Workaround for https://github.com/pypa/virtualenv/issues/306
if hasattr(sys, "pypy_version_info"):
version_fmt = '{0}' if six.PY3 else '{0}.{1}'
version_dir = version_fmt.format(*sys.version_info)
self.lib = Path(home, 'lib-python', version_dir)
else:
self.lib = Path(lib)
paths = sysconfig.get_paths(vars={
"base": self.location,
"platbase": self.location,
})
self.bin = Path(paths["scripts"])
self.site = Path(paths["purelib"])
self.lib = Path(paths["stdlib"])

def __repr__(self):
return "<VirtualEnvironment {}>".format(self.location)
Expand All @@ -50,10 +47,6 @@ def _create(self, clear=False):
if clear:
shutil.rmtree(self.location)
if self._template:
# On Windows, calling `_virtualenv.path_locations(target)`
# will have created the `target` directory...
if sys.platform == 'win32' and self.location.exists():
self.location.rmdir()
# Clone virtual environment from template.
shutil.copytree(
self._template.location, self.location, symlinks=True
Expand All @@ -63,19 +56,21 @@ def _create(self, clear=False):
else:
# Create a new virtual environment.
if self._venv_type == 'virtualenv':
_virtualenv.create_environment(
_virtualenv_run.run_via_cli([
self.location,
no_pip=True,
no_wheel=True,
no_setuptools=True,
)
"--no-pip",
"--no-wheel",
"--no-setuptools",
])
self._fix_virtualenv_site_module()
elif self._venv_type == 'venv':
builder = _venv.EnvBuilder()
context = builder.ensure_directories(self.location)
builder.create_configuration(context)
builder.setup_python(context)
self.site.mkdir(parents=True, exist_ok=True)
else:
raise ValueError("venv type must be 'virtualenv' or 'venv'")
self.sitecustomize = self._sitecustomize
self.user_site_packages = self._user_site_packages

Expand Down

0 comments on commit 4eae4ac

Please sign in to comment.