# HG changeset patch # User Jeff Hammel # Date 1304435208 25200 # Node ID 6fa6d987b3af7ad69825b844b47010ac3583cf20 initial commit of pyloader diff -r 000000000000 -r 6fa6d987b3af INSTALL.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/INSTALL.sh Tue May 03 08:06:48 2011 -0700 @@ -0,0 +1,27 @@ +#!/usr/bin/bash + +# installation script for pyloader +# Load python attributes from a string + +REPO='http://k0s.org/hg/pyloader' +DEST='pyloader' # name of the virtualenv + +if [ "$#" != "0" ] +then + DEST=$1 +fi + +if which virtualenv +then + virtualenv ${DEST} +else + curl https://bitbucket.org/ianb/virtualenv/raw/tip/virtualenv.py | python - ${DEST} +fi +cd ${DEST} +. bin/activate # linux only +mkdir src +cd src +hg clone ${REPO} +cd pyloader +python setup.py develop + diff -r 000000000000 -r 6fa6d987b3af README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Tue May 03 08:06:48 2011 -0700 @@ -0,0 +1,10 @@ +pyloader +=========== + +Load python attributes from a string + +---- + +Jeff Hammel +http://k0s.org/ + diff -r 000000000000 -r 6fa6d987b3af pyloader/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pyloader/__init__.py Tue May 03 08:06:48 2011 -0700 @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +""" +load modules and their attributes from a string +""" + +import imp +import os + +def import_dotted_path(module): + path = module.split('.') + module = __import__(module) + for name in path[1:]: + module = getattr(module, name) + return module + +def load(string): + """loads a string and returns a python object""" + + try: + if ':' in string: + path, target = string.split(':', 1) + if os.path.isabs(path) and os.path.exists(path): + # path to file + module = imp.load_source(path, path) + else: + module = import_dotted_path(path) + obj = module + while '.' in target: + attr, target = target.split('.', 1) + obj = getattr(obj, attr) + obj = getattr(obj, target) + return obj + else: + # module: dotted path + return import_dotted_path(string) + except: + print string + raise + + # TODO: entry points + +if __name__ == '__main__': + import sys + for i in sys.argv[1:]: + print load(i) diff -r 000000000000 -r 6fa6d987b3af setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Tue May 03 08:06:48 2011 -0700 @@ -0,0 +1,31 @@ +import os +from setuptools import setup, find_packages + +try: + here = os.path.dirname(os.path.abspath(__file__)) + description = file(os.path.join(here, 'README.txt')).read() +except IOError: + description = '' + +version = "0.1" +dependencies = [] + +setup(name='pyloader', + version=version, + description="Load python attributes from a string", + long_description=description, + classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers + author='Jeff Hammel', + author_email='jhammel@mozilla.com', + url='http://k0s.org/', + license='MPL', + packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), + include_package_data=True, + zip_safe=False, + install_requires=dependencies, + entry_points=""" + # -*- Entry points: -*- + """, + ) + +