Commits

Ronny Pfannschmidt committed 88bad85

adapt the new task api

Comments (0)

Files changed (3)

pu/tasks/build.py

+from pu.tasks.util import TaskBase
 
-
-class CopyModulesToBuild(object):
-    def __init__(self, source, build_lib):
-        self.source = source
-        self.build_lib = build_lib
-
+class CopyModulesToBuild(TaskBase):
+    keys = 'source', 'build_lib'
 
     def __call__(self):
         self.build_lib.ensure(dir=1)
             target.write(module.read())
 
 
-
-
-class CompileByteCode(object):
-    def __init__(self, build_lib):
-        self.build_lib = build_lib
+class CompileByteCode(TaskBase):
+    """
+    compiles all python files below the target directory
+    uses the optimizer settings of the current interpreter
+    """
+    keys = 'build_lib',
 
     def __call__(self):
+        from py_compile import compile
         for x in self.build_lib.visit('*.py'):
-            x.new(ext='.pyc').ensure() #XXX: actually compile
+            compile(str(x))
+
+
+

pu/tasks/metadata.py

-
+from .util import TaskBase
 
 def find_packages(base, start):
     result = []
     return result
 
 
+class FindPackages(TaskBase):
+    keys = 'source', 'match',
+    result = None
 
-
-
-
-
-class FindPackages(object):
-    def __init__(self, source, match):
-        self.source = source
-        self.match = match
-        self.result = None
-
-    def run(self):
+    def __call__(self):
         deep = self.match[-2:] == '.*'
         elements = self.match.split('.')
         if deep:
             elements.pop()
 
-        self.result = find_packages(self.source, self.source.join(*elements))
+        self.result = find_packages(self.source,
+                                    self.source.join(*elements))
         if not self.result:
             raise IOError('package %s not found below %s' % (
                            self.match, self.source))
 
+
+
+class ReadYamlMetadata(TaskBase):
+    keys = 'source',
+    result = None
+
+    def __call__(self):
+        from pu.files.dist import DistFile
+        self.result = DistFile(self.source.join('kij.yaml'))
+
+
+

tests/tasks/test_metadata.py

 import py
 from pu.tasks.metadata import FindPackages, find_packages
+from pu.tasks.metadata import ReadYamlMetadata
 
 def test_find_packages(source):
     pkg = source.join('pkg')
     pkg = source.join('pkg')
     source.ensure('pkg/__init__.py')
 
-    task = FindPackages(source, 'pkg')
-    task.run()
+    task = FindPackages(source=source, match='pkg')
+    task()
     assert task.result == ['pkg']
 
     task.match = 'missing'
-    py.test.raises(IOError, task.run)
+    py.test.raises(IOError, task)
 
     task.match = 'pkg.*'
-    task.run()
+    task()
     assert task.result == ['pkg']
 
 
 
+
+def test_read_yaml_task(source):
+    source.join('kij.yaml').write('name: test\npackages: [foo, bar]')
+    task = ReadYamlMetadata(source=source)
+    task()
+    assert task.result.name == 'test'
+    assert task.result.packages == ['foo', 'bar']