Would it be possible to create a python module that lazily downloads and installs submodules as needed? I've worked with "subclassed" modules that mimic real modules, but I've never tried to do so with downloads involved. Is there a guaranteed directory that I can download source code and data to, that the module would then be able to use on subsequent runs?
To make this more concrete, here is the ideal behavior:
- User runs
pip install magic_module
and the lightweightmagic_module
is installed to their system. - User runs the code
import magic_module.alpha
- The code goes to a predetermine URL, is told that there is an "
alpha
" subpackage, and is then given the URLs ofalpha.py
andalpha.csv
files. - The system downloads these files to somewhere that it knows about, and then loads the
alpha
module. - On subsequent runs, the user is able to take advantage of the downloaded files to skip the server trip.
- At some point down the road, the user could run a
import magic_module.alpha ; alpha._upgrade()
function from the command line to clear the cache and get the latest version.
Is this possible? Is this reasonable? What kinds of problems will I run into with permissions?