1999-03-22 14:55:25 +00:00
|
|
|
"""distutils.command.build_py
|
|
|
|
|
|
|
|
Implements the Distutils 'build_py' command."""
|
|
|
|
|
|
|
|
# created 1999/03/08, Greg Ward
|
|
|
|
|
|
|
|
__rcsid__ = "$Id$"
|
|
|
|
|
|
|
|
import string, os
|
|
|
|
from distutils.core import Command
|
|
|
|
from distutils.errors import *
|
|
|
|
from distutils.util import mkpath, newer, make_file, copy_file
|
|
|
|
|
|
|
|
|
|
|
|
class BuildPy (Command):
|
|
|
|
|
|
|
|
options = [('dir=', 'd', "directory for platform-shared files"),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def set_default_options (self):
|
|
|
|
self.dir = None
|
1999-09-08 02:42:30 +00:00
|
|
|
self.modules = None
|
|
|
|
self.package = None
|
1999-03-22 14:55:25 +00:00
|
|
|
|
|
|
|
def set_final_options (self):
|
|
|
|
self.set_undefined_options ('build',
|
1999-05-02 21:39:13 +00:00
|
|
|
('libdir', 'dir'))
|
1999-09-13 13:54:06 +00:00
|
|
|
# 'package' is an alias option in Distribution (hmmm, we
|
|
|
|
# really should change to "pull" options from Distribution
|
|
|
|
# rather than "pushing" them out to commands...)
|
1999-09-08 02:42:30 +00:00
|
|
|
if self.package is None:
|
|
|
|
self.package = ''
|
1999-03-22 14:55:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def run (self):
|
|
|
|
|
|
|
|
# XXX copy_file by default preserves all stat info -- mode, atime,
|
|
|
|
# and mtime. IMHO this is the right thing to do, but perhaps it
|
|
|
|
# should be an option -- in particular, a site administrator might
|
|
|
|
# want installed files to reflect the time of installation rather
|
|
|
|
# than the last modification time before the installed release.
|
|
|
|
|
|
|
|
# XXX copy_file does *not* preserve MacOS-specific file metadata.
|
|
|
|
# If this is a problem for building/installing Python modules, then
|
|
|
|
# we'll have to fix copy_file. (And what about installing scripts,
|
|
|
|
# when the time comes for that -- does MacOS use its special
|
|
|
|
# metadata to know that a file is meant to be interpreted by
|
|
|
|
# Python?)
|
|
|
|
|
|
|
|
self.set_final_options ()
|
|
|
|
|
|
|
|
infiles = []
|
|
|
|
outfiles = []
|
|
|
|
missing = []
|
|
|
|
|
|
|
|
# Loop over the list of "pure Python" modules, deriving
|
|
|
|
# input and output filenames and checking for missing
|
|
|
|
# input files.
|
|
|
|
|
1999-08-29 18:19:01 +00:00
|
|
|
# it's ok not to have *any* py files, right?
|
1999-09-08 02:42:30 +00:00
|
|
|
if not self.modules:
|
1999-08-29 18:19:01 +00:00
|
|
|
return
|
|
|
|
|
1999-03-22 14:55:25 +00:00
|
|
|
# XXX we should allow for wildcards, so eg. the Distutils setup.py
|
|
|
|
# file would just have to say
|
|
|
|
# py_modules = ['distutils.*', 'distutils.command.*']
|
|
|
|
# without having to list each one explicitly.
|
1999-09-08 02:42:30 +00:00
|
|
|
for m in self.modules:
|
1999-03-22 14:55:25 +00:00
|
|
|
fn = apply (os.path.join, tuple (string.split (m, '.'))) + '.py'
|
|
|
|
if not os.path.exists (fn):
|
|
|
|
missing.append (fn)
|
|
|
|
else:
|
|
|
|
infiles.append (fn)
|
1999-09-08 02:42:30 +00:00
|
|
|
outfiles.append (os.path.join (self.dir, self.package, fn))
|
1999-03-22 14:55:25 +00:00
|
|
|
|
|
|
|
# Blow up if any input files were not found.
|
|
|
|
if missing:
|
|
|
|
raise DistutilsFileError, \
|
|
|
|
"missing files: " + string.join (missing, ' ')
|
|
|
|
|
|
|
|
# Loop over the list of input files, copying them to their
|
|
|
|
# temporary (build) destination.
|
|
|
|
created = {}
|
|
|
|
for i in range (len (infiles)):
|
|
|
|
outdir = os.path.split (outfiles[i])[0]
|
|
|
|
if not created.get(outdir):
|
1999-04-04 02:46:29 +00:00
|
|
|
self.mkpath (outdir)
|
1999-03-22 14:55:25 +00:00
|
|
|
created[outdir] = 1
|
|
|
|
|
1999-04-04 02:46:29 +00:00
|
|
|
self.copy_file (infiles[i], outfiles[i])
|
1999-03-22 14:55:25 +00:00
|
|
|
|
|
|
|
# end class BuildPy
|