Mercurial > cpython-lru_cache-weakref
annotate Lib/packaging/command/install_lib.py @ 70817:dd775b1561ba
Fix markup.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 14 Jun 2011 21:09:55 +0200 |
| parents | 1a31c3be88b1 |
| children | 28e4cd8fd864 |
| rev | line source |
|---|---|
|
70194
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
1 """Install all modules (extensions and pure Python).""" |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
2 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
3 import os |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
4 import sys |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
5 import logging |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
6 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
7 from packaging import logger |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
8 from packaging.command.cmd import Command |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
9 from packaging.errors import PackagingOptionError |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
10 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
11 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
12 # Extension for Python source files. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
13 if hasattr(os, 'extsep'): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
14 PYTHON_SOURCE_EXTENSION = os.extsep + "py" |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
15 else: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
16 PYTHON_SOURCE_EXTENSION = ".py" |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
17 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
18 class install_lib(Command): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
19 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
20 description = "install all modules (extensions and pure Python)" |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
21 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
22 # The byte-compilation options are a tad confusing. Here are the |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
23 # possible scenarios: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
24 # 1) no compilation at all (--no-compile --no-optimize) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
25 # 2) compile .pyc only (--compile --no-optimize; default) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
26 # 3) compile .pyc and "level 1" .pyo (--compile --optimize) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
27 # 4) compile "level 1" .pyo only (--no-compile --optimize) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
28 # 5) compile .pyc and "level 2" .pyo (--compile --optimize-more) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
29 # 6) compile "level 2" .pyo only (--no-compile --optimize-more) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
30 # |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
31 # The UI for this is two option, 'compile' and 'optimize'. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
32 # 'compile' is strictly boolean, and only decides whether to |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
33 # generate .pyc files. 'optimize' is three-way (0, 1, or 2), and |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
34 # decides both whether to generate .pyo files and what level of |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
35 # optimization to use. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
36 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
37 user_options = [ |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
38 ('install-dir=', 'd', "directory to install to"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
39 ('build-dir=','b', "build directory (where to install from)"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
40 ('force', 'f', "force installation (overwrite existing files)"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
41 ('compile', 'c', "compile .py to .pyc [default]"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
42 ('no-compile', None, "don't compile .py files"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
43 ('optimize=', 'O', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
44 "also compile with optimization: -O1 for \"python -O\", " |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
45 "-O2 for \"python -OO\", and -O0 to disable [default: -O0]"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
46 ('skip-build', None, "skip the build steps"), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
47 ] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
48 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
49 boolean_options = ['force', 'compile', 'skip-build'] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
50 negative_opt = {'no-compile' : 'compile'} |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
51 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
52 def initialize_options(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
53 # let the 'install_dist' command dictate our installation directory |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
54 self.install_dir = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
55 self.build_dir = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
56 self.force = False |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
57 self.compile = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
58 self.optimize = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
59 self.skip_build = None |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
60 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
61 def finalize_options(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
62 # Get all the information we need to install pure Python modules |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
63 # from the umbrella 'install_dist' command -- build (source) directory, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
64 # install (target) directory, and whether to compile .py files. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
65 self.set_undefined_options('install_dist', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
66 ('build_lib', 'build_dir'), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
67 ('install_lib', 'install_dir'), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
68 'force', 'compile', 'optimize', 'skip_build') |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
69 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
70 if self.compile is None: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
71 self.compile = True |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
72 if self.optimize is None: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
73 self.optimize = 0 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
74 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
75 if not isinstance(self.optimize, int): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
76 try: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
77 self.optimize = int(self.optimize) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
78 if self.optimize not in (0, 1, 2): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
79 raise AssertionError |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
80 except (ValueError, AssertionError): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
81 raise PackagingOptionError("optimize must be 0, 1, or 2") |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
82 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
83 def run(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
84 # Make sure we have built everything we need first |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
85 self.build() |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
86 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
87 # Install everything: simply dump the entire contents of the build |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
88 # directory to the installation directory (that's the beauty of |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
89 # having a build directory!) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
90 outfiles = self.install() |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
91 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
92 # (Optionally) compile .py to .pyc |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
93 if outfiles is not None and self.distribution.has_pure_modules(): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
94 self.byte_compile(outfiles) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
95 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
96 # -- Top-level worker functions ------------------------------------ |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
97 # (called from 'run()') |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
98 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
99 def build(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
100 if not self.skip_build: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
101 if self.distribution.has_pure_modules(): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
102 self.run_command('build_py') |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
103 if self.distribution.has_ext_modules(): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
104 self.run_command('build_ext') |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
105 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
106 def install(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
107 if os.path.isdir(self.build_dir): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
108 outfiles = self.copy_tree(self.build_dir, self.install_dir) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
109 else: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
110 logger.warning( |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
111 '%s: %r does not exist -- no Python modules to install', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
112 self.get_command_name(), self.build_dir) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
113 return |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
114 return outfiles |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
115 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
116 def byte_compile(self, files): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
117 if getattr(sys, 'dont_write_bytecode'): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
118 # XXX do we want this? because a Python runs without bytecode |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
119 # doesn't mean that the *dists should not contain bytecode |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
120 #--or does it? |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
121 logger.warning('%s: byte-compiling is disabled, skipping.', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
122 self.get_command_name()) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
123 return |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
124 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
125 from packaging.util import byte_compile |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
126 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
127 # Get the "--root" directory supplied to the "install_dist" command, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
128 # and use it as a prefix to strip off the purported filename |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
129 # encoded in bytecode files. This is far from complete, but it |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
130 # should at least generate usable bytecode in RPM distributions. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
131 install_root = self.get_finalized_command('install_dist').root |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
132 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
133 # Temporary kludge until we remove the verbose arguments and use |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
134 # logging everywhere |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
135 verbose = logger.getEffectiveLevel() >= logging.DEBUG |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
136 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
137 if self.compile: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
138 byte_compile(files, optimize=0, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
139 force=self.force, prefix=install_root, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
140 dry_run=self.dry_run) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
141 if self.optimize > 0: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
142 byte_compile(files, optimize=self.optimize, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
143 force=self.force, prefix=install_root, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
144 verbose=verbose, |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
145 dry_run=self.dry_run) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
146 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
147 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
148 # -- Utility methods ----------------------------------------------- |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
149 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
150 def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
151 if not has_any: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
152 return [] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
153 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
154 build_cmd = self.get_finalized_command(build_cmd) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
155 build_files = build_cmd.get_outputs() |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
156 build_dir = getattr(build_cmd, cmd_option) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
157 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
158 prefix_len = len(build_dir) + len(os.sep) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
159 outputs = [] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
160 for file in build_files: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
161 outputs.append(os.path.join(output_dir, file[prefix_len:])) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
162 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
163 return outputs |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
164 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
165 def _bytecode_filenames(self, py_filenames): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
166 bytecode_files = [] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
167 for py_file in py_filenames: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
168 # Since build_py handles package data installation, the |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
169 # list of outputs can contain more than just .py files. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
170 # Make sure we only report bytecode for the .py files. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
171 ext = os.path.splitext(os.path.normcase(py_file))[1] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
172 if ext != PYTHON_SOURCE_EXTENSION: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
173 continue |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
174 if self.compile: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
175 bytecode_files.append(py_file + "c") |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
176 if self.optimize > 0: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
177 bytecode_files.append(py_file + "o") |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
178 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
179 return bytecode_files |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
180 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
181 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
182 # -- External interface -------------------------------------------- |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
183 # (called by outsiders) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
184 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
185 def get_outputs(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
186 """Return the list of files that would be installed if this command |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
187 were actually run. Not affected by the "dry-run" flag or whether |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
188 modules have actually been built yet. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
189 """ |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
190 pure_outputs = \ |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
191 self._mutate_outputs(self.distribution.has_pure_modules(), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
192 'build_py', 'build_lib', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
193 self.install_dir) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
194 if self.compile: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
195 bytecode_outputs = self._bytecode_filenames(pure_outputs) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
196 else: |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
197 bytecode_outputs = [] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
198 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
199 ext_outputs = \ |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
200 self._mutate_outputs(self.distribution.has_ext_modules(), |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
201 'build_ext', 'build_lib', |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
202 self.install_dir) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
203 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
204 return pure_outputs + bytecode_outputs + ext_outputs |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
205 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
206 def get_inputs(self): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
207 """Get the list of files that are input to this command, ie. the |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
208 files that get installed as they are named in the build tree. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
209 The files in this list correspond one-to-one to the output |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
210 filenames returned by 'get_outputs()'. |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
211 """ |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
212 inputs = [] |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
213 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
214 if self.distribution.has_pure_modules(): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
215 build_py = self.get_finalized_command('build_py') |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
216 inputs.extend(build_py.get_outputs()) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
217 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
218 if self.distribution.has_ext_modules(): |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
219 build_ext = self.get_finalized_command('build_ext') |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
220 inputs.extend(build_ext.get_outputs()) |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
221 |
|
1a31c3be88b1
initial import of the packaging package in the standard library
Tarek Ziade <tarek@ziade.org>
parents:
diff
changeset
|
222 return inputs |
