Browse Source

Added dynamic object loader utility for plugin support

main
Lakshmi Vyasarajan 14 years ago
parent
commit
1225852f38
3 changed files with 33 additions and 1 deletions
  1. +0
    -1
      hyde/tests/test_model.py
  2. +19
    -0
      hyde/tests/test_util.py
  3. +14
    -0
      hyde/util.py

+ 0
- 1
hyde/tests/test_model.py View File

@@ -65,7 +65,6 @@ class TestConfig(object):

assert c.deploy_root_path == TEST_SITE_ROOT.child_folder('deploy')


def test_conf1(self):
c = Config(sitepath=TEST_SITE_ROOT, config_dict=yaml.load(self.conf1))
assert c.content_root_path == TEST_SITE_ROOT.child_folder('stuff')


+ 19
- 0
hyde/tests/test_util.py View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
"""
Use nose
`$ pip install nose`
`$ nosetests`
"""

from hyde.util import load_python_object
import os

def test_can_load_locals():

file_class = load_python_object('hyde.fs.File')
assert file_class

f = file_class(__file__)
assert f

assert f.name == os.path.basename(__file__)

+ 14
- 0
hyde/util.py View File

@@ -0,0 +1,14 @@
"""
Hyde utilities
"""
import sys


def load_python_object(name):
"""
Loads a python module from string
"""
(module_name, _ , object_name) = name.rpartition(".")
__import__(module_name)
module = sys.modules[module_name]
return getattr(module, object_name)

Loading…
Cancel
Save