2009-01-09 / 22:38 /

…er, actually that’s probably just me. My work laptop runs Windows for unfortunate corporate reasons. Cygwin staunches the bleeding, but the Cygwin build of Python has trouble with some packages (e.g. matplotlib and pymssql). So I’m running the cygwin shell but a Windows build of Python.

PyX–cool looking plotting/graphics tool–makes a subprocess call to kpsewhich to find files. The cygwin build of kpsewhich naturally returns a cygwin path; the windows build of python naturally chokes. As a hack, I edited /Python25/Lib/site-packages/pyx/pykpathsea/__init__.py to add a call to cygpath -w. I also replaced the os.popen calls with subprocess.Popen since os.popen 1) wasn’t working for me and 2) is deprecated.

The modified function:

    def find_file(filename, kpse_file_format):
        # 2009-01-08: DAG: edits to allow working with cygwin tex but windows
        # python.  Replaced os.popen with subprocess.Popen and added call to
        # "cygpath -w"
        command = 'kpsewhich --format="%s" %s' % (kpse_file_format, filename)
        if not find_file_cache.has_key(command):
            path = Popen(command, stdout=PIPE).communicate()[0].strip()
            if path:
                path = Popen('cygpath -w %s' % path, stdout=PIPE).communicate()[0].strip()
            find_file_cache[command] = path
        return find_file_cache[command]

The patch: pyx_cygwin.diff

The full file (zipped w/ path relative to Python25/Lib): pyx_cygwin.zip