|
14 | 14 |
|
15 | 15 | import gzip
|
16 | 16 | import os
|
| 17 | +import re |
17 | 18 | import shutil
|
18 | 19 | import subprocess
|
| 20 | +from pathlib import Path |
19 | 21 |
|
20 |
| -driver_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "driver") |
21 |
| -package_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "playwright") |
22 |
| -drivers_path = os.path.join(package_path, "drivers") |
| 22 | +_dirname = Path(os.path.dirname(os.path.abspath(__file__))) |
23 | 23 |
|
24 |
| -if os.path.exists(os.path.join(driver_path, "package-lock.json")): |
25 |
| - os.remove(os.path.join(driver_path, "package-lock.json")) |
26 |
| -if os.path.exists(os.path.join(driver_path, "node_modules")): |
27 |
| - shutil.rmtree(os.path.join(driver_path, "node_modules")) |
28 |
| -if os.path.exists(os.path.join(driver_path, "out")): |
29 |
| - shutil.rmtree(os.path.join(driver_path, "out")) |
| 24 | +driver_path = _dirname / "driver" |
| 25 | +package_path = _dirname / "playwright" |
| 26 | +drivers_path = package_path / "drivers" |
| 27 | + |
| 28 | +if (driver_path / "package-lock.json").exists(): |
| 29 | + os.remove(driver_path / "package-lock.json") |
| 30 | +if (driver_path / "node_modules").exists(): |
| 31 | + shutil.rmtree(driver_path / "node_modules") |
| 32 | +if (driver_path / "out").exists(): |
| 33 | + shutil.rmtree(driver_path / "out") |
30 | 34 |
|
31 | 35 | subprocess.run("npm i", cwd=driver_path, shell=True)
|
32 | 36 | subprocess.run("npm run bake", cwd=driver_path, shell=True)
|
33 | 37 |
|
34 | 38 | for driver in ["driver-linux", "driver-macos", "driver-win.exe"]:
|
35 |
| - if os.path.exists(os.path.join(package_path, driver)): |
36 |
| - os.remove(os.path.join(package_path, driver)) |
| 39 | + if (package_path / driver).exists(): |
| 40 | + os.remove((package_path / driver)) |
37 | 41 |
|
38 |
| - in_path = os.path.join(driver_path, "out", driver) |
39 |
| - out_path = os.path.join(drivers_path, driver + ".gz") |
| 42 | + in_path = driver_path / "out" / driver |
| 43 | + out_path = drivers_path / (driver + ".gz") |
40 | 44 | with open(in_path, "rb") as f_in, gzip.open(out_path, "wb") as f_out:
|
41 | 45 | shutil.copyfileobj(f_in, f_out)
|
42 | 46 |
|
| 47 | +node_modules_playwright = driver_path / "node_modules" / "playwright" |
| 48 | + |
43 | 49 | shutil.copyfile(
|
44 |
| - os.path.join(driver_path, "node_modules", "playwright", "browsers.json"), |
45 |
| - os.path.join(drivers_path, "browsers.json"), |
| 50 | + node_modules_playwright / "browsers.json", drivers_path / "browsers.json", |
46 | 51 | )
|
| 52 | + |
| 53 | +upstream_readme = (node_modules_playwright / "README.md").read_text() |
| 54 | +pw_python_readme = (_dirname / "README.md").read_text() |
| 55 | + |
| 56 | +matches = re.findall(r"<!-- GEN:(.*?) -->(.*?)<!-- GEN:stop -->", upstream_readme) |
| 57 | + |
| 58 | +for key, value in matches: |
| 59 | + pw_python_readme = re.sub( |
| 60 | + rf"(<!-- GEN:{key} -->).*?(<!-- GEN:stop -->)", |
| 61 | + f"<!-- GEN:{key} -->{value}<!-- GEN:stop -->", |
| 62 | + pw_python_readme, |
| 63 | + ) |
| 64 | + |
| 65 | +(_dirname / "README.md").write_text(pw_python_readme) |
0 commit comments