def collect_objects(package, recursive=False): """ Run through `$PACKAGE.objects` and collect all objects which are subclasses of the superclasses provided in the `$PACKAGE.objects.initialize` function. """ pack_objects = load_package_module(package,'objects') super_clss, nullary_types = pack_objects.initialize() classes = {} inherited = {} for clsname, cls in pack_objects.__dict__.iteritems(): if type(cls) is TypeType and issubclass(cls,tuple(super_clss)): classes[cls.__name__] = cls if recursive: for cls in classes.itervalues(): for scls in all_subclasses(cls): inherited[scls.__name__] = scls if recursive: return classes, inherited else: return classes
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_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()
import os from inspect import getargspec from types import TypeType from django.conf import settings from django.template import Context from wise.worksheet.utils import load_haml_template from wise.worksheet.utils import trim_docstring from wise.utils.patterns import Aggregator from wise.utils.module_loading import module_has_submodule from wise.packages import loader Placeholder = loader.load_package_module('base','objects').Placeholder panels = Aggregator(file='cache/panels_cache') def _map_panel_types(obj): # If we have a Class read the argument signature of the # __init__ function and fill in all required arguments with # Placeholders. # Example: # Addition -> Addition(Placeholder(),Placeholder()) if isinstance(obj, TypeType): # Get the number of arguments the __init__ function for # the mathobject takes and substitute placeholder in for # each argument args, varargs, keywords, defaults = getargspec(obj.__init__) # decrement the len(args) since we ignore the self # argument
from django.utils import simplejson as json from django.views.generic import ListView, DetailView from django.views.generic.edit import (UpdateView, DeleteView, CreateView) from wise.translators.pytopure import parse_sexp from wise.worksheet import models from wise.worksheet.forms import WorksheetForm from wise.worksheet.utils import * from wise.packages import loader from operator import itemgetter wise.boot.start_python_pure() panel.build_panels() basecell = loader.load_package_module('base','cell') #--------------------------- # Home Page #--------------------------- class HomeView(ListView): model = models.Workspace template_name = "home.html" context_object_name = 'workspaces' def get_queryset(self): return models.Workspace.objects.filter(owner=self.request.user) #--------------------------- # Worksheet CRUD
from django import template from wise.worksheet.utils import load_haml_template from wise.packages.loader import load_package_module from wise.worksheet.utils import purify base_objects = load_package_module('base','objects') def initialize(): super_classes = [Integral, Diff, Taylor] nullary_types = {} return super_classes, nullary_types class Integral(base_objects.Term): """ This symbol is used to represent indefinite integration of unary functions. The first argument is the unary function the second argument is a variable of integration. """ show_parenthesis = True html = load_haml_template('integral.tpl') pure = 'integrate' def __init__(self, f, dx): self.integrand = f self.variable = dx self.terms = [f, dx] def _pure_(self): return self.po(self.integrand._pure_(),self.variable._pure_())
def package_to_graph(package): tops, nullary = load_package_module(package,'objects').initialize() return pycls2graph(*tops)