Re: Call For Help! I need Windows/Python developers!
James Abbatiello <[email protected]> Fri, 26 Jun 2009 00:16:34 -0400
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
I've just compiled NameMapper under Windows. There is only a minor
change needed to _namemapper.c. See attached patch. I compiled this
on Windows XP using Visual C++ 2008 Express (that's the free version).
The Python version is 2.6.2 installed from the python.org installer.
I've also tried to get the tests running under Windows. There are a
few problems here:
1) Use of commands.getstatusoutput(). This isn't supported on
Windows. I've replaced this will subprocess.Popen which seems to be
the preferred new method.
2) Some tests assume that the shell will expand globs ("*.tmpl") and
the Windows shell doesn't do this. I'm skipping these tests on
Windows.
3) One place assumed that temp files went in /tmp. I fixed that to be
more general.
4) After running `setup.py install` there's no command-line "cheetah"
command installed. The tests that try to shell out and run this
command don't work. I've made a batch file and put it on my PATH to
work around this for now but I don't know what the proper long-term
solution is. Use setuptools to create a wrapper .exe?
A patch addressing 1 through 3 is attached.
--
James Abbatiello
------------------------------------------------------------------------------
_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
0001-Compile-fix-for-_namemapper.c-under-MSVC.patch
(application/octet-stream, 951 B)
From a11a8813242e0982d277a9cc0227d0db0681e4f3 Mon Sep 17 00:00:00 2001 From: James Abbatiello <[email protected]> Date: Fri, 26 Jun 2009 00:04:39 -0400 Subject: [PATCH 1/2] Compile fix for _namemapper.c under MSVC --- src/_namemapper.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/_namemapper.c b/src/_namemapper.c index 5767e16..18c47d6 100644 --- a/src/_namemapper.c +++ b/src/_namemapper.c @@ -231,8 +231,9 @@ PyNamemapper_valueForName(PyObject *obj, char *nameChunks[], nextVal = PyMapping_GetItemString(currentVal, currentKey); } else { + PyObject *exc; nextVal = PyObject_GetAttrString(currentVal, currentKey); - PyObject *exc = PyErr_Occurred(); + exc = PyErr_Occurred(); if (exc != NULL) { // if exception == AttributeError if (PyErr_ExceptionMatches(PyExc_AttributeError)) { -- 1.6.3.2.1299.gee46c
0002-Fix-tests-under-Windows.patch
(application/octet-stream, 4.7 KB)
From e3a7e232bdd5ac0ea0a7abc67b5c1c1d7ea17d8c Mon Sep 17 00:00:00 2001 From: James Abbatiello <[email protected]> Date: Fri, 26 Jun 2009 00:05:15 -0400 Subject: [PATCH 2/2] Fix tests under Windows --- src/Tests/CheetahWrapper.py | 48 +++++++++++++++++++++++++++++++++--------- src/Tests/Unicode.py | 4 +- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/Tests/CheetahWrapper.py b/src/Tests/CheetahWrapper.py index da79a6f..d1127d7 100644 --- a/src/Tests/CheetahWrapper.py +++ b/src/Tests/CheetahWrapper.py @@ -11,7 +11,7 @@ Besides unittest usage, recognizes the following command-line options: --output Show the output of each subcommand. (Normally suppressed.) ''' -import commands, os, shutil, sys, tempfile +import subprocess, os, shutil, sys, tempfile import unittest_local_copy as unittest import re # Used by listTests. @@ -27,6 +27,17 @@ BACKUP_SUFFIX = CheetahWrapper.BACKUP_SUFFIX def warn(msg): sys.stderr.write(msg + '\n') +def skipIf(cond, reason): + if not cond: + def _id(obj): + return obj + return _id + + def decorator(obj): + return None + return decorator + + class CFBase(unittest.TestCase): """Base class for "cheetah compile" and "cheetah fill" unit tests. """ @@ -149,11 +160,17 @@ Found %(result)r""" test. out: None. """ - # Use commands.getstatusoutput instead of os.system so - # that we can mimic ">/dev/null 2>/dev/null" even on - # non-Unix platforms. - exit, output = commands.getstatusoutput(cmd) - status, signal = divmod(exit, 256) + subproc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + shell=True) + output = subproc.communicate()[0] + if subproc.returncode >= 0: + status = subproc.returncode + signal = 0 + else: + status = 0 + signal = -subproc.returncode if OUTPUT: if output.endswith("\n"): output = output[:-1] @@ -180,11 +197,17 @@ Found %(result)r""" in : cmd, string, the command to run. out: None. """ - # Use commands.getstatusoutput instead of os.system so - # that we can mimic ">/dev/null 2>/dev/null" even on - # non-Unix platforms. - exit, output = commands.getstatusoutput(cmd) - status, signal = divmod(exit, 256) + subproc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + shell=True) + output = subproc.communicate()[0] + if subproc.returncode >= 0: + status = subproc.returncode + signal = 0 + else: + status = 0 + signal = -subproc.returncode msg = "subcommand killed by signal %s: %s" % (signal, cmd) self.failUnlessEqual(signal, 0, msg) # Signal must be 0. msg = "subcommand exit status %s: %s" % (status, cmd) @@ -238,6 +261,7 @@ class OneFileNoExtension(CFBase): self.checkFill("a.txt") +@skipIf(sys.platform == "win32", "cmd.exe doesn't expand globs") class SplatTmpl(CFBase): def testCompile(self): self.go("cheetah compile *.tmpl") @@ -291,6 +315,7 @@ class ThreeFilesWithSubdirectoriesNoExtension(CFBase): self.checkFill("child/grandkid/a.txt") +@skipIf(sys.platform == "win32", "cmd.exe doesn't expand globs") class SplatTmplWithSubdirectories(CFBase): def testCompile(self): self.go("cheetah compile *.tmpl child/*.tmpl child/grandkid/*.tmpl") @@ -326,6 +351,7 @@ class OneFileWithOdir(CFBase): self.checkFill("DEST/a.txt") +@skipIf(sys.platform == "win32", "cmd.exe doesn't expand globs") class VarietyWithOdir(CFBase): def testCompile(self): self.go("cheetah compile --odir DEST a.tmpl child/a child/grandkid/*.tmpl") diff --git a/src/Tests/Unicode.py b/src/Tests/Unicode.py index 3910d8d..bc951a5 100644 --- a/src/Tests/Unicode.py +++ b/src/Tests/Unicode.py @@ -24,8 +24,8 @@ class CommandLineTest(unittest.TestCase): wrap = CheetahWrapper.CheetahWrapper() wrap.main(['cheetah', 'compile', '--nobackup', sourcefile]) - module_name = os.path.basename(sourcefile) - module = loadModule(module_name, ['/tmp']) + module_path, module_name = os.path.split(sourcefile) + module = loadModule(module_name, [module_path]) template = getattr(module, module_name) return template -- 1.6.3.2.1299.gee46c