Skip to content

Commit c606344

Browse files
chore: Use bdist_wheel instead of custom script (#349)
1 parent 58f212e commit c606344

File tree

8 files changed

+89
-110
lines changed

8 files changed

+89
-110
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
pip install -r local-requirements.txt
2828
pip install -e .
2929
- name: Build package
30-
run: python build_package.py
30+
run: python setup.py bdist_wheel
3131
- name: Install browsers
3232
run: python -m playwright install
3333
- name: Lint
@@ -76,7 +76,7 @@ jobs:
7676
pip install -r local-requirements.txt
7777
pip install -e .
7878
- name: Build package
79-
run: python build_package.py
79+
run: python setup.py bdist_wheel
8080
- name: Install browsers
8181
run: python -m playwright install
8282
- name: Test Sync API
@@ -113,6 +113,6 @@ jobs:
113113
pip install -r local-requirements.txt
114114
pip install -e .
115115
- name: Build package
116-
run: python build_package.py
116+
run: python setup.py bdist_wheel
117117
- name: Test package installation
118118
run: bash buildbots/test-package-installations.sh

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
pip install -r local-requirements.txt
2323
pip install -e .
2424
- name: Build package
25-
run: python build_package.py
25+
run: python setup.py bdist_wheel
2626
- name: Publish package
2727
env:
2828
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
@@ -50,7 +50,7 @@ jobs:
5050
pip install -r local-requirements.txt
5151
pip install -e .
5252
- name: Build package
53-
run: python build_package.py
53+
run: python setup.py bdist_wheel
5454
- name: Install
5555
run: python -m playwright install
5656
- name: Build Docker image

.github/workflows/publish_canary_docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
pip install -r local-requirements.txt
3232
pip install -e .
3333
- name: Build package
34-
run: python build_package.py
34+
run: python setup.py bdist_wheel
3535
- name: Install
3636
run: python -m playwright install
3737
- run: docker build -t playwright-python:localbuild .

.github/workflows/test_docker.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ on:
33
push:
44
paths:
55
- '.github/workflows/test_docker.yml'
6-
- 'build_package.py'
76
branches:
87
- master
98
pull_request:
109
paths:
1110
- '.github/workflows/test_docker.yml'
12-
- 'build_package.py'
1311
branches:
1412
- master
1513
jobs:
@@ -28,7 +26,7 @@ jobs:
2826
pip install -r local-requirements.txt
2927
pip install -e .
3028
- name: Build package
31-
run: python build_package.py
29+
run: python setup.py bdist_wheel
3230
- name: Install
3331
run: python -m playwright install
3432
- name: Build Docker image
@@ -38,6 +36,6 @@ jobs:
3836
CONTAINER_ID="$(docker run --rm -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-python:localbuild /bin/bash)"
3937
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" pip install -r local-requirements.txt
4038
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" pip install -e .
41-
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" python build_package.py
39+
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" python setup.py bdist_wheel
4240
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" xvfb-run pytest -vv tests/sync/
4341
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" xvfb-run pytest -vv tests/async/

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Install required dependencies:
1717
python -m pip install --upgrade pip wheel
1818
pip install -r local-requirements.txt
1919
pip install -e .
20+
python setup.py bdist_wheel
2021
```
2122

2223
For more details look at the [CI configuration](./blob/master/.github/workflows/ci.yml).

build_package.py

Lines changed: 0 additions & 96 deletions
This file was deleted.

docs/development.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
```sh
66
pip install -e .
7-
python ./build_driver.py
7+
python setup.py bdist_wheel
88
```
99

1010
## Run tests:
@@ -23,9 +23,8 @@ open htmlcov/index.html
2323
## Deploy:
2424

2525
```sh
26-
python ./build_package.py
27-
... check
28-
python ./upload_package.py
26+
python setup.py bdist_wheel
27+
python setup.py upload
2928
```
3029

3130
## Checking for typing errors

setup.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,87 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import glob
16+
import os
17+
import shutil
18+
import stat
19+
import subprocess
20+
import sys
21+
import zipfile
22+
1523
import setuptools
24+
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand
25+
26+
driver_version = "0.170.0-next.1605573954344"
27+
1628

1729
with open("README.md", "r", encoding="utf-8") as fh:
1830
long_description = fh.read()
1931

32+
33+
class PlaywrightBDistWheelCommand(BDistWheelCommand):
34+
def run(self) -> None:
35+
if os.path.exists("build"):
36+
shutil.rmtree("build")
37+
if os.path.exists("dist"):
38+
shutil.rmtree("dist")
39+
if os.path.exists("playwright.egg-info"):
40+
shutil.rmtree("playwright.egg-info")
41+
super().run()
42+
os.makedirs("driver", exist_ok=True)
43+
os.makedirs("playwright/driver", exist_ok=True)
44+
for platform in ["mac", "linux", "win32", "win32_x64"]:
45+
zip_file = f"playwright-cli-{driver_version}-{platform}.zip"
46+
if not os.path.exists("driver/" + zip_file):
47+
url = "https://playwright.azureedge.net/builds/cli/next/" + zip_file
48+
print("Fetching ", url)
49+
subprocess.check_call(
50+
["curl", "--http1.1", url, "-o", "driver/" + zip_file]
51+
)
52+
base_wheel_location = glob.glob("dist/*.whl")[0]
53+
without_platform = base_wheel_location[:-7]
54+
platform_map = {
55+
"darwin": "mac",
56+
"linux": "linux",
57+
"win32": "win32_x64" if sys.maxsize > 2 ** 32 else "win32",
58+
}
59+
for platform in ["mac", "linux", "win32", "win32_x64"]:
60+
zip_file = f"driver/playwright-cli-{driver_version}-{platform}.zip"
61+
with zipfile.ZipFile(zip_file, "r") as zip:
62+
zip.extractall(f"driver/{platform}")
63+
if platform_map[sys.platform] == platform:
64+
with zipfile.ZipFile(zip_file, "r") as zip:
65+
zip.extractall("playwright/driver")
66+
for file in os.listdir("playwright/driver"):
67+
if file == "playwright-cli" or file.startswith("ffmpeg"):
68+
print(f"playwright/driver/{file}")
69+
os.chmod(
70+
f"playwright/driver/{file}",
71+
os.stat(f"playwright/driver/{file}").st_mode | stat.S_IEXEC,
72+
)
73+
wheel = ""
74+
if platform == "mac":
75+
wheel = "macosx_10_13_x86_64.whl"
76+
if platform == "linux":
77+
wheel = "manylinux1_x86_64.whl"
78+
if platform == "win32":
79+
wheel = "win32.whl"
80+
if platform == "win32_x64":
81+
wheel = "win_amd64.whl"
82+
wheel_location = without_platform + wheel
83+
shutil.copy(base_wheel_location, wheel_location)
84+
with zipfile.ZipFile(wheel_location, "a") as zip:
85+
for file in os.listdir(f"driver/{platform}"):
86+
from_location = f"driver/{platform}/{file}"
87+
to_location = f"playwright/driver/{file}"
88+
if file == "playwright-cli" or file.startswith("ffmpeg"):
89+
os.chmod(
90+
from_location, os.stat(from_location).st_mode | stat.S_IEXEC
91+
)
92+
zip.write(from_location, to_location)
93+
os.remove(base_wheel_location)
94+
95+
2096
setuptools.setup(
2197
name="playwright",
2298
author="Microsoft Corporation",
@@ -40,6 +116,7 @@
40116
"Operating System :: OS Independent",
41117
],
42118
python_requires=">=3.7",
119+
cmdclass={"bdist_wheel": PlaywrightBDistWheelCommand},
43120
use_scm_version={
44121
"version_scheme": "post-release",
45122
"write_to": "playwright/_repo_version.py",

0 commit comments

Comments
 (0)