Skip to content

Assistance with dependencies containing native extensions #42

@genericmoniker

Description

@genericmoniker

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions