def build_transform_lookup(force=False): """ Build translation table for all available transforms from PACKAGES/transforms.py """ if transforms and not settings.NOCACHE: print 'Using cached transforms file.' return for pack_name in settings.INSTALLED_MATH_PACKAGES: print 'Importing transforms from ... ' + pack_name pack_module = import_module('packages.' + pack_name) # Load PACKAGE/rules.py if module_has_submodule(pack_module, 'transforms'): path = pack_name + '.transforms' pack_transforms = import_module('packages.' + path, settings.ROOT_MODULE) transforms.make_writable() for name, symbol in pack_transforms.__dict__.iteritems(): if is_mapping(symbol): symbol.package = pack_name transforms[name] = symbol transforms.sync()
def build_pure_lookup(force=False): if pure_trans.loaded and not force: return for name in settings.INSTALLED_MATH_PACKAGES: pack_module = load_package(name) package = wise.meta_inspector.PACKAGES[name] if module_has_submodule(pack_module, 'objects'): print 'Building Pure translation table from ... ' + name pack_objects = load_package_module(name,'objects') super_clss, nullary_types = pack_objects.initialize() # Populate the Pure translation table with nullary # objects pure_trans.populate(nullary_types) _pure_trans = {} for cls in python_trans.table.values(): if hasattr(cls,'pure'): _pure_trans[cls.pure] = cls pure_trans.populate(_pure_trans) return pure_trans
def build_python_lookup(force=False): if python_trans.loaded and not force: return for name in settings.INSTALLED_MATH_PACKAGES: pack_module = load_package(name) package = wise.meta_inspector.PACKAGES[name] if module_has_submodule(pack_module, 'objects'): print 'Building Python translation table from ... ' + name pack_objects = load_package_module(name,'objects') super_clss, nullary_types = pack_objects.initialize() first_order_symbols, all_symbols = collect_objects(name, recursive=True) python_trans.populate(first_order_symbols) python_trans.populate(all_symbols) # Give the package a list of strings containing the # classnames of the provided symbols and update the # persistence in memory value and sync to the disk if not package.provided_symbols: wise.meta_inspector.PACKAGES.make_writable() for sym in first_order_symbols.iterkeys(): package.provides(sym) wise.meta_inspector.PACKAGES[name] = package wise.meta_inspector.PACKAGES.sync() else: if settings.DEBUG: pass #print 'Not rebuilding symbol table for:', name return python_trans
def build_rule_lookup(force=False): """ Build translation table for all available rules from PACKAGES/rules.py """ if rulesets and not settings.NOCACHE: print 'Using cached rulesets file.' BUILD_RULESETS = False else: BUILD_RULESETS = True if rules and not settings.NOCACHE: print 'Using cached rules file.' BUILD_RULES = False else: BUILD_RULES = True if not (BUILD_RULESETS and BUILD_RULES): return for name in settings.INSTALLED_MATH_PACKAGES: pack_module = import_module('packages.' + name) # Load PACKAGE/rules.py if module_has_submodule(pack_module, 'rules'): print 'Importing rules from ... ' + name path = name + '.rules' pack_objects = import_module('packages.' + path, settings.ROOT_MODULE) # Build mathobjects.rulesets: # ------------------------ # get PACKAGE.rules.panel ( a dictionary object ) # which contains the hierarchy of rules to use in the # worksheet panels. Looks something like: # {'Commutative Algebra': ['algebra_normal if BUILD_RULESETS: rulesets.make_writable() rulesets.update(pack_objects.panel) rulesets.sync() # Build mathobjects.rules: # ------------------------ # Scrape all classes of type `PublicRule` from teh # module and load into the if BUILD_RULES: rules.make_writable() for name, symbol in pack_objects.__dict__.iteritems(): if type(symbol) is ClassType and issubclass(symbol, PublicRule): rules[name] = symbol #print name # Register the rule in the translation dictionary if hasattr(symbol,'register'): symbol.register(a) rules.sync()
def build_panels(force=False): if panels and not settings.NOCACHE: print 'Using cached panels file.' return for pack_name in settings.INSTALLED_MATH_PACKAGES: print 'Importing panels from ... ' + pack_name pack_module = loader.load_package(pack_name) # Load PACKAGE/panel.py if module_has_submodule(pack_module, 'panel'): pack_panels = loader.load_package_module(pack_name,'panel') panels.make_writable() for panel_name, symbol in pack_panels.__dict__.iteritems(): if is_panel(symbol): symbol.package = pack_name panels[panel_name] = symbol panels.sync()