Commits

Ronny Pfannschmidt committed 0f478fd

add a copy to scripts task

Comments (0)

Files changed (3)

 
 
 DIST_FILE_KEYS = set((
-    'packages', 'summary',
+    'packages', 'summary', 'scripts'
 ))
 
 

pu/tasks/build.py

 from pu.tasks.util import TaskBase
-from pu.tasks.metadata import FindPackages
+from pu.tasks.metadata import FindPackages, ReadYamlMetadata
 
 import logging
 log = logging.getLogger('kij.build')
         from py_compile import compile
         for x in self.build_lib.visit('*.py'):
             compile(str(x))
+
+
+class CopyScripts(TaskBase):
+    keys = 'source', 'build_scripts'
+    scripts = None
+    requirements = ReadYamlMetadata,
+
+    def on_readyamlmetadata_success(self, item):
+        self.scripts = item.result.scripts or ()
+
+    def __call__(self):
+        self.build_scripts.ensure(dir=True)
+        for script in self.scripts:
+            script = self.source.join(script)
+            print script
+            #XXX: better error
+            assert script.check(file=1), 'script %s missing'%script
+            script.copy(target=self.build_scripts.join(script.basename))

tests/tasks/test_build.py

-from pu.tasks.build import CopyPackagesToBuild, CompileByteCode
+from pu.tasks.build import CopyPackagesToBuild, CompileByteCode, CopyScripts
 from pu.task_queue import Queue
 
 
                     source=source,
                     build_lib=tmpdir.join('build/lib'),
                     )
-    
     queue = Queue()
     queue.add(task)
     queue.run_all()
     magic = imp.get_magic()
     target_magic = target.read()[:4]
     assert target_magic == magic
+
+
+def test_copy_scripts(source, tmpdir):
+    source.join('kij.yml').write('name: test\nscripts: [foo, bin/bar]')
+    source.ensure('foo')
+    source.ensure('bin/bar')
+
+    build_scripts = tmpdir.join('build/scripts')
+    task = CopyScripts(
+            source=source,
+            build_scripts=build_scripts,
+            )
+
+    queue = Queue()
+    queue.add(task)
+    queue.run_all()
+    assert len(build_scripts.listdir()) == 2
+
+
+
+