From: magnus.lycka on
I'd like to have the following structure of my Python code:

I have a directory called 'mysystem'. In this directory, I have files
'comp1.zip' and 'comp2.zip' etc which are zipped archives with python
packages and modules.

I'd like to be able to use them like this in my code:

import mysystem.comp1.module
import mysystem.comp2.package.module

etc.

Can I do that? I guess it requires that the __init__.py in mysystem is
written in a clever way, but it's not clear how to do this, and I
don't find a lot on this in any Python books or on the net.

I tried:

mysystem/__init__.py:

import sys
import os
dir = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(dir, 'comp1.zip'))
import comp1

That doesn't do what I want. To access comp1 with this __init__.py
I'll have to do

import mysystem
import comp1.module

instead of

import mysystem.comp1.module

:-(


Optionally, I'd like to be able to patch the system by putting a
module.py in mysystem/comp2/package/ and get that to override the
'package/module.py' in comp2.zip. It's OK if I need to patch
__init__.py in mysystem to do that.