-
-
Notifications
You must be signed in to change notification settings - Fork 13
Add processing of .pth files from "app_packages". #52
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
Add processing of .pth files from "app_packages". #52
Conversation
freakboy3742
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR; however, as noted on beeware/briefcase-windows-app-template#63, this isn't the best approach for a fix.
If you're using the default python interpreter, sitecustomize is really the only option you have for controlling the behavior of the interpreter. However, in our case, we're maintaining our own binary, so we don't need to rely on extension points - we can make the modification directly, and ensure that the stub app is started with the site modules that we want.
So - the better approach here is to modify the source of the stub binary to perform the site modifications - importing the site module, getting a handle to the addsitedir method, then invoking that method with a string argument. The patch to app_packages is currently being computed so it can be added to the module_search_paths (i.e., PYTHONPATH/sys.path); that would no longer be required, and the call to site.addsitedir() would be performed after the interpreter is initialized (i.e., inside the try{} block, but before the runpy invocation). The runpy code can be used as a template for how to import a module and invoke a method.
|
Alright, good point. I modified it as suggested. But now the Before: After: |
freakboy3742
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a heads up - this is going to be a slightly weird PR to land, because in addition to this change (which, with one modification flagged inline, looks great), we need to:
- Tag the repo to rebuild the stub binary used by the app template
- Update the app template to reference that new stub binary
- Add a change to Briefcase that is only a change note.
1 has to be done by someone on the core team; I can handle (2) as well.
I don't know your appetite for making the analogous change to the iOS, macOS-Xcode, Linux-system and Linux-Flatpak templates; but if you're up for it, we should probably make those changes as well before landing (3). There's also a fix needed for Android, but AFAIK it's not a "copy and paste + minor modifications" of this PR.
{{ cookiecutter.format }}/{{ cookiecutter.formal_name }}/Main.cpp
Outdated
Show resolved
Hide resolved
Good catch! That's definitely a technical backwards incompatibility, but I don't think I'm too concerned about it. The only way it would manifest is if an app is relying on an package installed in It might be worth mentioning this in a Briefcase release note as a backwards incompatibility - but I don't think that should stop us from making the change, given that the impact will be minimal, and we get correct |
|
So the changes for Windows-app I will leave to you. But I would like to try to make the analogous for the other platforms. Until the other platforms are ready, I would leave this PR marked as a draft, in case there are still things to be found on the other platforms that are also relevant here. I think at least iOS and Linux-system are a little bit more than just copy and paste, because of my findings in beeware/briefcase#2173 (comment) For iOS the handling of I will try it out, but it can take some time... I was also wondering where is the best place to add unit tests for |
Awesome - I look forward to seeing those patches.
That makes sense; I'll wait until they're all resolved before merging.
I recognise that the iOS issue needs special handling for debugging, but I'm fairly certain that work is independent of
Completely understood. Take whatever time you need; we're here to provide assistance if you need it.
That's a really good question. My suggestion would be to add a If we add to that repository an installable Python project (so, a subproject with it's own pyproject.toml) whose only purpose is to add a If we take that approach, then we'll end up with a There's a small "chicken-and-egg" problem though - If you add a |
Co-authored-by: Russell Keith-Magee <[email protected]>
{{ cookiecutter.format }}/{{ cookiecutter.formal_name }}/Main.cpp
Outdated
Show resolved
Hide resolved
freakboy3742
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome - works perfectly in my testing. Merging is still on hold until we're ready for everything to land, but as far as this PR is concerned, I think we're good.
As described here, the
app_packagesshould be added viasite.addsitedir()so that.pthfiles are executed correctly.I tested it using a manually created
.pthfile that executed a.pyfile with aprint. The output of the print was visible in the console withbriefcase run windows visualstudio.I also added
pywin32as a dependency in my application and tested it with the following code:Should fix beeware/briefcase#2195, beeware/briefcase#835, beeware/briefcase#669 and beeware/briefcase#381 for "windows visualstudio".
PR Checklist: