Skip to content

RFC: use relative imports instead of absolute? #356

Closed

Description

@FelixSchwarz

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.

Activity

  1. methane commented on May 10, 2019

    @methane
    Member

    I'm OK for it.

  2. FelixSchwarz commented on May 10, 2019

    @FelixSchwarz
    ContributorAuthor

    Ok, thanks. I added a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions