msgpack / msgpack-python

MessagePack serializer implementation for Python msgpack.org[Python]
https://msgpack.org/
Other
1.92k stars 230 forks source link

RFC: use relative imports instead of absolute? #356

Closed FelixSchwarz closed 5 years ago

FelixSchwarz commented 5 years ago

Currently msgpack uses absolute imports for its modules, e.g.:

if os.environ.get('MSGPACK_PUREPYTHON'):
    from msgpack.fallback import Packer, unpackb, Unpacker
else:
    try:
        from msgpack._cmsgpack import Packer, unpackb, Unpacker
    except ImportError:
        from msgpack.fallback import Packer, unpackb, Unpacker

Recently I worked on bundling msgpack inside another project to work around an incompatible system-wide install of msgpack (Fedora 30, borgbackup requires msgpack 0.5.6 but F30 ships 0.6.1).

One thing which made bundling a lot easier was to use relative imports in msgpack:

if os.environ.get('MSGPACK_PUREPYTHON'):
    from .fallback import Packer, unpackb, Unpacker
else:
    try:
        from ._cmsgpack import Packer, unpackb, Unpacker
    except ImportError:
        from .fallback import Packer, unpackb, Unpacker

That way I could copy msgpack's code to another location and it would not use the system-wide install.

I could create a PR if you would be interesting in merging this. Otherwise I'll carry some local patches for Fedora until we can drop the bundling.

methane commented 5 years ago

I'm OK for it.

FelixSchwarz commented 5 years ago

Ok, thanks. I added a pull request.