|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
| 15 | +import glob |
| 16 | +import os |
| 17 | +import shutil |
| 18 | +import stat |
| 19 | +import subprocess |
| 20 | +import sys |
| 21 | +import zipfile |
| 22 | + |
15 | 23 | import setuptools
|
| 24 | +from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand |
| 25 | + |
| 26 | +driver_version = "0.170.0-next.1605573954344" |
| 27 | + |
16 | 28 |
|
17 | 29 | with open("README.md", "r", encoding="utf-8") as fh:
|
18 | 30 | long_description = fh.read()
|
19 | 31 |
|
| 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 | + |
20 | 96 | setuptools.setup(
|
21 | 97 | name="playwright",
|
22 | 98 | author="Microsoft Corporation",
|
|
40 | 116 | "Operating System :: OS Independent",
|
41 | 117 | ],
|
42 | 118 | python_requires=">=3.7",
|
| 119 | + cmdclass={"bdist_wheel": PlaywrightBDistWheelCommand}, |
43 | 120 | use_scm_version={
|
44 | 121 | "version_scheme": "post-release",
|
45 | 122 | "write_to": "playwright/_repo_version.py",
|
|
0 commit comments