[py-svn] r57344 - py/build

hpk at codespeak.net hpk at codespeak.net
Sun Aug 17 13:36:32 CEST 2008


Author: hpk
Date: Sun Aug 17 13:36:31 2008
New Revision: 57344

Modified:
   py/build/gensetup.py
Log:
this now generates a setup.py that installs the py lib including an extension


Modified: py/build/gensetup.py
==============================================================================
--- py/build/gensetup.py	(original)
+++ py/build/gensetup.py	Sun Aug 17 13:36:31 2008
@@ -12,43 +12,6 @@
 def reformat(text):
     return " ".join(text.split())
 
-class CollectFiles:
-    def __init__(self, wcbasedir, wcpaths):
-        self.packages = []
-        self.data_files = []
-        self._datadict = []
-        for p in wcpaths:
-            if p.check(file=1): 
-                if p.basename.startswith("py.") and p.dirpath().basename == 'bin':
-                    self.scripts.append(p.relto(wcbasedir))
-                    self.adddatafile(p)
-                elif p.ext == '.py': 
-                    self.addpythonfile(p) 
-                else: 
-                    self.adddatafile(p)
-            #else: 
-            #    if not p.listdir(): 
-            #        self.adddatafile(p.ensure('dummy'))
-
-    def adddatafile(self, p): 
-        target = self._pkgtarget.join(p.dirpath().relto(self._pkgdir))
-        l = self._datadict.setdefault(str(target), [])
-        l.append(p.relto(self._rootdir))
-
-    def addpythonfile(self, wc): 
-        p = wc.localpath
-        parts = p.parts() 
-        for above in p.parts(reverse=True)[1:]: 
-            if self._pkgdir.relto(above): 
-                dottedname = p.dirpath().relto(self._rootdir).replace(p.sep, '.')
-                if dottedname not in self.packages: 
-                    self.packages.append(dottedname) 
-                break 
-            if not above.join('__init__.py').check(): 
-                self.adddatafile(p)
-                #print "warning, added data file", p
-                break 
-
 class SetupWriter(object):
     EXCLUDES = ("MANIFEST.in",)
 
@@ -61,6 +24,9 @@
         self.lines = []
         self.wcinfo = self.wcbasedir.info()
         self.wcstatus = self.wcbasedir.status(rec=True)
+        self.allpaths = [x for x in self.wcstatus.allpath()
+                            if x not in self.wcstatus.unknown and
+                               x not in self.wcstatus.external]
     
     def append(self, string):
         lines = string.split("\n")
@@ -130,12 +96,15 @@
                     platforms=%(platforms)r, 
                     author=%(author)r,
                     author_email=%(author_email)r,
+                    ext_modules = [Extension("py.c-extension.greenlet.greenlet", 
+                        ["py/c-extension/greenlet/greenlet.c"]),],
         ''' % params)
         indent = " " * 8
         self.append_pprint(indent, scripts=self.getscripts())
         self.append_pprint(indent, long_description=params['long_description'])
         self.append_pprint(indent, packages=self.getpackages())
-        self.append_pprint(indent, data_files=self.getdatafiles())
+        #self.append_pprint(indent, data_files=self.getdatafiles())
+        self.append_pprint(indent, package_data=self.getpackagedata())
         #self.append_pprint(indent, package_dir={'py': 'py'})
         #self.append_pprint(indent, packages=self.getpackages())
         self.lines.append(indent[4:] + ")\n")
@@ -157,24 +126,34 @@
     def getscripts(self):
         bindir = self.wcbasedir.join('py', 'bin')
         scripts = []
-        for p in self.wcstatus.allpath():
+        for p in self.allpaths:
             if p.dirpath() == bindir and p.basename.startswith('py.'):
                 scripts.append(p.relto(self.wcbasedir))
         return scripts
 
     def getpackages(self):
         packages = []
-        for p in self.wcstatus.allpath():
+        for p in self.allpaths:
             if p.check(dir=1) and p.join('__init__.py').check():
                 modpath = p.relto(self.wcbasedir).replace(p.sep, '.')
                 packages.append(modpath)
         return packages
 
+    def getpackagedata(self):
+        datafiles = []
+        pkgbase = self.wcbasedir.join(self.pkg.__name__)
+        for p in self.allpaths:
+            if p.check(file=1) and not p.ext == ".py":
+                if p.dirpath() != self.wcbasedir:
+                    datafiles.append(p.relto(pkgbase))
+        return {'py': datafiles}
+
     def getdatafiles(self):
         datafiles = []
-        for p in self.wcstatus.allpath():
+        for p in self.allpaths:
             if p.check(file=1) and not p.ext == ".py":
-                datafiles.append(p.relto(self.wcbasedir))
+                if p.dirpath() != self.wcbasedir:
+                    datafiles.append(p.relto(self.wcbasedir))
         return datafiles
 
     def setup_win32(self):
@@ -193,15 +172,13 @@
     def write_manifest(self):
         lines = []
         status = self.wcstatus
-        for p in status.allpath():
+        for p in self.allpaths:
             if p.check(dir=1):
                 continue
             toadd = p.relto(wcbasedir)
-            if toadd in self.EXCLUDES:
-                lines.append("exclude %s" %(toadd))
-            elif toadd:    
-                lines.append("include %s" %(toadd))
-        targetfile = self.basedir.join("MANIFEST.in")
+            if toadd and toadd not in self.EXCLUDES:
+                lines.append("%s" %(toadd))
+        targetfile = self.basedir.join("MANIFEST")
         targetfile.write("\n".join(lines))
         print "wrote",  targetfile
 



More information about the pytest-commit mailing list