blob: f147af47f300f2039dc8084dfcba5a8cf8a43392 [file] [log] [blame]
Greg Ward13ae1c81999-03-22 14:55:25 +00001# created 1999/03/13, Greg Ward
2
3__rcsid__ = "$Id$"
4
Greg Ward0f726951999-05-02 21:39:13 +00005import sys, string
Greg Ward13ae1c81999-03-22 14:55:25 +00006from distutils.core import Command
7from distutils.util import copy_tree
8
9class InstallPy (Command):
10
11 options = [('dir=', 'd', "directory to install to"),
Greg Ward0f726951999-05-02 21:39:13 +000012 ('build-dir=' 'b', "build directory (where to install from)"),
13 ('compile', 'c', "compile .py to .pyc"),
14 ('optimize', 'o', "compile .py to .pyo (optimized)"),
15 ]
16
Greg Ward13ae1c81999-03-22 14:55:25 +000017
18 def set_default_options (self):
19 # let the 'install' command dictate our installation directory
20 self.dir = None
21 self.build_dir = None
Greg Ward0f726951999-05-02 21:39:13 +000022 self.compile = 1
23 self.optimize = 1
Greg Ward13ae1c81999-03-22 14:55:25 +000024
25 def set_final_options (self):
26 # If we don't have a 'dir' value, we'll have to ask the 'install'
27 # command for one. (This usually means the user ran 'install_py'
28 # directly, rather than going through 'install' -- so in reality,
29 # 'find_command_obj()' will create an 'install' command object,
30 # which we then query.
31
32 self.set_undefined_options ('install',
33 ('build_lib', 'build_dir'),
Greg Ward0f726951999-05-02 21:39:13 +000034 ('install_site_lib', 'dir'),
35 ('compile_py', 'compile'),
36 ('optimize_py', 'optimize'))
37
Greg Ward13ae1c81999-03-22 14:55:25 +000038
39 def run (self):
40
41 self.set_final_options ()
42
43 # Dump entire contents of the build directory to the installation
44 # directory (that's the beauty of having a build directory!)
Greg Ward0f726951999-05-02 21:39:13 +000045 outfiles = self.copy_tree (self.build_dir, self.dir)
Greg Ward13ae1c81999-03-22 14:55:25 +000046
Greg Ward0f726951999-05-02 21:39:13 +000047 # (Optionally) compile .py to .pyc
48 # XXX hey! we can't control whether we optimize or not; that's up
49 # to the invocation of the current Python interpreter (at least
50 # according to the py_compile docs). That sucks.
51
52 if self.compile:
53 from py_compile import compile
54
55 for f in outfiles:
56 # XXX can't assume this filename mapping!
57 out_fn = string.replace (f, '.py', '.pyc')
58
59 self.make_file (f, out_fn, compile, (f,),
60 "compiling %s -> %s" % (f, out_fn),
61 "compilation of %s skipped" % f)
62
63 # XXX ignore self.optimize for now, since we don't really know if
64 # we're compiling optimally or not, and couldn't pick what to do
65 # even if we did know. ;-(
66
Greg Ward13ae1c81999-03-22 14:55:25 +000067 # run ()
68
69# class InstallPy