[py-svn] r11054 - in py/dist/py: . bin misc

hpk at codespeak.net hpk at codespeak.net
Sun Apr 24 00:24:31 CEST 2005


Author: hpk
Date: Sun Apr 24 00:24:30 2005
New Revision: 11054

Added:
   py/dist/py/bin/_makepyrelease.py   (contents, props changed)
Modified:
   py/dist/py/__init__.py
   py/dist/py/initpkg.py
   py/dist/py/misc/_dist.py
Log:
first stab at an automatic "makepyrelease" script
that puts things on codespeak, downloads it on
a test account, unpacks and tests it, all from
on the interactive command line.  



Modified: py/dist/py/__init__.py
==============================================================================
--- py/dist/py/__init__.py	(original)
+++ py/dist/py/__init__.py	Sun Apr 24 00:24:30 2005
@@ -6,11 +6,10 @@
 from initpkg import initpkg
 
 initpkg(__name__, 
-    name = "py",
     description = "py.test and the py lib",
-    version = "0.8.0-prealpha", 
+    version = "0.8.0-pre-alpha", 
     url = "http://codespeak.net/py",
-    download_url = "http://codespeak.net/download/py-0.8.0-pre-alpha.tgz", 
+    download_url = "http://codespeak.net/download/py/py-0.8.0-pre-alpha.tar.gz", 
     license = "MIT license",
     platforms = ['unix', 'linux', 'cygwin'],
     author = "holger krekel & others",

Added: py/dist/py/bin/_makepyrelease.py
==============================================================================
--- (empty file)
+++ py/dist/py/bin/_makepyrelease.py	Sun Apr 24 00:24:30 2005
@@ -0,0 +1,179 @@
+#!/usr/bin/python 
+
+from _findpy import py
+import sys
+
+pydir = py.path.local(py.__file__).dirpath()
+rootdir = pydir.dirpath()
+
+def gen_manifest(): 
+    pywc = py.path.svnwc(pydir)
+    status = pywc.status(rec=True)
+    #assert not status.modified 
+    #assert not status.deleted  
+    #assert not status.added  
+    versioned = dict([(x.localpath,1) for x in status.allpath()])
+
+    l = []
+    for x in rootdir.visit(): 
+        if x.check(file=1): 
+            names = [y.basename for y in x.parts()]
+            if '.svn' in names: 
+                l.append(x) 
+            elif x in versioned: 
+                l.append(x) 
+    l.append(rootdir / "setup.py")
+    l = [x.relto(rootdir) for x in l]
+    l.append("")
+    s = "\n".join(l) 
+    return s 
+
+def trace(arg): 
+    lines = str(arg).split('\n') 
+    prefix = "[trace] "
+    prefix = "* " 
+    indent = len(prefix)  
+    ispace = " " * indent
+    lines = [ispace + line for line in lines]
+    if lines: 
+        lines[0] = prefix + lines[0][indent:]
+    for line in lines: 
+        print >>py.std.sys.stdout, line 
+
+def make_distfiles(tmpdir): 
+    """ return distdir with tar.gz and zipfile. """ 
+    manifest = tmpdir.join('MANIFEST')
+    trace("generating %s" %(manifest,))
+    content = gen_manifest() 
+    manifest.write(content) 
+    trace("wrote %d files into manifest file" %len(content.split('\n')))
+
+    distdir = tmpdir.ensure('dist', dir=1)
+    oldir = rootdir.chdir()
+    try: 
+        trace("invoking sdist, generating into %s" % (distdir,)) 
+        py._dist.setup(py, script_name="setup.py", 
+                           script_args=('-q', 'sdist', '--no-prune', 
+                                        '-m', str(manifest), 
+                                        '--formats=gztar,zip',  
+                                        '-d', str(distdir)))
+    finally: 
+        oldir.chdir()
+    return distdir 
+
+
+def pytest(unpacked): 
+    trace("py-testing %s" % unpacked)
+    old = unpacked.chdir()
+    try: 
+        import os
+        os.system("python py/bin/py.test py") 
+    finally: 
+        old.chdir()
+    
+def unpackremotetar(tmpdir, strurl): 
+    import tarfile, urllib
+    f = urllib.urlopen(strurl)
+    basename = strurl.split('/')[-1]
+    target = tmpdir.join(basename)
+    trace("downloading to %s" %(target,))
+    target.write(f.read())
+
+    trace("extracting to %s" %(target,))
+    old = tmpdir.chdir()
+    try: 
+        py.process.cmdexec("tar zxf %s" %(target,))
+    finally: 
+        old.chdir()
+    prefix = '.tar.gz'
+    assert basename.endswith(prefix) 
+    stripped = basename[:-len(prefix)]
+    unpacked = tmpdir.join(stripped) 
+    assert unpacked
+    return unpacked 
+       
+def checksvnworks(unpacked): 
+    pywc = py.path.svnwc(unpacked.join('py'))
+    trace("checking versioning works: %s" %(pywc,))
+    status = pywc.status(rec=True)
+    assert not status.modified 
+    assert not status.deleted 
+    assert not status.unknown 
+
+def pytest_remote(address, url): 
+    gw = py.execnet.SshGateway(address)
+    basename = url[url.rfind('/')+1:]
+    purebasename = basename[:-len('.tar.gz')]
+
+    def mytrace(x, l=[]): 
+        l.append(x)
+        if x.endswith('\n'): 
+            trace("".join(l))
+            l[:] = []
+            
+    channel = gw.remote_exec(stdout=mytrace, stderr=sys.stderr, source="""
+        url = %(url)r
+        basename = %(basename)r
+        purebasename = %(purebasename)r
+        import os, urllib
+        f = urllib.urlopen(url) 
+        print "reading from", url 
+        s = f.read()
+        f.close()
+        f = open(basename, 'w')
+        f.write(s) 
+        f.close()
+        if os.path.exists(purebasename):
+            import shutil 
+            shutil.rmtree(purebasename) 
+        os.system("tar zxf %%s" %% (basename,))
+        print "unpacked", purebasename 
+        os.chdir(purebasename)
+        print "testing at %(address)s ..."
+        #os.system("python py/bin/py.test py")
+        import commands
+        status, output = commands.getstatusoutput("python py/bin/py.test py")
+        #print output 
+        print "status:", status
+
+    """ % locals())
+    channel.waitclose(200.0)
+    
+if __name__ == '__main__': 
+    py.magic.invoke(assertion=True) 
+    version = py.std.sys.argv[1]
+    assert py.__package__.version == version, (
+            "py package has version %s\nlocation: %s" % 
+            (py.__package__.version, pydir))
+
+    tmpdir = py.path.local.get_temproot().join('makepyrelease-%s' % version) 
+    if tmpdir.check(): 
+        trace("removing %s" %(tmpdir,))
+        tmpdir.remove()
+    tmpdir.mkdir() 
+    trace("using tmpdir %s" %(tmpdir,))
+
+    distdir = make_distfiles(tmpdir) 
+    targz = distdir.join('py-%s.tar.gz' % version)
+    zip = distdir.join('py-%s.zip' % version)
+    files = targz, zip
+    for fn in files: 
+        assert fn.check(file=1) 
+
+    remotedir = 'codespeak.net://www/codespeak.net/htdocs/download/py/' 
+    source = " ".join([str(x) for x in files]) 
+    trace("rsyncing %(source)s to %(remotedir)s" % locals())
+    py.process.cmdexec("rsync -avz %(source)s %(remotedir)s" % locals())
+
+    ddir = tmpdir.ensure('download', dir=1)
+    URL = py.__package__.download_url # 'http://codespeak.net/download/py/' 
+    unpacked = unpackremotetar(ddir, URL)
+    assert unpacked == ddir.join("py-%s" % (version,))
+
+    checksvnworks(unpacked) 
+    #pytest(unpacked)
+
+    pytest_remote('test at codespeak.net', py.__package__.download_url)
+
+
+

Modified: py/dist/py/initpkg.py
==============================================================================
--- py/dist/py/initpkg.py	(original)
+++ py/dist/py/initpkg.py	Sun Apr 24 00:24:30 2005
@@ -35,6 +35,7 @@
     def __init__(self, name, exportdefs):
         pkgmodule = sys.modules[name]
         assert pkgmodule.__name__ == name
+        self.name = name
         self.exportdefs = exportdefs
         self.module = pkgmodule
         assert not hasattr(pkgmodule, '__package__'), \

Modified: py/dist/py/misc/_dist.py
==============================================================================
--- py/dist/py/misc/_dist.py	(original)
+++ py/dist/py/misc/_dist.py	Sun Apr 24 00:24:30 2005
@@ -85,28 +85,23 @@
         print "data file   ", x
     print 
 
-def setup(pkg): 
+def setup(pkg, **kw): 
     """ invoke distutils on a given package. 
     """
     params = Params(pkg)
     #dump(params)
     source = getattr(pkg, '__package__', pkg)
-
-    kw = {}
     namelist = list(core.setup_keywords)
     namelist.extend(['packages', 'scripts', 'data_files'])
     for name in namelist: 
-        try: 
-            kw[name] = getattr(source, name, 
-                               getattr(params, name))
-        except AttributeError: 
-            pass 
-            #print "couldn't find", name
+        for ns in (source, params): 
+            if hasattr(ns, name): 
+                kw[name] = getattr(ns, name) 
+                break 
 
     #script_args = sys.argv[1:]
     #if 'install' in script_args: 
     #    script_args = ['--quiet'] + script_args 
     #    #print "installing", py 
-    
     #py.std.pprint.pprint(kw)
     core.setup(**kw)



More information about the pytest-commit mailing list