summaryrefslogtreecommitdiff
path: root/www/py-playwright
diff options
context:
space:
mode:
Diffstat (limited to 'www/py-playwright')
-rw-r--r--www/py-playwright/Makefile91
-rw-r--r--www/py-playwright/distinfo5
-rw-r--r--www/py-playwright/files/patch-pyproject.toml17
-rw-r--r--www/py-playwright/files/patch-setup.py28
-rw-r--r--www/py-playwright/files/test-async.py14
-rw-r--r--www/py-playwright/files/test-sync.py11
-rw-r--r--www/py-playwright/pkg-descr3
-rw-r--r--www/py-playwright/pkg-message21
8 files changed, 190 insertions, 0 deletions
diff --git a/www/py-playwright/Makefile b/www/py-playwright/Makefile
new file mode 100644
index 000000000000..057b2947048e
--- /dev/null
+++ b/www/py-playwright/Makefile
@@ -0,0 +1,91 @@
+PORTNAME= playwright
+DISTVERSIONPREFIX= v
+DISTVERSION= 1.55.0
+CATEGORIES= www python
+#MASTER_SITES= PYPI # no tarball
+MASTER_SITES+= https://playwright.azureedge.net/builds/driver/next/:driver # zip archive with JS scripts called "driver" are bundled with the Python module
+PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX}
+DISTFILES= playwright-${DISTVERSION}-beta-1756314050000-linux.zip:driver
+EXTRACT_ONLY= ${DISTNAME}${EXTRACT_SUFX} # do not extract the JS scripts archive
+
+MAINTAINER= yuri@FreeBSD.org
+COMMENT= High-level API to automate web browsers
+WWW= https://playwright.dev/python/ \
+ https://github.com/Microsoft/playwright-python
+
+LICENSE= APACHE20
+LICENSE_FILE= ${WRKSRC}/LICENSE
+
+BUILD_DEPENDS= ${PY_SETUPTOOLS} \
+ ${PYTHON_PKGNAMEPREFIX}setuptools-scm>=0:devel/py-setuptools-scm@${PY_FLAVOR} \
+ ${PYTHON_PKGNAMEPREFIX}wheel>=0.45.1:devel/py-wheel@${PY_FLAVOR} \
+ curl:ftp/curl
+LINUX_DEPENDS= linux-${LINUX_BASE}-alsa-lib>0:audio/linux-${LINUX_BASE}-alsa-lib \
+ linux-${LINUX_BASE}-at-spi2-atk>0:accessibility/linux-${LINUX_BASE}-at-spi2-atk \
+ linux-${LINUX_BASE}-atk>0:accessibility/linux-${LINUX_BASE}-atk \
+ linux-${LINUX_BASE}-cairo>0:graphics/linux-${LINUX_BASE}-cairo \
+ linux-${LINUX_BASE}-cups-libs>0:print/linux-${LINUX_BASE}-cups-libs \
+ linux-${LINUX_BASE}-dbus-libs>0:devel/linux-${LINUX_BASE}-dbus-libs \
+ linux-${LINUX_BASE}-dri>0:graphics/linux-${LINUX_BASE}-dri \
+ linux-${LINUX_BASE}-gstreamer1>0:multimedia/linux-${LINUX_BASE}-gstreamer1 \
+ linux-${LINUX_BASE}-libxkbcommon>0:x11/linux-${LINUX_BASE}-libxkbcommon \
+ linux-${LINUX_BASE}-nspr>0:devel/linux-${LINUX_BASE}-nspr \
+ linux-${LINUX_BASE}-nss>0:security/linux-${LINUX_BASE}-nss \
+ linux-${LINUX_BASE}-pango>0:x11-toolkits/linux-${LINUX_BASE}-pango
+RUN_DEPENDS= ${PYTHON_PKGNAMEPREFIX}greenlet>=3.1.1:devel/py-greenlet@${PY_FLAVOR} \
+ ${PYTHON_PKGNAMEPREFIX}pyee>=13:devel/py-pyee@${PY_FLAVOR}
+RUN_DEPENDS+= node24>0:www/node24 \
+ ${LINUX_DEPENDS}
+
+USES= linux:rl9 python
+USE_PYTHON= pep517 concurrent autoplist
+
+USE_GITHUB= yes
+GH_ACCOUNT= Microsoft
+GH_PROJECT= playwright-python
+
+LINUX_BASE= ${linux_ARGS}
+
+MAKE_ENV= SETUPTOOLS_SCM_PRETEND_VERSION=${PORTVERSION}
+
+XARCH:= ${ARCH:S/amd64/x64/}
+
+NO_ARCH= yes
+
+TEST_ENV= ${MAKE_ENV} PYTHONPATH=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}
+
+post-patch: # replace URL in JS scripts with DISTDIR
+ @${REINPLACE_CMD} \
+ -e 's|url = "https://playwright.azureedge.net/builds/driver/"|url = "file://${DISTDIR}/"|' \
+ ${WRKSRC}/setup.py
+
+post-install:
+ # replace node binary from the zip archive with JS scripts with the FreeBSD native binary
+ @cd ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/playwright/driver && \
+ ${RM} node && \
+ ${LN} -s ${LOCALBASE}/bin/node
+ # patch JS scripts: process.platform
+ @${GREP} -rl 'process.platform === "linux"' ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR} | \
+ ${GREP} "\.js$$" | \
+ ${XARGS} ${REINPLACE_CMD} -i '' \
+ -e 's/process.platform === "linux"/(process.platform === "linux" || process.platform === "freebsd")/'
+ @${GREP} -rl 'process.platform !== "linux"' ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR} | \
+ ${GREP} "\.js$$" | \
+ ${XARGS} ${REINPLACE_CMD} -i '' \
+ -e 's/process.platform !== "linux"/(process.platform !== "linux" \&\& process.platform !== "freebsd")/'
+ # patch JS scripts: env var PLAYWRIGHT_HOST_PLATFORM_OVERRIDE
+ @${REINPLACE_CMD} \
+ -i '' -e 's/if (process.env.PLAYWRIGHT_HOST_PLATFORM_OVERRIDE) {/if (true) {/' \
+ ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/playwright/driver/package/lib/server/utils/hostPlatform.js
+ @${REINPLACE_CMD} \
+ -i '' -e 's/process.env.PLAYWRIGHT_HOST_PLATFORM_OVERRIDE/"ubuntu24.04-${XARCH}"/' \
+ ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/playwright/driver/package/lib/server/utils/hostPlatform.js
+
+do-test:
+ @${SETENV} ${TEST_ENV} ${STAGEDIR}${PREFIX}/bin/playwright install
+.for test in test-sync.py test-async.py
+ @cd ${TEST_WRKSRC} && \
+ ${SETENV} ${TEST_ENV} ${PYTHON_CMD} ${FILESDIR}/${test}
+.endfor
+
+.include <bsd.port.mk>
diff --git a/www/py-playwright/distinfo b/www/py-playwright/distinfo
new file mode 100644
index 000000000000..501588f73d6f
--- /dev/null
+++ b/www/py-playwright/distinfo
@@ -0,0 +1,5 @@
+TIMESTAMP = 1756920881
+SHA256 (playwright-1.55.0-beta-1756314050000-linux.zip) = 12d54c1be52afeb66fd386e14abceaa75bdff79005f50275a4dbac0abf4efba5
+SIZE (playwright-1.55.0-beta-1756314050000-linux.zip) = 45573547
+SHA256 (Microsoft-playwright-python-v1.55.0_GH0.tar.gz) = adda41b4a6c02f414d535b7a0e03bc5f4c4f77fb3d4ef3028f8b609ca71f3613
+SIZE (Microsoft-playwright-python-v1.55.0_GH0.tar.gz) = 1343981
diff --git a/www/py-playwright/files/patch-pyproject.toml b/www/py-playwright/files/patch-pyproject.toml
new file mode 100644
index 000000000000..7991fde60245
--- /dev/null
+++ b/www/py-playwright/files/patch-pyproject.toml
@@ -0,0 +1,17 @@
+--- pyproject.toml.orig 2025-09-02 18:47:12 UTC
++++ pyproject.toml
+@@ -1,5 +1,5 @@
+ [build-system]
+-requires = ["setuptools==80.9.0", "setuptools-scm==8.3.1", "wheel==0.45.1", "auditwheel==6.2.0"]
++requires = ["setuptools", "setuptools-scm", "wheel"]
+ build-backend = "setuptools.build_meta"
+
+ [project]
+@@ -9,7 +9,6 @@ readme = "README.md"
+ {name = "Microsoft Corporation"}
+ ]
+ readme = "README.md"
+-license = "Apache-2.0"
+ dynamic = ["version"]
+ requires-python = ">=3.9"
+ # Please when changing dependencies run the following commands to update requirements.txt:
diff --git a/www/py-playwright/files/patch-setup.py b/www/py-playwright/files/patch-setup.py
new file mode 100644
index 000000000000..1b7831869548
--- /dev/null
+++ b/www/py-playwright/files/patch-setup.py
@@ -0,0 +1,28 @@
+--- setup.py.orig 2025-08-28 09:27:29 UTC
++++ setup.py
+@@ -74,6 +74,16 @@ base_wheel_bundles = [
+ },
+ ]
+
++# override for FreeBSD: use the Linux one and update the node binary in it
++base_wheel_bundles = [
++ {
++ "wheel": "manylinux1_x86_64.whl",
++ "machine": platform.machine().lower(),
++ "platform": sys.platform,
++ "zip_name": "linux",
++ }
++]
++
+ if len(sys.argv) == 2 and sys.argv[1] == "--list-wheels":
+ for bundle in base_wheel_bundles:
+ print(bundle["wheel"])
+@@ -108,7 +118,7 @@ def download_driver(zip_name: str) -> None:
+ or "-beta" in driver_version
+ or "-next" in driver_version
+ ):
+- url = url + "next/"
++ pass # do not alter the URL
+ url = url + zip_file
+ temp_destination_path = destination_path + ".tmp"
+ print(f"Fetching {url}")
diff --git a/www/py-playwright/files/test-async.py b/www/py-playwright/files/test-async.py
new file mode 100644
index 000000000000..f047304580c0
--- /dev/null
+++ b/www/py-playwright/files/test-async.py
@@ -0,0 +1,14 @@
+import asyncio
+from playwright.async_api import async_playwright
+
+async def main():
+ async with async_playwright() as p:
+ #for browser_type in [p.chromium, p.firefox, p.webkit]:
+ for browser_type in [p.firefox]:
+ browser = await browser_type.launch()
+ page = await browser.new_page()
+ await page.goto('http://playwright.dev')
+ await page.screenshot(path=f'example-{browser_type.name}-async.png')
+ await browser.close()
+
+asyncio.run(main())
diff --git a/www/py-playwright/files/test-sync.py b/www/py-playwright/files/test-sync.py
new file mode 100644
index 000000000000..19e028c11173
--- /dev/null
+++ b/www/py-playwright/files/test-sync.py
@@ -0,0 +1,11 @@
+from playwright.sync_api import sync_playwright
+
+with sync_playwright() as p:
+ #for browser_type in [p.chromium, p.firefox, p.webkit]:
+ for browser_type in [p.firefox]:
+ browser = browser_type.launch()
+ page = browser.new_page()
+ page.goto('http://playwright.dev')
+ page.screenshot(path=f'example-{browser_type.name}-sync.png')
+ browser.close()
+
diff --git a/www/py-playwright/pkg-descr b/www/py-playwright/pkg-descr
new file mode 100644
index 000000000000..70f80f94f54e
--- /dev/null
+++ b/www/py-playwright/pkg-descr
@@ -0,0 +1,3 @@
+Playwright is a Python library to automate Chromium, Firefox and WebKit browsers
+with a single API. Playwright delivers automation that is ever-green, capable,
+reliable and fast.
diff --git a/www/py-playwright/pkg-message b/www/py-playwright/pkg-message
new file mode 100644
index 000000000000..1a8265fbce37
--- /dev/null
+++ b/www/py-playwright/pkg-message
@@ -0,0 +1,21 @@
+[
+{ type: install
+ message: <<EOM
+You installed playwright: API to automate web browsers.
+
+playright expects Linuxlator to be initialized because it
+downloads and runs Linux binaries for web browsers and
+ffmpeg.
+playwright is known to work with linux_base-rl9.
+
+playright is supposed to work with 3 browsers: Chrome, Firefox, WebKit.
+
+Chrome is currently broken: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=289285
+WebKit is also broken due to missing dependencies.
+
+You are expected to run the command 'playwright install' to download
+browser binaries before you can use playwright.
+
+EOM
+}
+]