Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit becb9e4

Browse files
jgrahammoz-wptsync-bot
authored andcommitted
Bug 1834350 [wpt PR 40130] - Don't require virtualenv binary, a=testonly
Automatic update from web-platform-tests Don't require virtualenv binary With Python 3 we can use python3 -m venv to create a virtualenv. The main dififculty is that we're missing activate_this.py which we use to activate the environment. But we can do the relevant path / env manipulations ourselves and so cut down the number of dependencies. -- Try falling back to `pip` if `pip3` doesn't exist -- Update documentation -- wpt-commits: 7eed90bb584ed77bf7227233501882a43f90d05e, 5bb7544e8c50cb3bcc55bd4508cbbc94b1209302, 4fd791ba8cda63f0fdece4bdb72a431f198b582e wpt-pr: 40130
1 parent 575a0b7 commit becb9e4

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

testing/web-platform/tests/.taskcluster.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ tasks:
5757
owner: ${owner}
5858
source: ${event.repository.clone_url}
5959
payload:
60-
image: webplatformtests/wpt:0.53
60+
image: webplatformtests/wpt:0.54
6161
maxRunTime: 7200
6262
artifacts:
6363
public/results:

testing/web-platform/tests/docs/running-tests/from-local-system.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ The tests are designed to be run from your local computer.
44

55
## System Setup
66

7-
Running the tests requires `python`, `pip` and `virtualenv`, as well as updating
8-
the system `hosts` file.
7+
Running the tests requires `python` and `pip` as well as updating the
8+
system `hosts` file.
99

1010
WPT requires Python 3.7 or higher.
1111

@@ -14,12 +14,12 @@ The required setup is different depending on your operating system.
1414
### Linux Setup
1515

1616
If not already present, use the system package manager to install `python`,
17-
`pip` and `virtualenv`.
17+
and `pip`.
1818

19-
On Debian or Ubuntu:
19+
On Ubuntu:
2020

2121
```bash
22-
sudo apt-get install python python-pip virtualenv
22+
sudo apt-get install python3 python3-pip python3-venv
2323
```
2424

2525
It is important to have a package that provides a `python` binary. On Fedora,
@@ -28,13 +28,12 @@ Ubuntu Focal and later, the package is called `python-is-python3`.
2828

2929
### macOS Setup
3030

31-
The system-provided Python can be used, while `pip` and `virtualenv` can be
31+
The system-provided Python can be used, while `pip` can be
3232
installed for the user only:
3333

3434
```bash
3535
python -m ensurepip --user
3636
export PATH="$PATH:$( python3 -m site --user-base )/bin"
37-
pip install --user virtualenv
3837
```
3938

