Skip to main content

Consolidates the shared object dependencies across multiple wheels

Project description

https://github.com/amol-/consolidatewheels/actions/workflows/tests.yml/badge.svg https://coveralls.io/repos/amol-/consolidatewheels/badge.svg https://img.shields.io/pypi/v/consolidatewheels.svg https://img.shields.io/pypi/pyversions/consolidatewheels.svg https://img.shields.io/pypi/l/consolidatewheels.svg

Introduction

When multiple wheels depend on each other and share some .so files, it is possible to rely on auditwheel --exclude to make sure the .so is included in only one of the wheels to avoid duplicating the file in every package.

That allows Python wheels to share the same .so as far as at least one of them is loading them in memory. See https://github.com/pypa/auditwheel/issues/76 and https://github.com/pypa/auditwheel/pull/368 for discussions on the topic.

The problem with this approach is that the package where the .so is included will have the library name mangled by auditwheel, while the ones where it’s excluded will reference to the library with its original name.

Suppose you have libone.whl and libtwo.whl both depending on libfoo.so, and libone is a dependency of libtwo so you already know you can include libfoo.so only in libone.whl, you could do:

auditwheel repair dist/libone.whl
auditwheel repair dist/libtwo.whl --exclude libfoo.so

In such case you would end up with the following wheels:

venv/lib/python3.10/site-packages/libone
├── __init__.py
├── _libone.cpython-310-aarch64-linux-gnu.so
venv/lib/python3.10/site-packages/libone.libs
└── libfoo-ef63151d.so
venv/lib/python3.10/site-packages/libtwo
├── __init__.py
├── _libtwo.cpython-310-aarch64-linux-gnu.so

The problem would be that while _libone.cpython-310-aarch64-linux-gnu.so was patched by auditwheel to know about the libfoo-ef63151d.so name, _libtwo.cpython-310-aarch64-linux-gnu.so was not, and so still refers to the original name:

$ ldd venv/lib/python3.10/site-packages/libone/_libone.cpython-310-aarch64-linux-gnu.so
    libfoo-ef63151d.so => ../libone.libs/libfoo-ef63151d.so (0x0000ffff8f8f0000)

$ ldd venv/lib/python3.10/site-packages/libtwo/_libtwo.cpython-310-aarch64-linux-gnu.so
    libfoo.so => not found

Which means that trying to import libtwo will fail with:

ImportError: libfoo.so: cannot open shared object file: No such file or directory

Which makes sense, because we actually provided libfoo-ef63151d.so and not libfoo.so.

To solve this problem consolidatewheels will patch all provided wheels to make sure that they share a single naming convention for libraries that were mangled.

After consolidatewheels is used, the final result would be:

$ ldd venv/lib/python3.10/site-packages/libone/_libone.cpython-310-aarch64-linux-gnu.so
    libfoo-ef63151d.so => ../libone.libs/libfoo-ef63151d.so (0x0000ffff8f8f0000)

$ ldd venv/lib/python3.10/site-packages/libtwo/_libtwo.cpython-310-aarch64-linux-gnu.so
    libfoo-ef63151d.so => not found

which would work correctly as far as libone is imported _before_ libtwo as they will both look for libfoo-ef63151d.so which was loaded already by libone.

OSX Support

consolidatewheels works also in conjunction with delocate, consolidating all libraries embedded by delocate and removing duplicates of the embedded libraries when they are provided in multiple wheels.

Install

Install with:

$ pip install consolidatewheels

Note that consolidatewheels requires patchelf to be available in the system, and it only works on Linux systems. But those are the same requirements that auditwheel has, so you are probably already satisfying them if you use auditwheel.

Usage

Usage instructions:

consolidatewheels --help

Example:

consolidatewheels libone.whl libtwo.whl --dest=./consolidated_wheels

For a more complex example and a testing environment, you can take a look at https://github.com/amol-/wheeldeps which uses consolidatewheels

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

consolidatewheels-0.3.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

consolidatewheels-0.3-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file consolidatewheels-0.3.tar.gz.

File metadata

  • Download URL: consolidatewheels-0.3.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for consolidatewheels-0.3.tar.gz
Algorithm Hash digest
SHA256 9bdb479b29afacc030c55cb775e633c3aa460308a1afd820a4fd06e9808c0f88
MD5 c00b000d09190f137152ba6f0350a34c
BLAKE2b-256 75d5d0bf0615ee39867bedd53ac940569692a55fd39ab990826ce3fd5ade454b

See more details on using hashes here.

File details

Details for the file consolidatewheels-0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for consolidatewheels-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1c16e55e010a1606d56257c31ced39017f7be124f47b5705e0e2d422b5bbe458
MD5 4b9f40bf46e79023e321730095c55576
BLAKE2b-256 1e1b9c5d7695c896eb47cd0e452b04bb858bc4a37ebdc82a532d8a4c261f8b9e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page