Skip to content

Commit 965afa4

Browse files
feat: Installation from github (microsoft#537)
1 parent 9dee7b3 commit 965afa4

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
python -m pip install --upgrade pip
1717
pip install -r local-requirements.txt
1818
pip install -e .
19-
python setup.py bdist_wheel
19+
python setup.py bdist_wheel --all
2020
python -m playwright install-deps
2121
- name: Publish package
2222
env:

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repos:
88
- id: end-of-file-fixer
99
exclude: ^playwright/drivers/browsers.json$
1010
- id: check-yaml
11+
- id: check-toml
1112
- id: requirements-txt-fixer
1213
- repo: https://github.com/psf/black
1314
rev: 20.8b1

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Build and install drivers:
2424
```sh
2525
pip install -e.
2626
python setup.py bdist_wheel
27+
# For all platforms
28+
python setup.py bdist_wheel --all
2729
```
2830

2931
Run tests:

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools-scm", "wheel", "auditwheel"]
3+
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ def extractall(zip: zipfile.ZipFile, path: str) -> None:
3737

3838

3939
class PlaywrightBDistWheelCommand(BDistWheelCommand):
40+
user_options = BDistWheelCommand.user_options + [
41+
("all", "a", "create wheels for all platforms")
42+
]
43+
boolean_options = BDistWheelCommand.boolean_options + ["all"]
44+
45+
def initialize_options(self) -> None:
46+
super().initialize_options()
47+
self.all = False
48+
4049
def run(self) -> None:
4150
if os.path.exists("build"):
4251
shutil.rmtree("build")
@@ -47,7 +56,16 @@ def run(self) -> None:
4756
super().run()
4857
os.makedirs("driver", exist_ok=True)
4958
os.makedirs("playwright/driver", exist_ok=True)
50-
for platform in ["mac", "linux", "win32", "win32_x64"]:
59+
platform_map = {
60+
"darwin": "mac",
61+
"linux": "linux",
62+
"win32": "win32_x64" if sys.maxsize > 2 ** 32 else "win32",
63+
}
64+
if self.all:
65+
platforms = ["mac", "linux", "win32", "win32_x64"]
66+
else:
67+
platforms = [platform_map[sys.platform]]
68+
for platform in platforms:
5169
zip_file = f"playwright-{driver_version}-{platform}.zip"
5270
if not os.path.exists("driver/" + zip_file):
5371
url = "https://playwright.azureedge.net/builds/driver/"
@@ -56,14 +74,10 @@ def run(self) -> None:
5674
print("Fetching ", url)
5775
# Don't replace this with urllib - Python won't have certificates to do SSL on all platforms.
5876
subprocess.check_call(["curl", url, "-o", "driver/" + zip_file])
59-
base_wheel_location = glob.glob("dist/*.whl")[0]
77+
base_wheel_location = glob.glob(os.path.join(self.dist_dir, "*.whl"))[0]
6078
without_platform = base_wheel_location[:-7]
61-
platform_map = {
62-
"darwin": "mac",
63-
"linux": "linux",
64-
"win32": "win32_x64" if sys.maxsize > 2 ** 32 else "win32",
65-
}
66-
for platform in ["mac", "linux", "win32", "win32_x64"]:
79+
80+
for platform in platforms:
6781
zip_file = f"driver/playwright-{driver_version}-{platform}.zip"
6882
with zipfile.ZipFile(zip_file, "r") as zip:
6983
extractall(zip, f"driver/{platform}")
@@ -88,26 +102,25 @@ def run(self) -> None:
88102
from_path = os.path.join(dir_path, file)
89103
to_path = os.path.relpath(from_path, driver_root)
90104
zip.write(from_path, f"playwright/driver/{to_path}")
91-
if platform == "mac":
105+
if platform == "mac" and self.all:
92106
# Ship mac both as 10_13 as and 11_0 universal to work across Macs.
93107
universal_location = without_platform + "macosx_11_0_universal2.whl"
94108
shutil.copyfile(wheel_location, universal_location)
95109
with zipfile.ZipFile(universal_location, "a") as zip:
96110
zip.writestr("playwright/driver/README.md", "Universal Mac package")
97111

98112
os.remove(base_wheel_location)
99-
for whlfile in glob.glob("dist/*.whl"):
100-
113+
for whlfile in glob.glob(os.path.join(self.dist_dir, "*.whl")):
101114
os.makedirs("wheelhouse", exist_ok=True)
102115
with InWheel(
103116
in_wheel=whlfile,
104117
out_wheel=os.path.join("wheelhouse", os.path.basename(whlfile)),
105118
ret_self=True,
106119
):
107120
print("Updating RECORD file of %s" % whlfile)
108-
shutil.rmtree("dist")
121+
shutil.rmtree(self.dist_dir)
109122
print("Copying new wheels")
110-
shutil.move("wheelhouse", "dist")
123+
shutil.move("wheelhouse", self.dist_dir)
111124

112125

113126
setuptools.setup(

0 commit comments

Comments
 (0)