4039
To make the `PATH` change persistent, add it to your `~/.bash_profile` file or
@@ -50,12 +49,6 @@ installer includes `pip` by default.
5049
Add `C:\Python39` and `C:\Python39\Scripts` to your `%Path%`
5150
[environment variable](http://www.computerhope.com/issues/ch000549.htm).
5251

53-
Finally, install `virtualenv`:
54-
55-
```bash
56-
pip install virtualenv
57-
```
58-
5952
The standard Windows shell requires that all `wpt` commands are prefixed
6053
by the Python binary i.e. assuming `python` is on your path the server is
6154
started using:

testing/web-platform/tests/tools/ci/tc/tasks/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ components:
44
workerType: ci
55
schedulerId: taskcluster-github
66
deadline: "24 hours"
7-
image: webplatformtests/wpt:0.53
7+
image: webplatformtests/wpt:0.54
88
maxRunTime: 7200
99
artifacts:
1010
public/results:
@@ -116,6 +116,7 @@ components:
116116
- python3.7
117117
- python3.7-distutils
118118
- python3.7-dev
119+
- python3.7-venv
119120

120121
tox-python3_10:
121122
env:
@@ -125,6 +126,7 @@ components:
125126
- python3.10
126127
- python3.10-distutils
127128
- python3.10-dev
129+
- python3.10-venv
128130

129131
tests-affected:
130132
options:

testing/web-platform/tests/tools/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ RUN apt-get -qqy update \
3131
python3 \
3232
python3-dev \
3333
python3-pip \
34+
python3-venv \
3435
software-properties-common \
3536
qemu-kvm \
3637
tzdata \
@@ -64,7 +65,6 @@ RUN apt-get -qqy install \
6465
RUN apt-get -y autoremove
6566

6667
RUN pip install --upgrade pip
67-
RUN pip install virtualenv
6868

6969
ENV TZ "UTC"
7070
RUN echo "${TZ}" > /etc/timezone \

testing/web-platform/tests/tools/wpt/virtualenv.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# mypy: allow-untyped-defs
22

3+
import logging
34
import os
45
import shutil
6+
import site
57
import sys
6-
import logging
8+
import sysconfig
9+
from pathlib import Path
710
from shutil import which
811

912
# The `pkg_resources` module is provided by `setuptools`, which is itself a
@@ -27,9 +30,7 @@ def __init__(self, path, skip_virtualenv_setup):
2730
self.path = path
2831
self.skip_virtualenv_setup = skip_virtualenv_setup
2932
if not skip_virtualenv_setup:
30-
self.virtualenv = which("virtualenv")
31-
if not self.virtualenv:
32-
raise ValueError("virtualenv must be installed and on the PATH")
33+
self.virtualenv = [sys.executable, "-m", "venv"]
3334
self._working_set = None
3435

3536
@property
@@ -47,7 +48,7 @@ def create(self):
4748
if os.path.exists(self.path):
4849
shutil.rmtree(self.path)
4950
self._working_set = None
50-
call(self.virtualenv, self.path, "-p", sys.executable)
51+
call(*self.virtualenv, self.path)
5152

5253
@property
5354
def bin_path(self):
@@ -59,7 +60,9 @@ def bin_path(self):
5960
def pip_path(self):
6061
path = which("pip3", path=self.bin_path)
6162
if path is None:
62-
raise ValueError("pip3 not found")
63+
path = which("pip", path=self.bin_path)
64+
if path is None:
65+
raise ValueError("pip3 or pip not found")
6366
return path
6467

6568
@property
@@ -100,9 +103,37 @@ def activate(self):
100103
# https://github.com/web-platform-tests/wpt/issues/27377
101104
# https://github.com/python/cpython/pull/9516
102105
os.environ.pop('__PYVENV_LAUNCHER__', None)
103-
path = os.path.join(self.bin_path, "activate_this.py")
104-
with open(path) as f:
105-
exec(f.read(), {"__file__": path})
106+
107+
# Setup the path and site packages as if we'd launched with the virtualenv active
108+
bin_dir = os.path.join(self.path, "bin")
109+
os.environ["PATH"] = os.pathsep.join([bin_dir] + os.environ.get("PATH", "").split(os.pathsep))
110+
os.environ["VIRTUAL_ENV"] = self.path
111+
112+
prev_length = len(sys.path)
113+
114+
schemes = sysconfig.get_scheme_names()
115+
if "venv" in schemes:
116+
scheme = "venv"
117+
else:
118+
scheme = "nt_user" if os.name == "nt" else "posix_user"
119+
sys_paths = sysconfig.get_paths(scheme)
120+
data_path = sys_paths["data"]
121+
added = set()
122+
# Add the venv library paths as sitedirs.
123+
# This converts system paths like /usr/local/lib/python3.10/site-packages
124+
# to venv-relative paths like {self.path}/lib/python3.10/site-packages and adds
125+
# those paths as site dirs to be used for module import.
126+
for key in ["purelib", "platlib"]:
127+
host_path = Path(sys_paths[key])
128+
relative_path = host_path.relative_to(data_path)
129+
site_dir = os.path.normpath(os.path.normcase(Path(self.path) / relative_path))
130+
if site_dir not in added:
131+
site.addsitedir(site_dir)
132+
added.add(site_dir)
133+
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]
134+
135+
sys.real_prefix = sys.prefix
136+
sys.prefix = self.path
106137

107138
def start(self):
108139
if not self.exists or self.broken_link:

0 commit comments

Comments
 (0)