annotate Lib/distutils/command/build_scripts.py @ 57303:4aa4c19dfaed legacy-trunk

#1757126: fix typo with the cyrillic_asian alias
author Philip Jenvey <pjenvey@underboss.org>
date Tue, 17 Nov 2009 02:42:26 +0000
parents 8dc28a126b2c
children fa69e891edf4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
1 """distutils.command.build_scripts
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
2
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
3 Implements the Distutils 'build_scripts' command."""
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
4
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
5 __revision__ = "$Id$"
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
6
45468
1d84bf5f9478 Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents: 44430
diff changeset
7 import os, re
27355
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
8 from stat import ST_MODE
21330
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
9 from distutils import sysconfig
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
10 from distutils.core import Command
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
11 from distutils.dep_util import newer
18871
1b09a9cb06d5 Do convert_path() on script paths (now PyXML builds out of the box
Just van Rossum <just@letterror.com>
parents: 18831
diff changeset
12 from distutils.util import convert_path
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22082
diff changeset
13 from distutils import log
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
14
18831
132c4bfdba74 Undo revision 1.7: always mangle a #! line containing "python" to point
Greg Ward <gward@python.net>
parents: 16956
diff changeset
15 # check if Python is called on the first line with this expression
29621
ded9abcb9174 Do not add extra "\n" after bang line.
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 27520
diff changeset
16 first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$')
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
17
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
18 class build_scripts (Command):
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
19
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
20 description = "\"build\" scripts (copy and fixup #! line)"
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
21
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
22 user_options = [
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
23 ('build-dir=', 'd', "directory to \"build\" (copy) to"),
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
24 ('force', 'f', "forcibly build everything (ignore file timestamps"),
33266
4e9ecbf47b6b Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents: 32736
diff changeset
25 ('executable=', 'e', "specify final destination interpreter path"),
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
26 ]
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
27
14829
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
28 boolean_options = ['force']
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
29
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
30
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
31 def initialize_options (self):
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
32 self.build_dir = None
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
33 self.scripts = None
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
34 self.force = None
33266
4e9ecbf47b6b Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents: 32736
diff changeset
35 self.executable = None
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
36 self.outfiles = None
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
37
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
38 def finalize_options (self):
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
39 self.set_undefined_options('build',
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
40 ('build_scripts', 'build_dir'),
33266
4e9ecbf47b6b Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents: 32736
diff changeset
41 ('force', 'force'),
4e9ecbf47b6b Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents: 32736
diff changeset
42 ('executable', 'executable'))
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
43 self.scripts = self.distribution.scripts
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
44
31852
2cfe14275a04 backport fix for SF bug #796042: sdist ignores scripts argument in setup
Fred Drake <fdrake@acm.org>
parents: 29621
diff changeset
45 def get_source_files(self):
2cfe14275a04 backport fix for SF bug #796042: sdist ignores scripts argument in setup
Fred Drake <fdrake@acm.org>
parents: 29621
diff changeset
46 return self.scripts
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
47
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
48 def run (self):
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
49 if not self.scripts:
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
50 return
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
51 self.copy_scripts()
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
52
16956
a1b3446c720f When not copying a file because the output is up to date, make the message
Fred Drake <fdrake@acm.org>
parents: 16846
diff changeset
53
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
54 def copy_scripts (self):
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
55 """Copy each script listed in 'self.scripts'; if it's marked as a
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
56 Python script in the Unix way (first line matches 'first_line_re',
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
57 ie. starts with "\#!" and contains "python"), then adjust the first
13725
449dd3a00bd7 Fixed a grab-bag of typos spotted by Rob Hooft.
Greg Ward <gward@python.net>
parents: 12752
diff changeset
58 line to refer to the current Python interpreter as we copy.
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
59 """
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
60 self.mkpath(self.build_dir)
27355
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
61 outfiles = []
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
62 for script in self.scripts:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
63 adjust = 0
18871
1b09a9cb06d5 Do convert_path() on script paths (now PyXML builds out of the box
Just van Rossum <just@letterror.com>
parents: 18831
diff changeset
64 script = convert_path(script)
12752
7b49334a6369 Take the basename of the script before concatenating it with the build dir.
Greg Ward <gward@python.net>
parents: 12748
diff changeset
65 outfile = os.path.join(self.build_dir, os.path.basename(script))
27355
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
66 outfiles.append(outfile)
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
67
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
68 if not self.force and not newer(script, outfile):
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22082
diff changeset
69 log.debug("not copying %s (up-to-date)", script)
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
70 continue
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
71
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
72 # Always open the file, but ignore failures in dry-run mode --
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
73 # that way, we'll get accurate feedback if we can read the
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
74 # script.
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
75 try:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
76 f = open(script, "r")
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
77 except IOError:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
78 if not self.dry_run:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
79 raise
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
80 f = None
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
81 else:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
82 first_line = f.readline()
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
83 if not first_line:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
84 self.warn("%s is an empty file (skipping)" % script)
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
85 continue
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
86
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
87 match = first_line_re.match(first_line)
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
88 if match:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
89 adjust = 1
21355
003dc573b295 Joe VanAndel wrote:
Marc-André Lemburg <mal@egenix.com>
parents: 21330
diff changeset
90 post_interp = match.group(1) or ''
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
91
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
92 if adjust:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22082
diff changeset
93 log.info("copying and adjusting %s -> %s", script,
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22082
diff changeset
94 self.build_dir)
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
95 if not self.dry_run:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
96 outf = open(outfile, "w")
21330
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
97 if not sysconfig.python_build:
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31852
diff changeset
98 outf.write("#!%s%s\n" %
33266
4e9ecbf47b6b Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents: 32736
diff changeset
99 (self.executable,
21330
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
100 post_interp))
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
101 else:
29621
ded9abcb9174 Do not add extra "\n" after bang line.
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 27520
diff changeset
102 outf.write("#!%s%s\n" %
21330
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
103 (os.path.join(
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
104 sysconfig.get_config_var("BINDIR"),
51616
8dc28a126b2c Fixed #4524: distutils build_script command failed with --with-suffix=3
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
105 "python%s%s" % (sysconfig.get_config_var("VERSION"),
8dc28a126b2c Fixed #4524: distutils build_script command failed with --with-suffix=3
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
106 sysconfig.get_config_var("EXE"))),
21330
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
107 post_interp))
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
108 outf.writelines(f.readlines())
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
109 outf.close()
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
110 if f:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
111 f.close()
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
112 else:
44430
5cd28f010fc7 Patch #1696. Don't attempt to close None in dry-run mode.
Guido van Rossum <guido@python.org>
parents: 43350
diff changeset
113 if f:
5cd28f010fc7 Patch #1696. Don't attempt to close None in dry-run mode.
Guido van Rossum <guido@python.org>
parents: 43350
diff changeset
114 f.close()
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
115 self.copy_file(script, outfile)
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
116
27355
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
117 if os.name == 'posix':
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
118 for file in outfiles:
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
119 if self.dry_run:
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
120 log.info("changing mode of %s", file)
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
121 else:
27520
6786e86b8ff0 Only log a message and chmod() when the mode isn't already what we
Guido van Rossum <guido@python.org>
parents: 27355
diff changeset
122 oldmode = os.stat(file)[ST_MODE] & 07777
6786e86b8ff0 Only log a message and chmod() when the mode isn't already what we
Guido van Rossum <guido@python.org>
parents: 27355
diff changeset
123 newmode = (oldmode | 0555) & 07777
6786e86b8ff0 Only log a message and chmod() when the mode isn't already what we
Guido van Rossum <guido@python.org>
parents: 27355
diff changeset
124 if newmode != oldmode:
6786e86b8ff0 Only log a message and chmod() when the mode isn't already what we
Guido van Rossum <guido@python.org>
parents: 27355
diff changeset
125 log.info("changing mode of %s from %o to %o",
6786e86b8ff0 Only log a message and chmod() when the mode isn't already what we
Guido van Rossum <guido@python.org>
parents: 27355
diff changeset
126 file, oldmode, newmode)
6786e86b8ff0 Only log a message and chmod() when the mode isn't already what we
Guido van Rossum <guido@python.org>
parents: 27355
diff changeset
127 os.chmod(file, newmode)
27355
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
128
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
129 # copy_scripts ()
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
130
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
131 # class build_scripts