[pypy-svn] r40765 - in pypy/dist/pypy/tool/build/testproject: . bin builds dist dist/test

guido at codespeak.net guido at codespeak.net
Mon Mar 19 13:23:49 CET 2007


Author: guido
Date: Mon Mar 19 13:23:44 2007
New Revision: 40765

Added:
   pypy/dist/pypy/tool/build/testproject/
   pypy/dist/pypy/tool/build/testproject/__init__.py
   pypy/dist/pypy/tool/build/testproject/bin/
   pypy/dist/pypy/tool/build/testproject/bin/autopath.py
   pypy/dist/pypy/tool/build/testproject/bin/buildserver.py   (contents, props changed)
   pypy/dist/pypy/tool/build/testproject/bin/metaserver.py   (contents, props changed)
   pypy/dist/pypy/tool/build/testproject/bin/startcompile.py   (contents, props changed)
   pypy/dist/pypy/tool/build/testproject/builds/
   pypy/dist/pypy/tool/build/testproject/compileoption.py
   pypy/dist/pypy/tool/build/testproject/config.py
   pypy/dist/pypy/tool/build/testproject/dist/
   pypy/dist/pypy/tool/build/testproject/dist/test/
   pypy/dist/pypy/tool/build/testproject/dist/test/test.c
   pypy/dist/pypy/tool/build/testproject/systemoption.py
   pypy/dist/pypy/tool/build/testproject/tooloption.py
Log:
Small test project to test the build tool with.


Added: pypy/dist/pypy/tool/build/testproject/__init__.py
==============================================================================

Added: pypy/dist/pypy/tool/build/testproject/bin/autopath.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/testproject/bin/autopath.py	Mon Mar 19 13:23:44 2007
@@ -0,0 +1,114 @@
+"""
+self cloning, automatic path configuration 
+
+copy this into any subdirectory of pypy from which scripts need 
+to be run, typically all of the test subdirs. 
+The idea is that any such script simply issues
+
+    import autopath
+
+and this will make sure that the parent directory containing "pypy"
+is in sys.path. 
+
+If you modify the master "autopath.py" version (in pypy/tool/autopath.py) 
+you can directly run it which will copy itself on all autopath.py files
+it finds under the pypy root directory. 
+
+This module always provides these attributes:
+
+    pypydir    pypy root directory path 
+    this_dir   directory where this autopath.py resides 
+
+"""
+
+
+def __dirinfo(part):
+    """ return (partdir, this_dir) and insert parent of partdir
+    into sys.path.  If the parent directories don't have the part
+    an EnvironmentError is raised."""
+
+    import sys, os
+    try:
+        head = this_dir = os.path.realpath(os.path.dirname(__file__))
+    except NameError:
+        head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
+
+    while head:
+        partdir = head
+        head, tail = os.path.split(head)
+        if tail == part:
+            break
+    else:
+        raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
+    
+    pypy_root = os.path.join(head, '')
+    try:
+        sys.path.remove(head)
+    except ValueError:
+        pass
+    sys.path.insert(0, head)
+
+    munged = {}
+    for name, mod in sys.modules.items():
+        if '.' in name:
+            continue
+        fn = getattr(mod, '__file__', None)
+        if not isinstance(fn, str):
+            continue
+        newname = os.path.splitext(os.path.basename(fn))[0]
+        if not newname.startswith(part + '.'):
+            continue
+        path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
+        if path.startswith(pypy_root) and newname != part:
+            modpaths = os.path.normpath(path[len(pypy_root):]).split(os.sep)
+            if newname != '__init__':
+                modpaths.append(newname)
+            modpath = '.'.join(modpaths)
+            if modpath not in sys.modules:
+                munged[modpath] = mod
+
+    for name, mod in munged.iteritems():
+        if name not in sys.modules:
+            sys.modules[name] = mod
+        if '.' in name:
+            prename = name[:name.rfind('.')]
+            postname = name[len(prename)+1:]
+            if prename not in sys.modules:
+                __import__(prename)
+                if not hasattr(sys.modules[prename], postname):
+                    setattr(sys.modules[prename], postname, mod)
+
+    return partdir, this_dir
+
+def __clone():
+    """ clone master version of autopath.py into all subdirs """
+    from os.path import join, walk
+    if not this_dir.endswith(join('pypy','tool')):
+        raise EnvironmentError("can only clone master version "
+                               "'%s'" % join(pypydir, 'tool',_myname))
+
+
+    def sync_walker(arg, dirname, fnames):
+        if _myname in fnames:
+            fn = join(dirname, _myname)
+            f = open(fn, 'rwb+')
+            try:
+                if f.read() == arg:
+                    print "checkok", fn
+                else:
+                    print "syncing", fn
+                    f = open(fn, 'w')
+                    f.write(arg)
+            finally:
+                f.close()
+    s = open(join(pypydir, 'tool', _myname), 'rb').read()
+    walk(pypydir, sync_walker, s)
+
+_myname = 'autopath.py'
+
+# set guaranteed attributes
+
+pypydir, this_dir = __dirinfo('pypy')
+
+if __name__ == '__main__':
+    __clone()

