[Zope-CVS]
SVN: zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/
- add missing imports to zpkgsetup.build_scripts
Fred L. Drake, Jr.
fred at zope.com
Thu Jul 15 12:38:49 EDT 2004
Log message for revision 26557:
- add missing imports to zpkgsetup.build_scripts
- add explanation of how the implementation was changed from the base
class, since most of it is a copy of a long method
- make the implementation more readibly testable regardless of host
platform
- add a test suite
Changed:
U zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/build_scripts.py
A zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/tests/test_build_scripts.py
-=-
Modified: zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/build_scripts.py
===================================================================
--- zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/build_scripts.py 2004-07-15 15:50:51 UTC (rev 26556)
+++ zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/build_scripts.py 2004-07-15 16:38:49 UTC (rev 26557)
@@ -18,11 +18,35 @@
$Id$
"""
-from distutils.command.build_scripts import build_scripts as _build_scripts
+import os
+import sys
+from stat import ST_MODE
-class build_scripts(_build_scripts):
+from distutils import log
+from distutils import sysconfig
+from distutils.command import build_scripts as _build_scripts
+from distutils.dep_util import newer
+from distutils.util import convert_path
+
+class build_scripts(_build_scripts.build_scripts):
+
+ # The copy_scripts() method is copied in it's entirety from the
+ # stock build_scripts command since it isn't broken down into
+ # useful bits to better support subclassing. The only changes are
+ # the addition of the "if" statement that causes the ".py"
+ # extension to be added on Windows if it is not already present,
+ # the on_windows attribute, and a fix to a reference to the
+ # first_line_re defined in the module of the base class.
+ #
+ # The on_windows attribute can be re-initialized on command
+ # instances to support testing of this class without regard to the
+ # host platform. It is the only determinant of the behavior to
+ # use when scripts are built.
+
+ on_windows = sys.platform[:3].lower() == "win"
+
def copy_scripts (self):
"""Copy each script listed in 'self.scripts'; if it's marked as a
Python script in the Unix way (first line matches 'first_line_re',
@@ -35,9 +59,8 @@
adjust = 0
script = convert_path(script)
outfile = os.path.join(self.build_dir, os.path.basename(script))
- # This if statement is all we add to the underlying base class.
- if (sys.platform[:3].lower() == "win"
- and not outfile.endswith(".py")):
+ # This is what was added.
+ if (self.on_windows and not outfile.lower().endswith(".py")):
outfile += ".py"
outfiles.append(outfile)
@@ -60,7 +83,7 @@
self.warn("%s is an empty file (skipping)" % script)
continue
- match = first_line_re.match(first_line)
+ match = _build_scripts.first_line_re.match(first_line)
if match:
adjust = 1
post_interp = match.group(1) or ''
Added: zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/tests/test_build_scripts.py
===================================================================
--- zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/tests/test_build_scripts.py 2004-07-15 15:50:51 UTC (rev 26556)
+++ zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/tests/test_build_scripts.py 2004-07-15 16:38:49 UTC (rev 26557)
@@ -0,0 +1,74 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Tests of zpkgsetup.build_scripts.
+
+$Id$
+"""
+import os.path
+import shutil
+import unittest
+
+from distutils.dist import Distribution
+
+from zpkgsetup.build_scripts import build_scripts
+from zpkgsetup.tests.tempfileapi import mkdtemp
+
+
+class BuildScriptsTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.srcdir = mkdtemp(prefix="src-")
+ self.destdir = mkdtemp(prefix="dest-")
+ self.script_sources = []
+ self.add_script("script1")
+ self.add_script("script2.py")
+ self.add_script("script3.PY")
+
+ def add_script(self, name):
+ path = os.path.join(self.srcdir, name)
+ self.script_sources.append(path)
+ f = open(path, "w")
+ f.write("#!/usr/bin/env python2.3\n")
+ f.write("pass")
+ f.close()
+
+ def tearDown(self):
+ shutil.rmtree(self.srcdir)
+ shutil.rmtree(self.destdir)
+
+ def test_not_on_windows(self):
+ self.check_scripts(0, ["script1", "script2.py", "script3.PY"])
+
+ def test_on_windows(self):
+ self.check_scripts(1, ["script1.py", "script2.py", "script3.PY"])
+
+ def check_scripts(self, on_windows, scripts):
+ dist = Distribution()
+ dist.scripts = self.script_sources
+ cmd = build_scripts(dist)
+ cmd.build_dir = self.destdir
+ cmd.on_windows = on_windows
+ cmd.ensure_finalized()
+ cmd.run()
+ for fn in scripts:
+ path = os.path.join(self.destdir, fn)
+ self.assert_(os.path.isfile(path),
+ "missing script " + fn)
+
+
+def test_suite():
+ return unittest.makeSuite(BuildScriptsTestCase)
+
+if __name__ == "__main__":
+ unittest.main(defaultTest="test_suite")
Property changes on: zpkgtools/branches/fdrake-scripts-on-windows/zpkgsetup/tests/test_build_scripts.py
___________________________________________________________________
Name: svn:mime-type
+ text/x-python
Name: svn:eol-style
+ native
More information about the Zope-CVS
mailing list