Friday, 23 August 2013

Some way to create a cross-platform, self-contained, cloud-synchronized python library of modules?

Some way to create a cross-platform, self-contained, cloud-synchronized
python library of modules?

I have migrated all my personal, pet projects to Dropbox, and this
includes source code.
I enjoy using Python because I can switch to Windows or Linux machines,
and I just to execute scripts and they work right away, no matter which OS
or which specific machine I am using.
However, I would like to improve my workflow regarding REUSE of python
functionality, which is overwhelmingly duplicated. Due to inept/lazy
handling of imports, and the tendency to copy-paste imports to the same
folder of every new script, not to say reimplementing the same
micro-functionality over and over, I am seriously motivated to stop this
workflow and adhere to strong reuse by using better-crafted, DRYed
modules, and heavy importing, ending up with higher-level, lean,
problem-specific scripts.
It's important context that I've been "bitten" by the way .Net works in
VisualStudio, you just go on using namespaces right away (well, sort of,
provided the right references have been added, we know).
I have read quite a lot about *.pth files, init.py files, appending to
sys.path, but that has been quite confusing to me.
My goals would be:
Have a folder inside Dropbox (or GDrive, or whatever), with two
subfolders: Scripts and Modules
Scripts folder would contain only independent, single-file scripts,
possibly inside subfolders in arbitrary levels of nesting, but they should
not reference one another in any way, just reference the system-installed
Python modules AND the modules packaged in Scripts folder;
Modules folder should contain some hierarchical structure of folders and
namespaces, with higher-level modules importing/reusing lower-level
modules, and any of these modules using system-installed Python modules.
A typical workflow that would reflect my needs:
I create a script in one machine, and make it run properly;
Then I go to another machine (also with Dropbox), install some lacking
python modules (say, Numpy, or PIL), and then run the script I created in
the other machine;
I update the script, adding some imports to more already-existing modules
from Modules folder, and make it run properly. Ideally, the scripts would
contain minimal if any boilerplate code;
I come back to the previous machine, wait for Dropbox to sync, and run the
updated script right away!
I don't have a firm idea on how to achieve this, and my few previously
mentioned tries (with __init__ files and *.pth files) instead of simplify
ended up making everything more complicated. But I still think this is
something so natural, so obvious, that probably I am just missing
something that is widely known by the initiated.
Any help is welcome, thanks for reading!

No comments:

Post a Comment