Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare support for Nuitka #2435

Merged
merged 4 commits into from
May 24, 2024
Merged

prepare support for Nuitka #2435

merged 4 commits into from
May 24, 2024

Conversation

KRRT7
Copy link
Contributor

@KRRT7 KRRT7 commented May 10, 2024

this PR will prepare playwright to make it easier to be compiled into standalone / onefile programs for ease of distribution
the following changes have been made:

  1. added the python version of
const registryDirectory = exports.registryDirectory

in playwright._impl._driver, Nuitka will use this to resolve the path to the browsers .

  1. check if _compiled__ is in the globals dict, if it is, set PLAYWRIGHT_BROWSERS_PATH to 0 just like for pyinstaller

@KRRT7
Copy link
Contributor Author

KRRT7 commented May 10, 2024

@microsoft-github-policy-service agree

@KRRT7
Copy link
Contributor Author

KRRT7 commented May 10, 2024

@KRRT7 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@mxschmitt
Copy link
Member

happy to accept the changes in playwright/_impl/_transport.py. What is the rationale of adding the get_registry_directory method? Its not used.

@KRRT7
Copy link
Contributor Author

KRRT7 commented May 24, 2024

happy to accept the changes in playwright/_impl/_transport.py. What is the rationale of adding the get_registry_directory method? Its not used.

happy to accept the changes in playwright/_impl/_transport.py. What is the rationale of adding the get_registry_directory method? Its not used.

we need a way to know the paths of where the browsers are stored, nuitka would use this to determine the locations in order to bundle the browsers, if playwright isn't happy providing it directly from playwright itself, we could also patch it from nuitka ourselves, but it would make it far easier if it was within playwright already.

@mxschmitt
Copy link
Member

We have the following workflow for Pyinstaller, that should also work for Nuitka?

  1. PLAYWRIGHT_BROWSERS_PATH=0 playwright install chromium This will install the browsers locally, inside the site-modules directory.
  2. pyinstaller -F main.py This will bundle the site-modules directory.

If Nuitka isn't bundling all the files inside the site-modules directory, we recommend instead do do something like this:

  1. PLAYWRIGHT_BROWSERS_PATH=./browsers playwright install chromium This will install the browsers locally inside ./browsers.
  2. And set PLAYWRIGHT_BROWSERS_PATH=./browsers inside your program, so Playwright knows about it.

I'm not a huge fan of get_registry_directory since in my case, it contains 50 browsers, for a lot of Playwright versions - we'd need to match first while the solution above allows you to install only what you want.

@KRRT7
Copy link
Contributor Author

KRRT7 commented May 24, 2024

we don't like affecting the user experience, so we generally just look wherever the program looks and go from there, this is in case the user runs from either an venv, or global packages, users don't normally set the PLAYWRIGHT_BROWSERS_PATH=0 flag unless they're using pyinstaller or set PLAYWRIGHT_BROWSERS_PATH unless they want the browsers in different location, we're also looking into the directory ourselves so that we can look thru the folder and see what browsers are available, and then we prompt the user on which one they want to use as to avoid including unnecesary bloat, i.e including all browsers when they're only using a particular one, however i'll be happy with just the changes in playwright/_impl/_transport.py :)

@KRRT7
Copy link
Contributor Author

KRRT7 commented May 24, 2024

another question, i see playwright downloads ffmpeg when you do a bare playwright install, i would like to know when ffmpeg is used or not so that we also know when to bundle it? thanks.

@mxschmitt
Copy link
Member

another question, i see playwright downloads ffmpeg when you do a bare playwright install, i would like to know when ffmpeg is used or not so that we also know when to bundle it? thanks.

ffmpeg is needed for chromium based browsers in order to record video.

however i'll be happy with just the changes in playwright/_impl/_transport.py :

let's do that, then the Nuitka experience is on par with Pyinstaller.

@mxschmitt mxschmitt merged commit 2402e12 into microsoft:main May 24, 2024
35 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants