Example #1
0
    def test_function_dump(self):
        nlazy = evalcache.Lazy(
            cache=evalcache.DirCache(test_environment.dircache_path),
            function_dump=False,
            onplace=True,
        )
        flazy = evalcache.Lazy(
            cache=evalcache.DirCache(test_environment.dircache_path),
            function_dump=True,
            onplace=True,
        )

        lmb_1 = lambda: 1
        lmb_2 = lambda: 2

        nlazy_11 = nlazy(lmb_1, hint="a")()
        nlazy_12 = nlazy(lmb_2, hint="b")()
        nlazy_21 = nlazy(lmb_1)()
        nlazy_22 = nlazy(lmb_2)()

        flazy_11 = flazy(lmb_1, hint="a")()
        flazy_12 = flazy(lmb_2, hint="b")()
        flazy_21 = flazy(lmb_1)()
        flazy_22 = flazy(lmb_2)()

        self.assertNotEqual(nlazy_11, nlazy_12)
        self.assertEqual(nlazy_21, nlazy_22)
        self.assertNotEqual(flazy_11, flazy_12)
        self.assertNotEqual(flazy_21, flazy_22)
Example #2
0
    def test_cached_operations(self):
        nlazy = evalcache.Lazy(cache=evalcache.DirCache(
            test_environment.dircache_path), )

        i = nlazy(3)
        print(float(i))

        self.assertEqual(i, 3)
Example #3
0
    def test_getattr(self):
        lazy = evalcache.Lazy(cache={})

        class Cls:
            def __init__(self):
                self.i = 3

            def __repr__(self):
                return "Cls"

        Cls = lazy(Cls)
        a = Cls()

        self.assertEqual(a.i.unlazy(), 3)
Example #4
0
    def test_function_dump(self):
        nlazy = evalcache.Lazy(
            cache=evalcache.DirCache(test_environment.dircache_path),
            function_dump=False,
            onplace=True,
        )

        self.assertNotEqual(
            nlazy((1, 10)).__lazyhash__,
            nlazy("<class 'tuple'><splitter>01<splitter>110").__lazyhash__)

        self.assertNotEqual(
            nlazy(("<splitter>01<splitter>210,", )).__lazyhash__,
            nlazy((1, 10)).__lazyhash__)
Example #5
0
    def test_aaa(self):
        nlazy = evalcache.Lazy(
            cache=evalcache.DirCache(test_environment.dircache_path),
            encache=False,
        )

        class Cls:
            def get_three(self):
                return 3

            def __repr__(self):
                return "Cls"

            def __getitem__(self, i):
                return i

            def __len__(self):
                return 2

        @nlazy
        def foo():
            return Cls()

        a, b = foo()
Example #6
0
#!/usr/bin/python3

import sys

sys.path.insert(0, "..")

import evalcache

lazy = evalcache.Lazy(".evalcache")


@lazy
def gen():
    return [1, 2, 3]


arr = gen()

print(arr)

print(len(arr))
iter(arr)

for a in arr:
    print(a.unlazy())
Example #7
0
#!/usr/bin/python3

import sys

sys.path.insert(0, "..")

import evalcache

lazy = evalcache.Lazy(cache=evalcache.DirCache(".evalcache"))


class A:
    def __repr__(self):
        return "A"


class B:
    pass


lazy(A())
lazy(B())
Example #8
0
import zencad.configure

import pyservoce
import hashlib
import operator
import os

from zencad.util import points, vector3, point3

cachepath = os.path.expanduser("~/.zencadcache")
algo = hashlib.sha512

lazy = evalcache.Lazy(cache=evalcache.dircache_v2.DirCache_v2(cachepath),
                      algo=algo,
                      onbool=True,
                      onstr=True,
                      pedantic=True
                      #    status_notify=True
                      )


def install_evalcahe_notication(comm):
    if zencad.configure.CONFIGURE_WITHOUT_EVALCACHE_NOTIFIES:
        return

    lazy.status_notify_enable(True)

    def stcb(root):
        arr = evalcache.lazy.tree_objects(root)
        comm.send({
            "cmd": "evalcache",
Example #9
0
#!/usr/bin/python3

import sys
sys.path.insert(0, "..")

import evalcache

lazy = evalcache.Lazy(cache=evalcache.DirCache(".evalcache"), diag=True)


@lazy
def foo():
    return 42


@lazy
def bar():
    return foo()


print(bar().unlazy())
Example #10
0
 def test_cached_operations(self):
     nlazy = evalcache.Lazy(cache=evalcache.DirCache_v2(
         test_environment.dircache_path2), )
Example #11
0
import evalcache
import evalcache.dircache
import evalcache.dircache_v2
from evalcache.lazyfile import LazyFile

import pyservoce
import hashlib
import os

from zencad.util import points, vector3, point3

cachepath = os.path.expanduser("~/.zencadcache")
algo = hashlib.sha512

lazy = evalcache.Lazy(cache=evalcache.dircache_v2.DirCache_v2(cachepath),
                      algo=algo,
                      onbool=True)


class LazyObjectShape(evalcache.LazyObject):
    def __init__(self, *args, **kwargs):
        evalcache.LazyObject.__init__(self, *args, **kwargs)

    def translate(self, *args, **kwargs):
        return self.lazyinvoke(
            pyservoce.Shape.translate,
            (self, *args),
            kwargs,
            encache=False,
            decache=False,
            cls=LazyObjectShape,
Example #12
0
#!/usr/bin/python3

import sys

sys.path.insert(0, "..")

import evalcache
import shelve

lazy = evalcache.Lazy(cache=shelve.open(".shelve"), diag=True)


@lazy
def foo():
    return 1


a = foo().unlazy()

print(a)
Example #13
0
#!/usr/bin/python3

import sys

sys.path.insert(0, "..")

import evalcache
import hashlib
import shelve

lazy = evalcache.Lazy(cache=shelve.open(".cache"), algo=hashlib.sha256)


@lazy
def summ(a, b, c):
    return a + b + c


@lazy
def sqr(a):
    return a * a


a = 1
b = sqr(2)
c = lazy(3)

lazyresult = summ(a, b, c)
result = lazyresult.unlazy()

print(lazyresult
Example #14
0
import hashlib

import evalcache
import evalcache.dircache
import evalcache.dircache_v2
from evalcache.lazyfile import LazyFile

cachepath = os.path.expanduser("~/.zencadcache")
algo = hashlib.sha512

lazy = evalcache.Lazy(
    cache=evalcache.dircache_v2.DirCache_v2(cachepath),
    algo=algo,
    onbool=True,
    onstr=True,
    pedantic=True,

    # diag=True,
    # diag_values=True,
    # print_invokes=True,
    # fastdo=True
)

diag = None
ensave = None
desave = None
onplace = None
status_notify = None


def disable_lazy():
    global ensave, desave, onplace, diag, status_notify
Example #15
0
#!/usr/bin/python3

import sys

sys.path.insert(0, "..")

import evalcache
import math

#cache = evalcache.DirCache(".evalcache")
cache = evalcache.dircache_v2.DirCache_v2(".evalcache")
#cache.clean()

lazy = evalcache.Lazy(cache=cache, status_notify=True)


def stcb(root):
    arr = evalcache.lazy.tree_objects(root)
    print("total:{}".format(len(arr)))


def sncb(root, obj):
    arrs = evalcache.lazy.tree_needeval(root)
    print("toload:{} toeval:{}".format(len(arrs.toload), len(arrs.toeval)))


def ftcb(root):
    pass
    #print("ftcb")

Example #16
0
#!/usr/bin/python3
# coding:utf-8

import evalcache
import evalcache.dircache
import shutil

import os

dircache_path = ".evalcache"
dircache_path2 = ".evalcache2"

lazy = evalcache.Lazy(cache=evalcache.dircache.DirCache(dircache_path))
memoize = evalcache.Memoize(onplace=False)
onplace_memoize = evalcache.Memoize(onplace=True)


def clean():
    for path in os.listdir(dircache_path):
        os.remove("{}/{}".format(dircache_path, path))
    lazy.cache.files = set()


def full_clean():
    #shutil.rmtree(dircache_path, ignore_errors=False, onerror=None)
    shutil.rmtree(dircache_path2, ignore_errors=False, onerror=None)


def clean_memoize():
    memoize.cache = {}