Considering the following schedule of events:
Oct 4: I go out of town (away from email, off the net, etc.)
Oct 10: planned release of Python 2.0
Oct 12: I'm back in town, ready to hack! (and wondering why it's
so quiet around here...)
the Distutils 1.0 release will go out October 1 or 2. I don't need
quite as much code freeze time as the full Python release, but let's put
it this way: if there are features you want added to the Distutils that
I don't already know about, forget about it. Changes currently under
consideration:
* Rene Liebscher's rearrangement of the CCompiler classes; most
of this is just reducing the amount of code, but it does
add some minor features, so it's under consideration.
* making byte-compilation more flexible: should be able to
generate both .pyc and .pyo files, and should be able to
do it at build time or install time (developer's and packager's
discretion)
If you know about any outstanding Distutils bugs, please tell me *now*.
Put 'em in the SourceForge bug database if you're wondering why I
haven't fixed them yet -- they might have gotten lost, I might not know
about 'em, etc. If you're not sure, put it in SourceForge.
Stuff that will definitely have to wait until after 1.0:
* a "test" command (standard test framework for Python modules)
* finishing the "config" command (auto-configuration)
* installing package meta-data, to support "what *do* I have
installed, anyways?" queries, uninstallation, upgrades, etc.
Blue-sky projects:
* standard documentation processing
* intra-module dependencies
Greg
--
Greg Ward gward(a)python.net
http://starship.python.net/~gward/
Hi all --
based on and inspired by recent patches from Marc-Andre Lemburg and Rene
Liebscher, I've finally started tackling the byte-compilation problem in
earnest. Here's the approach I'm taking:
* new function 'byte_compile()' in distutils.util: this is the all-
singing, all-dancing wrapper around py_compile that will do all
the real work
* reduce the 'bytecompile()' method in the install_lib command to
a simple wrapper around 'util.byte_compile()', that does the Right
Thing with respect to optimization and claimed source filename
written to the .py{c,o} file
* add similar functionality to the build_py command, so that you
may optionally do byte-compilation at build time rather than
install time.
The first two steps are done and checked in, except that install_lib's
'bytecompile()' method doesn't yet take advantage of the fancy features
in the new 'byte_compile()' -- it doesn't rewrite filenames or do
optimization.
The default will continue to be doing compilation at install time rather
than build time. I'm still leaning towards build-time compilation, but
it's too late in the Distutils 1.0 release cycle to change things like
this. However, I want to have the *option* to do compilation at build
time, so people can experiment with it, see if it works, figure out what
other features are needed so it really works, etc. The idea is that
developers could put settings in their setup.cfg that control when to do
byte-compilation; I suspect developers who want to distribute
closed-source modules will have to do build-time compilation. Probably
the "install" command will need some sort of "don't install source"
option, or maybe the build command should have a "blow away source after
compiling it" option.
Here's my 'byte_compile()' function: as usual, it works for me. Please
review it, and if you're following CVS, try it out. (Should be enough
to install any module distribution containing pure Python modules.)
------------------------------------------------------------------------
def byte_compile (py_files,
optimize=0, force=0,
prefix=None, base_dir=None,
verbose=1, dry_run=0,
direct=None):
"""Byte-compile a collection of Python source files to either
.pyc or .pyo files in the same directory. 'optimize' must be
one of the following:
0 - don't optimize (generate .pyc)
1 - normal optimization (like "python -O")
2 - extra optimization (like "python -OO")
If 'force' is true, all files are recompiled regardless of
timestamps.
The source filename encoded in each bytecode file defaults to the
filenames listed in 'py_files'; you can modify these with 'prefix' and
'basedir'. 'prefix' is a string that will be stripped off of each
source filename, and 'base_dir' is a directory name that will be
prepended (after 'prefix' is stripped). You can supply either or both
(or neither) of 'prefix' and 'base_dir', as you wish.
If 'verbose' is true, prints out a report of each file. If 'dry_run'
is true, doesn't actually do anything that would affect the filesystem.
Byte-compilation is either done directly in this interpreter process
with the standard py_compile module, or indirectly by writing a
temporary script and executing it. Normally, you should let
'byte_compile()' figure out to use direct compilation or not (see
the source for details). The 'direct' flag is used by the script
generated in indirect mode; unless you know what you're doing, leave
it set to None.
"""
# First, if the caller didn't force us into direct or indirect mode,
# figure out which mode we should be in. We take a conservative
# approach: choose direct mode *only* if the current interpreter is
# in debug mode and optimize is 0. If we're not in debug mode (-O
# or -OO), we don't know which level of optimization this
# interpreter is running with, so we can't do direct
# byte-compilation and be certain that it's the right thing. Thus,
# always compile indirectly if the current interpreter is in either
# optimize mode, or if either optimization level was requested by
# the caller.
if direct is None:
direct = (__debug__ and optimize == 0)
# "Indirect" byte-compilation: write a temporary script and then
# run it with the appropriate flags.
if not direct:
from tempfile import mktemp
script_name = mktemp(".py")
if verbose:
print "writing byte-compilation script '%s'" % script_name
if not dry_run:
script = open(script_name, "w")
script.write("""\
from distutils.util import byte_compile
files = [
""")
script.write(string.join(map(repr, py_files), ",\n") + "]\n")
script.write("""
byte_compile(files, optimize=%s, force=%s,
prefix=%s, base_dir=%s,
verbose=%s, dry_run=0,
direct=1)
""" % (`optimize`, `force`, `prefix`, `base_dir`, `verbose`))
script.close()
cmd = [sys.executable, script_name]
if optimize == 1:
cmd.insert(1, "-O")
elif optimize == 2:
cmd.insert(1, "-OO")
spawn(cmd, verbose=verbose, dry_run=dry_run)
# "Direct" byte-compilation: use the py_compile module to compile
# right here, right now. Note that the script generated in indirect
# mode simply calls 'byte_compile()' in direct mode, a weird sort of
# cross-process recursion. Hey, it works!
else:
from py_compile import compile
for file in py_files:
if file[-3:] != ".py":
raise ValueError, \
"invalid filename: %s doesn't end with '.py'" % `file`
# Terminology from the py_compile module:
# cfile - byte-compiled file
# dfile - purported source filename (same as 'file' by default)
cfile = file + (__debug__ and "c" or "o")
dfile = file
if prefix:
if file[:len(prefix)] != prefix:
raise ValueError, \
("invalid prefix: filename %s doesn't start with %s"
% (`file`, `prefix`))
dfile = dfile[len(prefix):]
if base_dir:
dfile = os.path.join(base_dir, dfile)
cfile_base = os.path.basename(cfile)
if direct:
if force or newer(file, cfile):
if verbose:
print "byte-compiling %s to %s" % (file, cfile_base)
if not dry_run:
compile(file, cfile, dfile)
else:
if verbose:
print "skipping byte-compilation of %s to %s" % \
(file, cfile_base)
------------------------------------------------------------------------
--
Greg Ward gward(a)python.net
http://starship.python.net/~gward/
Python Distribution Utilities
release 1.0
October 2, 2000
The Python Distribution Utilities, or Distutils for short, are a
collection of modules that aid in the development, distribution, and
installation of Python modules. (It is intended that ultimately the
Distutils will grow up into a system for distributing and installing
whole Python applications, but for now their scope is limited to module
distributions.)
The Distutils are a standard part of Python 1.6 and 2.0; if you are running
1.6 or 2.0, you don't need to install the Distutils separately. (However,
you might want to upgrade if you're running Python 1.6.) This release is
primarily so that you can add the Distutils to a Python 1.5.2 installation
-- you will then be able to install modules that require the Distutils, or
use the Distutils to distribute your own modules.
Distutils 1.0 is the version that will be released with Python 2.0 (unless
last-minute bugs pop up).
More information is available at the Distutils web page:
http://www.python.org/sigs/distutils-sig/
and in the README.txt included in the Distutils source distribution.
You can download the Distutils from
http://www.python.org/sigs/distutils-sig/download.html
Trivial patches can be sent to me (Greg Ward) at gward(a)python.net.
Larger patches should be discussed on the Distutils mailing list:
distutils-sig(a)python.org.
Greg
--
Greg Ward gward(a)python.net
http://starship.python.net/~gward/
And now for something completely different.
I just had the idea to make bcccompiler a little bit
more robust.
By default, python is delivered with pythonxx.lib
and pythonxx_d.lib import libraries generated by MSVC,
which are in COFF format. By inspection I found
that these libraries start with the bytes '!<arch>./'
(without the single quotes).
Shouldn't we open these files and issue a warning
or error if they start with these bytes?
We could even invoke borland's coff2omf utility
to convert them...
Thomas
Hi all --
I just finished hacking up the bytecode compilation stuff. Turns out
that was a lot more fun than working on the test suite. Anyways, this
is the last non-bug-fix that's going to get into Distutils 1.0, which I
plan on releasing tomorrow (Monday) night. After that, I won't be
available until Oct 12, so the code I release tomorrow night will almost
certainly be what goes out with Python 2.0
So, obviously, I need all your help to beat up on this code snapshot!
You know the routine by now: please give this snapshot a workout on your
favourite Python module distribution on a variety of platforms. You can
download it from the usual place:
http://www.python.org/sigs/distutils-sig/download.html
Thanks!
Greg
--
Greg Ward gward(a)python.net
http://starship.python.net/~gward/
i've got a python extension that is simply a wrapping
around another C library. (not an uncommon case :])
i cannot figure out the 'right' way to check for and
link/include this dependency into my distutils
setup.py script.
under linux, it's pretty easy to assume the correct
header and shared library will be somewhere in the
standard include and library directories
/usr/local/include, /usr/local/lib, etc
my main concern is getting it working with windows
(and keeping it crossplatform happy for linux). my best
bet in windows seems to be walk around the parent directory
tree trying to find directories for the dependency??
if that is the best way, it would probably be nice for
the linux version to use this method or look in the
standard compiler directories ???????
i'm hoping someone out there has an example doing just
this sort of stuff i could look at. the documentation doesn't
mention anything about this sort of stuff. (except for
adding library and include info to the Extensions() call
thanks for any help and/or guidance. the distutils have
just amazed me.
(please help, i couldn't get any responses on c.l.python)
On 02 October 2000, Mark Favas said:
> With the current (Oct 2) CVS versions of PyXML and Python (2), running
> "python setup.py install" produces the following glitch: copies all the
> relevant files to /usr/local/lib/python2.0/site-packages/_xmlplus and
> then tries to compile them all. Unfortunatley, it tries to byte-compile
> sgmlop.so, leading to the traceback below. Is this a PyXML mis-setup of
> setup.py or a distutils (Python core version) bug?
D'ohh! That's a Distutils bug, introduced last night. Just checked in
a fix -- thanks for the quick report!
BTW, it doesn't matter if you follow the Python CVS or the Distutils
CVS, you'll get my latest code either way.
Greg
--
Greg Ward gward(a)python.net
http://starship.python.net/~gward/
Hi all --
some months ago, I added completely experimental and untested support
for compiling SWIG extensions to the Distutils. I even documented it!
But I have been unable to verify for myself that it works, since I have
been unable to build SWIG on my home PC. I haven't heard any reports of
success, and the first reports of failure were from 4Thought last week.
So: can anyone vouch for whether the Distutils SWIG support works at
all, does the "right thing", etc? What's broken about it, what works?
Should it even be documented?
Greg
--
Greg Ward gward(a)python.net
http://starship.python.net/~gward/