Code review comment for lp://staging/~gary/launchpad/buildout-py

Revision history for this message
Gary Poster (gary) wrote :

Here's an idea: use ``#! /usr/bin/env {path-to-bin/py}`` instead of ``#! {path-to-bin/py}``. Make that modification after Mailman's ``make`` and before ``make install`` (because Mailman's ``make install`` tries to run ``bin/update``). It seemed to work as a technique when I experimented yesterday on the ec2 instance. I don't see a downside yet (other than the small amount of code to do the hack). It should work. I'll push and give it a try on ec2.

The incremental diff below also switches bin/py back to a shell script. This seemed to make the Mailman pofile creation happier on hardy than the zc.buildout Python version that I had switched to for this branch. It also meant that I could go back to using -t normally in the Makefile. (I had switched from the shell version primarily because I didn't know I would have to get a shell version working; now that we have the site.py hack, it works fine.)

=== modified file 'Makefile'
--- Makefile 2009-10-13 18:50:35 +0000
+++ Makefile 2009-10-17 17:46:38 +0000
@@ -82,7 +82,7 @@
 check: clean build
  # Run all tests. test_on_merge.py takes care of setting up the
  # database.
- ${PYTHON} -t ${PY} ./test_on_merge.py $(VERBOSITY)
+ ${PY} -t ./test_on_merge.py $(VERBOSITY)

 jscheck: build
  # Run all JavaScript integration tests. The test runner takes care of
@@ -103,7 +103,7 @@
 check_mailman: build
  # Run all tests, including the Mailman integration
  # tests. test_on_merge.py takes care of setting up the database.
- ${PYTHON} -t ${PY} ./test_on_merge.py $(VERBOSITY) --layer=MailmanLayer
+ ${PY} -t ./test_on_merge.py $(VERBOSITY) --layer=MailmanLayer

 lint: ${PY}
  @bash ./bin/lint.sh
@@ -112,7 +112,7 @@
  @bash ./bin/lint.sh -v

 xxxreport: $(PY)
- ${PYTHON} -t ${PY} ./utilities/xxxreport.py -f csv -o xxx-report.csv ./
+ ${PY} -t ./utilities/xxxreport.py -f csv -o xxx-report.csv ./

 check-configs: $(PY)
  ${PY} utilities/check-configs.py
@@ -149,7 +149,7 @@
 compile: $(PY)
  ${SHHH} $(MAKE) -C sourcecode build PYTHON=${PYTHON} \
      PYTHON_VERSION=${PYTHON_VERSION} LPCONFIG=${LPCONFIG}
- ${SHHH} LPCONFIG=${LPCONFIG} ${PYTHON} -t ${PY} buildmailman.py
+ ${SHHH} LPCONFIG=${LPCONFIG} ${PY} -t buildmailman.py
  ${SHHH} $(PY) sourcecode/lazr-js/tools/build.py \
   -n launchpad -s lib/canonical/launchpad/javascript \
   -b lib/canonical/launchpad/icing/build $(EXTRA_JS_FILES)

=== modified file 'buildmailman.py'
--- buildmailman.py 2009-10-15 04:19:54 +0000
+++ buildmailman.py 2009-10-18 00:59:56 +0000
@@ -84,25 +84,52 @@

     # Build and install the Mailman software. Note that we don't care about
     # --with-cgi-gid because we're not going to use that Mailman subsystem.
+ executable = os.path.abspath('bin/py')
     configure_args = (
         './configure',
         '--prefix', mailman_path,
         '--with-var-prefix=' + var_dir,
- '--with-python=' + os.path.abspath('bin/py'),
+ '--with-python=' + executable,
         '--with-username=' + user,
         '--with-groupname=' + group,
         '--with-mail-gid=' + group,
         '--with-mailhost=' + build_host_name,
         '--with-urlhost=' + build_host_name,
         )
+ # Configure.
     retcode = subprocess.call(configure_args, cwd=mailman_source)
     if retcode:
         print >> sys.stderr, 'Could not configure Mailman:'
         sys.exit(retcode)
+ # Make.
     retcode = subprocess.call(('make',), cwd=mailman_source)
     if retcode:
         print >> sys.stderr, 'Could not make Mailman.'
         sys.exit(retcode)
+ # We have a brief interlude before we install. Hardy will not
+ # accept a script as the executable for the shebang line--it will
+ # treat the file as a shell script instead. The ``bin/by``
+ # executable that we specified in '--with-python' above is a script
+ # so this behavior causes problems for us. Our work around is to
+ # prefix the ``bin/py`` script with ``/usr/bin/env``, which makes
+ # Hardy happy. We need to do this before we install because the
+ # installation will call Mailman's ``bin/update``, which is a script
+ # that needs this fix.
+ build_dir = os.path.join(mailman_source, 'build')
+ original = '#! %s\n' % (executable,)
+ modified = '#! /usr/bin/env %s\n' % (executable,)
+ for (dirpath, dirnames, filenames) in os.walk(build_dir):
+ for filename in filenames:
+ filename = os.path.join(dirpath, filename)
+ f = open(filename, 'r')
+ if f.readline() == original:
+ rest = f.read()
+ f.close()
+ f = open(filename, 'w')
+ f.write(modified)
+ f.write(rest)
+ f.close()
+ # Now we actually install.
     retcode = subprocess.call(('make', 'install'), cwd=mailman_source)
     if retcode:
         print >> sys.stderr, 'Could not install Mailman.'

=== renamed file 'buildout-templates/bin/pythonpath-py.in' => 'buildout-templates/bin/py.in'
=== modified file 'buildout.cfg'
--- buildout.cfg 2009-10-13 18:50:35 +0000
+++ buildout.cfg 2009-10-17 17:44:14 +0000
@@ -46,7 +46,6 @@

 [scripts]
 recipe = zc.recipe.egg
-interpreter = py
 eggs = lp
     windmill
     funkload

« Back to merge proposal