Added: pypy/dist/pypy/tool/build/testproject/bin/buildserver.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/testproject/bin/buildserver.py	Mon Mar 19 13:23:44 2007
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+import autopath
+import py
+from py.execnet import PopenGateway
+from pypy.tool.build import outputbuffer
+
+def compile(wc, compileinfo, buildpath):
+    code = """\
+        import os
+        
+        import py
+
+        # interpolating the path
+        wc = py.path.local(%r)
+        try:
+            os.chdir(str(wc))
+            try:
+                output = py.process.cmdexec("gcc -o test test.c")
+            except Exception, e:
+                output = str(e)
+            upath = wc.join('test')
+            channel.send(output)
+            channel.send(str(upath))
+        finally:
+            channel.close()
+    """
+    gw = PopenGateway()
+    interpolated = py.code.Source(outputbuffer,
+                                  code % (str(wc), compileinfo,
+                                  str(buildpath)))
+    channel = gw.remote_exec(interpolated)
+    try:
+        upath = channel.receive()
+        output = channel.receive()
+    except channel.RemoteError, e:
+        print 'Remote exception:'
+        print str(e)
+        return (None, str(e))
+    channel.close()
+
+    return upath, output
+
+if __name__ == '__main__':
+    # main bit
+    from pypy.tool.build.bin import path
+    from pypy.tool.build.testproject import config
+    from pypy.tool.build.buildserver import main
+
+    main(config, path, compile)
+

Added: pypy/dist/pypy/tool/build/testproject/bin/metaserver.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/testproject/bin/metaserver.py	Mon Mar 19 13:23:44 2007
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+
+from pypy.tool.build.testproject import config
+from pypy.tool.build.metaserver import main
+
+main(config)
+

Added: pypy/dist/pypy/tool/build/testproject/bin/startcompile.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/testproject/bin/startcompile.py	Mon Mar 19 13:23:44 2007
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+
+import autopath
+from pypy.tool.build.testproject import config
+from pypy.tool.build.compile import main, getrequest
+from py.execnet import SshGateway, PopenGateway
+
+request, foreground = getrequest(config)
+main(config, request, foreground)

Added: pypy/dist/pypy/tool/build/testproject/compileoption.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/testproject/compileoption.py	Mon Mar 19 13:23:44 2007
@@ -0,0 +1,9 @@
+import py
+from pypy.config.config import OptionDescription, BoolOption, IntOption
+from pypy.config.config import ChoiceOption, Config
+
+import sys
+compile_optiondescription = OptionDescription('compile', '', [
+    BoolOption('moo', 'moo while compiling', default=False),
+])
+

Added: pypy/dist/pypy/tool/build/testproject/config.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/testproject/config.py	Mon Mar 19 13:23:44 2007
@@ -0,0 +1,65 @@
+import py
+
+packageparent = py.magic.autopath().dirpath().dirpath().dirpath().dirpath().dirpath()
+
+# general settings, used by both server and client
+server = 'localhost'
+port = 23432
+testport = 43234
+path = [str(packageparent)]
+
+# options for webserver
+webserver = ''
+vhostroot = ''
+webport = 8080
+
+# configuration of options for client and startcompile
+from pypy.config.config import Config
+
+# system config, on the client everything is set by scanning the system, when
+# calling startcompile defaults are taken from the system, overrides are
+# possible using cmdline args
+from systemoption import system_optiondescription
+system_config = Config(system_optiondescription)
+
+# compile option config, used by client to parse info, by startcompile for 
+# cmdline args, defaults are taken from the optiondescription
+from compileoption import compile_optiondescription
+compile_config = Config(compile_optiondescription)
+
+from tooloption import tool_optiondescription
+tool_config = Config(tool_optiondescription)
+
+# settings for the server
+projectname = 'testproject'
+buildpath = packageparent.ensure('/pypy/tool/build/testproject/builds',
+                                 dir=True)
+mailhost = 'localhost'
+mailport = 25
+mailfrom = 'guido at codespeak.net'
+
+# this var is only used below
+svnroot = 'http://codespeak.net/svn/pypy/dist/pypy/tool/build/testproject'
+
+# when considering a compile job, the checkers below will be called (with
+# request as only arg), if one of them returns False the compilation will
+# not be accepted
+def check_svnroot(req):
+    if not req.svnurl.startswith(svnroot):
+        return False
+    return True
+
+client_checkers = [check_svnroot]
+
+# function to turn SVN paths into full URLs
+def svnpath_to_url(p):
+    root = svnroot
+    if root.endswith('/'):
+        root = root[:-1]
+    return '%s/%s' % (root, p)
+
+# create an URL from a path, the URL is used in emails
+def path_to_url(p):
+    return 'http://localhost/testproject/%s/data.zip' % (
+                p.relto(py.magic.autopath().dirpath()),)
+

Added: pypy/dist/pypy/tool/build/testproject/dist/test/test.c
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/testproject/dist/test/test.c	Mon Mar 19 13:23:44 2007
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char *argv) {
+    printf("Hello, World!\n");
+    return 0;
+}

Added: pypy/dist/pypy/tool/build/testproject/systemoption.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/testproject/systemoption.py	Mon Mar 19 13:23:44 2007
@@ -0,0 +1,13 @@
+import py
+from pypy.config.config import OptionDescription, BoolOption, IntOption
+from pypy.config.config import ChoiceOption, Config
+
+import sys
+system_optiondescription = OptionDescription('system', '', [
+    IntOption('maxint', 'maximum int value', default=sys.maxint),
+    ChoiceOption('byteorder', 'endianness, byte order (little/big)',
+                 ['little', 'big'], default=sys.byteorder),
+    ChoiceOption('os', 'operating system', ['win32', 'linux2'],
+                 default=sys.platform),
+])
+

Added: pypy/dist/pypy/tool/build/testproject/tooloption.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/testproject/tooloption.py	Mon Mar 19 13:23:44 2007
@@ -0,0 +1,13 @@
+import py
+from pypy.config.config import StrOption, IntOption
+from pypy.config.config import OptionDescription, Config
+
+import sys
+tool_optiondescription = OptionDescription('tool', '', [
+    IntOption('svnrev', 'Subversion revision', default='HEAD'),
+    StrOption('svnpath', 'Subversion path (relative to the project root)',
+              default='dist'),
+    StrOption('revrange', 'Revision range (max difference in revision between '
+                          'requested build and result)', default=0),
+])
+



More information about the Pypy-commit mailing list