changeset 11:e6a62ba0c24d

now respect the order sources are installed in
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 08 Jul 2011 15:02:44 -0700
parents d1f090c5f291
children 542b46ac4e28
files carton.py tests/packageA/setup.py
diffstat 2 files changed, 34 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/carton.py	Fri Jul 08 13:23:47 2011 -0700
+++ b/carton.py	Fri Jul 08 15:02:44 2011 -0700
@@ -46,7 +46,7 @@
 
 # packed files
 VIRTUAL_ENV='''%(VIRTUAL_ENV)s'''.decode('base64').decode('zlib')
-PACKAGE_SOURCES='''%(PACKAGE_SOURCES)s'''.decode('base64').decode('zlib')
+PACKAGE_SOURCES=%(PACKAGE_SOURCES)s
 
 # unpack virtualenv
 tempdir = tempfile.mkdtemp()
@@ -68,15 +68,6 @@
 # create the virtualenv
 call([sys.executable, virtualenv, ENV])
 
-# unpack the sources
-srcdir = os.path.join(ENV, 'src')
-os.mkdir(srcdir)
-buffer = StringIO()
-buffer.write(PACKAGE_SOURCES)
-buffer.seek(0)
-tf = tarfile.open(mode='r', fileobj=buffer)
-tf.extractall(srcdir)
-
 # find the bin/scripts directory
 for i in ('bin', 'Scripts'):
     scripts_dir = os.path.abspath(os.path.join(ENV, i))
@@ -93,18 +84,28 @@
 else:
     raise Exception("python not found in " + scripts_dir)
 
-# activate the virtualenv
-#activate = os.path.join(scripts_dir, 'activate_this.py')
-#assert os.path.exists(activate), activate + " does not exist"
-#execfile(activate, dict(__file__=activate))
+# unpack the sources and setup for development
+srcdir = os.path.join(ENV, 'src')
+os.mkdir(srcdir)
+setup_pys = set()
+for source in PACKAGE_SOURCES:
+    source = source.decode('base64').decode('zlib')
+    buffer = StringIO()
+    buffer.write(source)
+    buffer.seek(0)
+    tf = tarfile.open(mode='r', fileobj=buffer)
+    tf.extractall(srcdir)
 
-# setup the sources for development
-for i in os.listdir(srcdir):
-    subdir = os.path.join(srcdir, i)
-    if os.path.exists(os.path.join(srcdir, i, 'setup.py')):
-        call([python, 'setup.py', 'develop'], cwd=subdir)
+    # setup sources for development if there are any new setup.py files
+    for i in os.listdir(srcdir):
+        if i in setup_pys:
+            continue
+        subdir = os.path.join(srcdir, i)
+        if os.path.exists(os.path.join(srcdir, i, 'setup.py')):
+            call([python, 'setup.py', 'develop'], cwd=subdir)
+            setup_pys.add(i)
 
-# cleanup tempdir
+# cleanup tempdir # TODO (optionally?)
 # shutil.rmtree(tempdir)
 
 # TODO:
@@ -134,18 +135,25 @@
     sources = args[1:]
 
     # tar up the sources
-    source_buffer = StringIO()
-    sources_tar = tarfile.open(mode="w:gz", fileobj=source_buffer)
+    source_array = []
     for source in sources:
+        buffer = None
 
         if isURL(source):
             # remote tarball
             raise NotImplementedError
         else:
             # local directory or tarball
-            sources_tar.add(source, arcname=os.path.basename(source))
+            # TODO: check for a tarball
+            source_buffer = StringIO()
+            source_tar = tarfile.open(mode="w:gz", fileobj=source_buffer)
+            source_tar.add(source, arcname=os.path.basename(source))
+            source_tar.close()
+            buffer = source_buffer.getvalue()
+
         # could use git, hg, etc repos. but probably shouldn't
-    sources_tar.close()
+        
+        source_array.append(buffer.encode('zlib').encode('base64'))
 
     # tar up virtualenv if not available
     if options.virtualenv:
@@ -170,7 +178,7 @@
         outfile = environment + '.py'
     variables = {'VIRTUAL_ENV': VIRTUAL_ENV.encode('zlib').encode('base64'),
                  'ENV': environment,
-                 'PACKAGE_SOURCES': source_buffer.getvalue().encode('zlib').encode('base64')}
+                 'PACKAGE_SOURCES': repr(source_array)}
     f = file(outfile, 'w')
     f.write(template % variables)
     f.close()
--- a/tests/packageA/setup.py	Fri Jul 08 13:23:47 2011 -0700
+++ b/tests/packageA/setup.py	Fri Jul 08 15:02:44 2011 -0700
@@ -9,7 +9,7 @@
 
 version = '0.0'
 
-deps = []
+deps = ['packageB']
 
 setup(name='packageA',
       version=version,