annotate Lib/distutils/command/build_scripts.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 7d69d04522e3
children
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
45471
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44441
diff changeset
5 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
6 from stat import ST_MODE
21330
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
7 from distutils import sysconfig
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
8 from distutils.core import Command
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
9 from distutils.dep_util import newer
49911
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
10 from distutils.util import convert_path, Mixin2to3
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22082
diff changeset
11 from distutils import log
70028
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
12 import tokenize
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
13
18831
132c4bfdba74 Undo revision 1.7: always mangle a #! line containing "python" to point
Greg Ward <gward@python.net>
parents: 16956
diff changeset
14 # check if Python is called on the first line with this expression
70028
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
15 first_line_re = re.compile(b'^#!.*python[0-9.]*([ \t].*)?$')
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
16
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
17 class build_scripts(Command):
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
18
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
19 description = "\"build\" scripts (copy and fixup #! line)"
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
20
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
21 user_options = [
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
22 ('build-dir=', 'd', "directory to \"build\" (copy) to"),
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
23 ('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
24 ('executable=', 'e', "specify final destination interpreter path"),
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
25 ]
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
26
14829
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
27 boolean_options = ['force']
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 13725
diff changeset
28
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
29
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
30 def initialize_options(self):
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
31 self.build_dir = None
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
32 self.scripts = None
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
33 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
34 self.executable = None
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
35 self.outfiles = None
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
36
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
37 def finalize_options(self):
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
38 self.set_undefined_options('build',
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
39 ('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
40 ('force', 'force'),
4e9ecbf47b6b Patch #736857, #736859: Add -e option to build_scripts.
Martin v. Löwis <martin@v.loewis.de>
parents: 32736
diff changeset
41 ('executable', 'executable'))
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
42 self.scripts = self.distribution.scripts
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
43
31852
2cfe14275a04 backport fix for SF bug #796042: sdist ignores scripts argument in setup
Fred Drake <fdrake@acm.org>
parents: 29621
diff changeset
44 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
45 return self.scripts
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
46
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
47 def run(self):
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
48 if not self.scripts:
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
49 return
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
50 self.copy_scripts()
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
51
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
52
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
53 def copy_scripts(self):
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
54 """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
55 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
56 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
57 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
58 """
12745
dad205d13bb5 Bastian Kleineidam: the "build_scripts" command.
Greg Ward <gward@python.net>
parents:
diff changeset
59 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
60 outfiles = []
49911
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
61 updated_files = []
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
62 for script in self.scripts:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
63 adjust = False
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:
70028
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
76 f = open(script, "rb")
81039
7d69d04522e3 Replace IOError with OSError (#16715)
Andrew Svetlov <andrew.svetlov@gmail.com>
parents: 71541
diff changeset
77 except OSError:
12748
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:
70028
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
82 encoding, lines = tokenize.detect_encoding(f.readline)
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
83 f.seek(0)
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
84 first_line = f.readline()
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
85 if not first_line:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
86 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
87 continue
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
88
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
89 match = first_line_re.match(first_line)
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
90 if match:
43026
a6d3930b5613 General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents: 42084
diff changeset
91 adjust = True
70028
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
92 post_interp = match.group(1) or b''
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
93
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
94 if adjust:
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 22082
diff changeset
95 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
96 self.build_dir)
49911
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
97 updated_files.append(outfile)
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
98 if not self.dry_run:
21330
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
99 if not sysconfig.python_build:
70028
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
100 executable = self.executable
21330
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
101 else:
70028
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
102 executable = os.path.join(
21330
4420a4bd96a4 Fix for
Michael W. Hudson <mwh@python.net>
parents: 21271
diff changeset
103 sysconfig.get_config_var("BINDIR"),
51619
616138eef224 Merged revisions 69600 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 49911
diff changeset
104 "python%s%s" % (sysconfig.get_config_var("VERSION"),
70028
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
105 sysconfig.get_config_var("EXE")))
70019
6ad356525381 Close #10419, issue #6011: build_scripts command of distutils handles correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63136
diff changeset
106 executable = os.fsencode(executable)
70028
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
107 shebang = b"#!" + executable + post_interp + b"\n"
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
108 # Python parser starts to read a script using UTF-8 until
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
109 # it gets a #coding:xxx cookie. The shebang has to be the
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
110 # first line of a file, the #coding:xxx cookie cannot be
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
111 # written before. So the shebang has to be decodable from
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
112 # UTF-8.
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
113 try:
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
114 shebang.decode('utf-8')
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
115 except UnicodeDecodeError:
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
116 raise ValueError(
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
117 "The shebang ({!r}) is not decodable "
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
118 "from utf-8".format(shebang))
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
119 # If the script is encoded to a custom encoding (use a
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
120 # #coding:xxx cookie), the shebang has to be decodable from
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
121 # the script encoding too.
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
122 try:
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
123 shebang.decode(encoding)
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
124 except UnicodeDecodeError:
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
125 raise ValueError(
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
126 "The shebang ({!r}) is not decodable "
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
127 "from the script encoding ({})"
fd7d4639dae2 Issue #10419: Fix build_scripts command of distutils to handle correctly
Victor Stinner <victor.stinner@haypocalc.com>
parents: 51619
diff changeset
128 .format(shebang, encoding))
70199
cc5cfeaa4a8d Issue #10419, issue #6011: port 6ad356525381 fix from distutils to packaging
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70029
diff changeset
129 with open(outfile, "wb") as outf:
cc5cfeaa4a8d Issue #10419, issue #6011: port 6ad356525381 fix from distutils to packaging
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70029
diff changeset
130 outf.write(shebang)
cc5cfeaa4a8d Issue #10419, issue #6011: port 6ad356525381 fix from distutils to packaging
Victor Stinner <victor.stinner@haypocalc.com>
parents: 70029
diff changeset
131 outf.writelines(f.readlines())
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
132 if f:
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
133 f.close()
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
134 else:
44441
b91ca87e6f32 Merged revisions 59666-59679 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43400
diff changeset
135 if f:
b91ca87e6f32 Merged revisions 59666-59679 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43400
diff changeset
136 f.close()
49911
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
137 updated_files.append(outfile)
12748
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
138 self.copy_file(script, outfile)
eb562df0cebe Improvements to Bastian's build_scripts command:
Greg Ward <gward@python.net>
parents: 12745
diff changeset
139
27355
dc6116278259 Change the mode of scripts in the build/scripts* directory to
Guido van Rossum <guido@python.org>
parents: 26285
diff changeset
140 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
141 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
142 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
143 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
144 else:
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 33965
diff changeset
145 oldmode = os.stat(file)[ST_MODE] & 0o7777
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 33965
diff changeset
146 newmode = (oldmode | 0o555) & 0o7777
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
147 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
148 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
149 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
150 os.chmod(file, newmode)
49911
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
151 # XXX should we modify self.outfiles?
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
152 return outfiles, updated_files
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
153
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
154 class build_scripts_2to3(build_scripts, Mixin2to3):
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
155
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
156 def copy_scripts(self):
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
157 outfiles, updated_files = build_scripts.copy_scripts(self)
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
158 if not self.dry_run:
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
159 self.run_2to3(updated_files)
60e775eaaaee Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents: 45471
diff changeset
160 return outfiles, updated_files