Search code examples
pythonpython-3.xvirtualenvpython-module

What is the best way to use a custom fork of a python library in another python project?


I am developing a python application. This application relies on an open source library that I have forked and heavily modified.

If it matters, the (very much WIP) forked library is available on github it it helps.

To import the forked library in my application, what I am currently doing is as follows:

sys.path.append(os.path.abspath(os.path.join(__file__, '..', '..', '..', '..', '..', 'couchdb')))
import couchdb

This works, but I'm not entirely happy with it for obvious reasons. It's far from elegant or flexible, and also seems to confuse my IDE. I feel like, especially in a language as elegant as Python, there ought to be a better way to simultaneously develop both an application and a library it depends on.

Both the library and the application are currently located side-by-side in a folder on my machine, sharing a virtual environment but residing in two separate git repositories. It is important to me that they remain in different git repositories, so nesting the library within the application is out, but the rest I'm happy to change.

I'm certain someone else has been in this situation before, so I'm hoping someone knows a way of doing this which is more "officially sanctioned" by Python.


Solution

  • The fact that your code is based on couchdb isn't really important, since it's not compatible with couchdb anymore, presumably. Just install it properly under its own unique name, then import it as you would any other module.

    import couchdbdmj
    

    Don't make your scripts depend on your development environment: configure your development environment to provide your custom modules in a uniform matter.