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

Assistance with dependencies containing native extensions #42

Open
genericmoniker opened this issue Jun 7, 2024 · 0 comments
Open

Assistance with dependencies containing native extensions #42

genericmoniker opened this issue Jun 7, 2024 · 0 comments

Comments

@genericmoniker
Copy link

First, this is a slick plugin for PDM-managed projects with pure-Python dependencies -- thanks!

Is your feature request related to a problem? Please describe.

Is is clear from the caveats section of the zipapp docs that Python cannot load a native/C extension from a zipapp. Some of the bugs logged against this project are caused by that (e.g. #11, #33) and have been closed as "not planned".

Describe the solution you'd like

The referenced zipapp caveats section also suggests how to ship a zipapp dependent on a C extension:

  1. "exclude that dependency from the zipfile, and ... ship it alongside your zipfile" and
  2. "include the directory containing the unzipped module in sys.path"

It would be nice if there were an easy way to generate output like that. For example, if I'm building myapp.pyz and I have a dependency on the "cryptography" library (among others), then I end up with:

myapp.pyz - My code and all of the zip safe dependencies
myapp-lib\ - A directory with all of the non-zip safe stuff installed, like cryptography

There would perhaps be an entrypoint shim that would insert myapp-lib\ into sys.path before calling the user-specified entrypoint.

Then I'd distribute both the zip file and the associated directory.

Describe alternatives you've considered

  1. Do some kind of yet-to-be-determined pre and/or post processing external to pdm-packer to get to the desired output (suggestions on this welcome).
  2. Use zipapps, a project that helps build zipapps with extensions, but which isn't as nicely integrated with PDM.
  3. Use PEX or shiv or something that is zipapp-ish.

Additional context

The zipapps project mentioned above actually includes packages with native extensions in the zip file and extracts them at runtime and adjusts sys.path. It can optionally do that automatically by looking for dependencies having .pyd or .so files at build time. For my situation, having them separate at build-time would be better, but I could see the extract thing being useful too.

Finally, a little feedback on the README.

  1. I wasn't sure whether external dependencies would be included in the zip file produced by pdm-packer at all. Maybe the brief description could be amended to say "A PDM plugin that packs your packages and their dependencies into a zipapp".
  2. Having tried it and discovering that it did include dependencies I saw the caveat "If the result zipapp contains binaries..." which made me think that it might also support C extensions, but only for a single platform.
  3. If this proposal is out-of-scope, that would make an excellent additional caveat -- that all dependencies must be pure-Python.
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

No branches or pull requests

1 participant