This is a single archived entry from Stefan Tilkov’s blog. For more up-to-date content, check out my author page at INNOQ, which has more information about me and also contains a list of published talks, podcasts, and articles. Or you can check out the full archive.

distutils support in Jython

Stefan Tilkov,

I wanted to play around with Jython, especially because I believe that Web services and dynamic languages should be a nice match. This is actually my first contact with Python, so I got stuck with a pretty simple problem: Most Python packages come with an installation routine based on distutils. Unfortunately, I was unable to install anything this way because distutils is not available with a standard Jython installation.
So I grabbed the distutils source itself, which I was unable to install either - it seems not to run with Jython out of the box.
The following two patches, based on information in the distutils mailing list, did the trick:
I added this to to INSTALL_SCHEMES dictionary:


'java': {
'purelib': '$base',
'platlib': '$base',
'headers': '$base/Include/$dist_name',
'scripts': '$base/Scripts',
'data' : '$base',
},

and then patched file_util.py from

if preserve_times:
os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))
if preserve_mode:
os.chmod(dst, S_IMODE(st[ST_MODE]))

to this:

if hasattr(os, 'utime'):
if preserve_times:
os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))
if hasattr(os, 'chmod'):
if preserve_mode:
os.chmod(dst, S_IMODE(st[ST_MODE]))

Ugly, probably stupid as hell ... but it worked.
On March 20, 2007 5:34 AM, Justin Ryan said:

The second blurb can be simplified and possibly more efficient as:

            if preserve_times and hasattr(os, 'utime'):

os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))

if preserve_mode and hasattr(os, 'chmod')::

os.chmod(dst, S_IMODE(st[ST_MODE]))

the hasattr will never run if the first is false, and that’s really the important condition.

That said, this isn’t working for me with latest Jython, though I did find that some people are trying to make utime and chmod work with a new javaos.py implementation.