building: BUNDLE: exempt collected .py/.pyc files from relocation#7180
Conversation
In macOS .app bundles, exempt the .py and .pyc files that are collected as DATA files from being relocated from Contents/MacOS to Contents/Resources (and then symlinked back). In certain scenarios (such as OpenCV loader's code), the path to a .py file needs to resolve to the directory that contains the adjacent binary extensions; i.e., the original directory in Contents/MacOS, beaucse the extensions are not relocated. This might introduce regressions with bundle signing and notarization that we cannot test, hence the breaking change news entry. But to my knowledge, the main source of problems with that are dots in the directory names, which should not be the problem with directory- and base names of the collected .py/.pyc files.
What would it take to test it? A real codesigning certificate and an application containing |
|
I think for codesigning test, the ad-hoc signing that we do by default is sufficient - if there's something that The regression part is meant more generally, though, as it might involve any package where we collect source .py files as DATA files (for example, |
| if typ == 'DATA' and base_path not in _QT_BASE_PATH: | ||
| # Exempt python source files from this relocation, because their real path might need to resolve | ||
| # to the directory that also contains the extension module. | ||
| relocate_file = type == 'DATA' and base_path not in _QT_BASE_PATH |
There was a problem hiding this comment.
@rokm @bwoodsend A test is definitely needed as nothing caught the typo here type should be typ which means that no files are relocated ever
There was a problem hiding this comment.
Indeed. The effect of this error should be caught by the metadata collection test that will be added in #7187.
Thanks for investigating and fixing the regression!
I can give some background what kind of issues with signing you can expect when there is a .py file, as we had some serious trouble with this in the past on MusicBrainz Picard and it can be hard to figure out the root cause when users report broken signatures. macOS expects every file in the app bundle to be digitally signed. For the binaries placed in Now the app signing has two strategies how to still add signatures to these files. For files in But for files in This second part is difficult and can lead to surprising results: After signing everything seems to be fine. If you check the signatures after building everything is ok. You can also package the files up in a .dmg image, distribute it, and it will seemingly work. But file attributes can easily get lost. E.g. if users copy the app to a file system without support for extended attributes the signature break (I think this happens when users have disks formatted with the old HFS file system instead of the newer APFS). Also zipping the app bundle can I think cause the attributes to get lost. So if you want to have reliable signed app bundles placing file types for which the signature cannot be placed as part of the file itself in |
|
This change broke Pyzo. We intentionally include |
No, but you can relocate the problematic files yourself once the bundle is generated. |
|
Also, unless you prefer to have |
|
Thanks for the detailed help 🙏 you even took the time to dive into the obscurities of our freezing process :) |
|
If I manually move some files around after PyInstaller is doen, it breaks the signatures, rendering the application "broken". Can I tell PyInstaller to redo the signing in such a case? |
Not, but you can re-sign your bundle yourself after post-processing it. |
I.e., use the equivalent of the command PyInstaller is using here (and here): for ad-hoc and if you use signing cert. |
|
I decided to have a go at code signing with a proper certificate, on GH Actions. Bit of a rough ride, but it looks like it worked. I documented what I did on this PR: pyzo/pyzo#842 |
In macOS .app bundles, exempt the .py and .pyc files that are collected as DATA files from being relocated from Contents/MacOS to Contents/Resources (and then symlinked back).
In certain scenarios (such as OpenCV loader's code), the path to a .py file needs to resolve to the directory that contains the adjacent binary extensions; i.e., the original directory in Contents/MacOS, beaucse the extensions are not relocated.
This might introduce regressions with bundle signing and notarization that we cannot test, hence the breaking change news entry. But to my knowledge, the main source of problems with that are dots in the directory names, which should not be the problem with directory- and base names of the collected .py/.pyc files.
Fixes #7128.