changeset 0:6fa6d987b3af

initial commit of pyloader
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 03 May 2011 08:06:48 -0700
parents
children 47d9472e7754
files INSTALL.sh README.txt pyloader/__init__.py setup.py
diffstat 4 files changed, 114 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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
+
--- /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/
+
--- /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)
--- /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: -*-
+      """,
+      )
+      
+