Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 1 | # created 1999/03/13, Greg Ward |
| 2 | |
| 3 | __rcsid__ = "$Id$" |
| 4 | |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 5 | import sys, string |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 6 | from distutils.core import Command |
| 7 | from distutils.util import copy_tree |
| 8 | |
| 9 | class InstallPy (Command): |
| 10 | |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 11 | options = [('install-dir=', 'd', "directory to install to"), |
Greg Ward | 440e2f5 | 1999-08-29 18:19:37 +0000 | [diff] [blame] | 12 | ('build-dir=','b', "build directory (where to install from)"), |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 13 | ('compile', 'c', "compile .py to .pyc"), |
| 14 | ('optimize', 'o', "compile .py to .pyo (optimized)"), |
| 15 | ] |
| 16 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 17 | |
| 18 | def set_default_options (self): |
| 19 | # let the 'install' command dictate our installation directory |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 20 | self.install_dir = None |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 21 | self.build_dir = None |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 22 | self.compile = 1 |
| 23 | self.optimize = 1 |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 24 | |
| 25 | def set_final_options (self): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 26 | |
Greg Ward | fa4eb18 | 1999-09-13 13:58:34 +0000 | [diff] [blame] | 27 | # Find out from the 'build_ext' command if we were asked to build |
| 28 | # any extensions. If so, that means even pure-Python modules in |
| 29 | # this distribution have to be installed to the "platlib" |
| 30 | # directory. |
| 31 | extensions = self.get_peer_option ('build_ext', 'extensions') |
| 32 | if extensions: |
| 33 | dir_option = 'install_site_platlib' |
| 34 | else: |
| 35 | dir_option = 'install_site_lib' |
| 36 | |
| 37 | # Get all the information we need to install pure Python modules |
| 38 | # from the umbrella 'install' command -- build (source) directory, |
| 39 | # install (target) directory, and whether to compile .py files. |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 40 | self.set_undefined_options ('install', |
| 41 | ('build_lib', 'build_dir'), |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 42 | (dir_option, 'install_dir'), |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 43 | ('compile_py', 'compile'), |
| 44 | ('optimize_py', 'optimize')) |
| 45 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 46 | |
| 47 | def run (self): |
| 48 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 49 | # Dump entire contents of the build directory to the installation |
| 50 | # directory (that's the beauty of having a build directory!) |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 51 | outfiles = self.copy_tree (self.build_dir, self.install_dir) |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 52 | |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 53 | # (Optionally) compile .py to .pyc |
| 54 | # XXX hey! we can't control whether we optimize or not; that's up |
| 55 | # to the invocation of the current Python interpreter (at least |
| 56 | # according to the py_compile docs). That sucks. |
| 57 | |
| 58 | if self.compile: |
| 59 | from py_compile import compile |
| 60 | |
| 61 | for f in outfiles: |
| 62 | # XXX can't assume this filename mapping! |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 63 | |
Greg Ward | 440e2f5 | 1999-08-29 18:19:37 +0000 | [diff] [blame] | 64 | # only compile the file if it is actually a .py file |
| 65 | if f[-3:] == '.py': |
| 66 | out_fn = string.replace (f, '.py', '.pyc') |
| 67 | |
| 68 | self.make_file (f, out_fn, compile, (f,), |
Greg Ward | ef9ad6d | 1999-10-03 21:03:26 +0000 | [diff] [blame^] | 69 | "byte-compiling %s" % f, |
| 70 | "byte-compilation of %s skipped" % f) |
Greg Ward | 440e2f5 | 1999-08-29 18:19:37 +0000 | [diff] [blame] | 71 | |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 72 | # XXX ignore self.optimize for now, since we don't really know if |
| 73 | # we're compiling optimally or not, and couldn't pick what to do |
| 74 | # even if we did know. ;-( |
| 75 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 76 | # run () |
| 77 | |
| 78 | # class InstallPy |