def import_structure(directory,structure_name='structure'): """Make a structure object based on thepian.conf.global_structure and structure variables found in the file specified. directory Current directory, or some other directory in the repository """ import imp, hashlib repo_dir, basedir, repo_type = find_basedir(directory) k = hashlib.sha1(structure_name + ":" + basedir).hexdigest() if k in _already_imported: return _already_imported[k] struct = Structure() struct.apply_basedir(repo_dir, basedir, repo_type) f, filename, description = imp.find_module(structure_name,[struct.CONF_DIR]) if not f: raise ImportError, "ad hoc structure, %s not found in %s" % (structure_name,struct.CONF_DIR) try: mod = imp.load_module("thepian.conf."+k, f, filename, description) struct.blend(mod) _already_imported[k] = struct finally: f.close() return struct
def test_base_Structure_class(): from os.path import dirname from thepian.conf import global_structure from thepian.conf.base import Structure structure = Structure() assert structure.__file__ == '' # All entries in global_structure are found in a new structure for name in dir(global_structure): if name == name.upper(): assert getattr(structure,name) == getattr(global_structure,name) # All entries in global_structure are found after blending in a blank structure module from samples import sample_structure repo_dir = basedir = dirname(sample_structure.__file__) structure.apply_basedir(repo_dir, basedir, "single") structure.blend(sample_structure) for name in dir(sample_structure): if name == name.upper(): assert getattr(structure,name) == getattr(sample_structure,name) assert structure.__file__ == sample_structure.__file__ # New properties are found after blending in a structure module from samples import sample_structure2 structure.blend(sample_structure2) assert structure.BOGUS == sample_structure2.BOGUS assert structure.SILLY_TUPLE == sample_structure2.SILLY_TUPLE assert structure.__file__ == sample_structure2.__file__