Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 1 | # created 1999/03/13, Greg Ward |
| 2 | |
Greg Ward | 3ce77fd | 2000-03-02 01:49:45 +0000 | [diff] [blame] | 3 | __revision__ = "$Id$" |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 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 | |
Greg Ward | 297dd9f | 2000-03-23 04:37:11 +0000 | [diff] [blame^] | 9 | class install_lib (Command): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 10 | |
Greg Ward | 37bc815 | 2000-01-30 18:34:15 +0000 | [diff] [blame] | 11 | description = "install pure Python modules" |
| 12 | |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 13 | user_options = [ |
| 14 | ('install-dir=', 'd', "directory to install to"), |
| 15 | ('build-dir=','b', "build directory (where to install from)"), |
| 16 | ('compile', 'c', "compile .py to .pyc"), |
| 17 | ('optimize', 'o', "compile .py to .pyo (optimized)"), |
| 18 | ] |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 19 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 20 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 21 | def initialize_options (self): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 22 | # let the 'install' command dictate our installation directory |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 23 | self.install_dir = None |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 24 | self.build_dir = None |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 25 | self.compile = 1 |
| 26 | self.optimize = 1 |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 27 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 28 | def finalize_options (self): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 29 | |
Greg Ward | fa4eb18 | 1999-09-13 13:58:34 +0000 | [diff] [blame] | 30 | # Get all the information we need to install pure Python modules |
| 31 | # from the umbrella 'install' command -- build (source) directory, |
| 32 | # install (target) directory, and whether to compile .py files. |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 33 | self.set_undefined_options ('install', |
| 34 | ('build_lib', 'build_dir'), |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 35 | ('install_lib', 'install_dir'), |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 36 | ('compile_py', 'compile'), |
| 37 | ('optimize_py', 'optimize')) |
| 38 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 39 | |
| 40 | def run (self): |
| 41 | |
Greg Ward | 7478a48 | 2000-01-30 15:07:56 +0000 | [diff] [blame] | 42 | # Make sure we have "built" all pure Python modules first |
| 43 | self.run_peer ('build_py') |
| 44 | |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 45 | # Install everything: simply dump the entire contents of the build |
| 46 | # directory to the installation directory (that's the beauty of |
| 47 | # having a build directory!) |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 48 | outfiles = self.copy_tree (self.build_dir, self.install_dir) |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 49 | |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 50 | # (Optionally) compile .py to .pyc |
| 51 | # XXX hey! we can't control whether we optimize or not; that's up |
| 52 | # to the invocation of the current Python interpreter (at least |
| 53 | # according to the py_compile docs). That sucks. |
| 54 | |
| 55 | if self.compile: |
| 56 | from py_compile import compile |
| 57 | |
| 58 | for f in outfiles: |
Greg Ward | 4f08e4f | 2000-02-26 00:49:04 +0000 | [diff] [blame] | 59 | # XXX can't assume this filename mapping! (what if |
| 60 | # we're running under "python -O"?) |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 61 | |
Greg Ward | 440e2f5 | 1999-08-29 18:19:37 +0000 | [diff] [blame] | 62 | # only compile the file if it is actually a .py file |
| 63 | if f[-3:] == '.py': |
| 64 | out_fn = string.replace (f, '.py', '.pyc') |
| 65 | |
| 66 | self.make_file (f, out_fn, compile, (f,), |
Greg Ward | ef9ad6d | 1999-10-03 21:03:26 +0000 | [diff] [blame] | 67 | "byte-compiling %s" % f, |
| 68 | "byte-compilation of %s skipped" % f) |
Greg Ward | 440e2f5 | 1999-08-29 18:19:37 +0000 | [diff] [blame] | 69 | |
Greg Ward | 0f72695 | 1999-05-02 21:39:13 +0000 | [diff] [blame] | 70 | # XXX ignore self.optimize for now, since we don't really know if |
| 71 | # we're compiling optimally or not, and couldn't pick what to do |
| 72 | # even if we did know. ;-( |
| 73 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 74 | # run () |
| 75 | |
| 76 | # class InstallPy |