Commits

Ronny Pfannschmidt committed 8b7ce80

introduce using a config object instead of passing around data

Comments (0)

Files changed (9)

kij/commands/__init__.py

 
     options = [
         Option(
-            'source_directory',
+            'source',
             help='The source code directory',
             default=py.path.local(os.getcwd()),
             processor=py.path.local

kij/commands/build.py

 
 
 def build_command(config, queue):
-    build = config.source_directory.ensure('build', dir=True)
+    build = config.source.ensure('build', dir=True)
     build_lib = build.ensure('lib', dir=True)
-    build_scripts = build.ensure('scripts-%s.%s' % VERSION_INFO, dir=True)
-    task = Build(
-        source=config.source_directory,
-        build_lib=build_lib,
-        build_scripts=build_scripts,
-    )
+    #build_scripts = build.ensure('scripts-%s.%s' % VERSION_INFO, dir=True)
+    config.build_scripts = build.ensure('scripts-%s.%s' % VERSION_INFO, dir=True) #XXX: hackish
+    config.build_lib = build_lib
+
+    task = Build(config)
     queue.add(task)
 
 

kij/commands/install.py

 def link_command(config, queue):
     #XXX: handle fscked paths?
     #XXX: scripts
-    queue.add(LinkPTH(
-                   source=config.source,
-                   site=config.site,
-                   ))
+    queue.add(LinkPTH(config))

kij/tasks/__init__.py

     requirements = ()
     queue = None
 
-    def __init__(self, **kw):
+    def __init__(self, config=None, **kw):
+
         for key in self.keys:
-            setattr(self, key, kw[key])
+            if key in kw:
+                setattr(self, key, kw[key])
+            elif hasattr(config, key):
+                setattr(self, key, getattr(config, key))
+            else:
+                raise KeyError('%r required to set up %s' % (
+                    key,
+                    type(self).__name__)
+                    )
 
         self._kw = kw
+        self._config = config
 
     # hashing and equality
     def _key(self):
-        return tuple((key, getattr(self, key)) for key in self.keys)
+        return tuple((key, getattr(self, key, LookupError)) for key in self.keys)
 
     def __hash__(self):
         return hash(self._key())
         if self.requirements:
             print 'equeue next for', self
             req = self.requirements.popleft()
-            task = req(**self._kw)
+            task = req(self._config, **self._kw)
             print 'made', task
             self.queue.append(task)
 

kij/tasks/install.py

 from kij.storage.pth import PthFile
+from . import TaskBase
 
-
-class LinkTask(object):
+class LinkTask(TaskBase):
     pth_name = 'pu-links.pth'
-
-    def __init__(self, site, source):
-        self.site = site
-        self.source = source
+    keys = 'site', 'source'
 
     def __call__(self):
         self.run()

tests/cli/test_build.py

 from kij.commands import kij_script
 from kij.task_queue import Queue
 
-def test_build_command(script, fullsource):
+def test_build_command(script, fullsource, build_lib, build_scripts):
     script.main(['kij', 'build'])
-    build = fullsource.join('build')
-    assert build.check()
-    assert build.join('lib').check()
-    assert build.join('scripts-%s.%s' % VERSION_INFO).check()
+    assert build_lib.check()
+    assert build_scripts.check()
 

tests/conftest.py

 
 from kij.commands import kij_script
 
-def pytest_funcarg__site(request):
-    tmpdir = request.getfuncargvalue('tmpdir')
-    return tmpdir.ensure('site', dir=True)
 
+# python stuff
+dirs = {
+    'site': 'site',
+    'source': 'source',
+    'build_lib': 'build/lib',
+    'build_scripts': 'builds/scripts',
+}
 
-def pytest_funcarg__source(request):
-    tmpdir = request.getfuncargvalue('tmpdir')
-    return tmpdir.ensure('source', dir=True)
+for name in dirs:
+    globals()['pytest_funcarg__' + name] = lambda request, name=name: getattr(request.getfuncargvalue('config'), name)
+
 
 def pytest_funcarg__fullsource(request):
-    source = request.getfuncargvalue('source')
+    source = request.getfuncargvalue('config').source
     source.join('kij.yml').write(
             'name: test\n'
             'scripts: [foo, bin/bar]\n'
     return source
 
 def pytest_funcarg__config(request):
-    source = request.getfuncargvalue('source')
-    site = request.getfuncargvalue('site')
+    tmpdir = request.getfuncargvalue('tmpdir')
+
+    paths = {}
+    for name, subdir in dirs.items():
+        paths[name] = tmpdir.ensure(subdir, dir=1)
+
     config = Config()
-    config.grab_from_dict(dict(
-            site=site,
-            source=source,
-            source_directory=source,
-            ))
+    config.grab_from_dict(paths)
     return config
 
 def pytest_funcarg__script(request):

tests/tasks/test_build.py

 from kij.task_queue import Queue
 
 
-def test_copy_build(source, tmpdir):
+def test_copy_build(source,config):
     source.ensure('testpkg/__init__.py')
     source.join('kij.yml').write('name: test\npackages: [testpkg]\n')
-    task = CopyPackagesToBuild(
-                    source=source,
-                    build_lib=tmpdir.join('build/lib'),
-                    )
+    task = CopyPackagesToBuild(config)
     queue = Queue()
     queue.add(task)
     queue.run_all()
-    assert tmpdir.join('build/lib/testpkg/__init__.py').check()
+    assert config.build_lib.join('testpkg/__init__.py').check()
 
 
-def test_build_and_compile(source, tmpdir):
+def test_build_and_compile(source, tmpdir, config, build_lib):
 
     queue = Queue()
 
     source.ensure('testpkg/__init__.py')
     source.join('kij.yml').write('name: test\npackages: [testpkg]\n')
-    build_lib = tmpdir.join('build/lib')
 
-    compile = CompileByteCode(
-            source=source,
-            build_lib=build_lib,
-            )
+    compile = CompileByteCode(config)
     queue.add(compile)
 
     queue.run_all()
     assert target_magic == magic
 
 
-def test_copy_scripts(source, tmpdir):
+def test_copy_scripts(config, source, build_scripts):
     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,
-            )
-
+    task = CopyScripts(config)
     queue = Queue()
     queue.add(task)
     queue.run_all()

tests/tasks/test_develop.py

 
 
 def test_enable(site, source):
-    task = LinkPTH(site, source)
+    task = LinkPTH(site=site, source=source)
     assert not site.join(task.pth_name).check()
     task.run()
     assert site.join(task.pth_name).check()
 def test_disable(site, source):
     test_enable(site, source)
 
-    task = UnlinkPTH(site, source)
+    task = UnlinkPTH(site=site, source=source)
 
     pth = PthFile(site.join(task.pth_name))
     assert source in pth.entries