0

Sometimes when I'm working in a large package, I'll find that there's behavior that's very difficult to work around in one of the dependencies, and sometimes the only way to implement a solution and move on is to alter a module in the dependency and wait for a fix or a new feature from the developers. Just to make this more concrete, imagine the workaround is in matplotlib.legend.py. Here's where how my project might be packaged:

myproject
   bundled
       legend.py
   a.py
   b.py
   c.py

And until a new version of matplotlib is released that fixes some bug or implements some feature, I just make calls like:

from bundled.legend import X,Y,Z

Obviously this works sometimes, but often I have to bundle several modules to get the behavior.

Sometimes doing this is the only way I can move forward on a project, but I don't know how other engineers would react to this practice. Is this an acceptable practice in python? A lot of times it's not just workarounds that motivate this, but customization or adding some features particular to myproject that are deep into the module.

Adam Hughes
  • 14,601
  • 12
  • 83
  • 122

1 Answers1

2

This will not always work as you expect. Imagine the following case.

  1. User installs very old version of legend.
  2. User install your package with a newer bundles version of legend

Now, in your code, you do

from bundled.legend import X

BUT, in legend.x is says

from legend import Y

It could import Y from the old version of legend the user installed.

You might want to take a look at: Embedding a Python library in my own package

Community
  • 1
  • 1
Nick Humrich
  • 14,905
  • 8
  • 62
  • 85