Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/util.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 147ad02875fa |
| children | 502b139b3b19 cfbe51e66749 |
| rev | line source |
|---|---|
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
1 """distutils.util |
|
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
2 |
|
12226
ffd242fed0e2
Reorganization: ripped util.py to shreds, creating in the process:
Greg Ward <gward@python.net>
parents:
12170
diff
changeset
|
3 Miscellaneous utility functions -- anything that doesn't fit into |
| 14950 | 4 one of the other *util.py modules. |
| 5 """ | |
|
10435
324450ea5450
First checkin of real Distutils code.
Greg Ward <gward@python.net>
parents:
diff
changeset
|
6 |
|
72818
27a36b05caed
Fix distutils byte-compilation to comply with PEP 3147 (#11254).
Éric Araujo <merwok@netwok.org>
parents:
71540
diff
changeset
|
7 import os |
|
27a36b05caed
Fix distutils byte-compilation to comply with PEP 3147 (#11254).
Éric Araujo <merwok@netwok.org>
parents:
71540
diff
changeset
|
8 import re |
|
27a36b05caed
Fix distutils byte-compilation to comply with PEP 3147 (#11254).
Éric Araujo <merwok@netwok.org>
parents:
71540
diff
changeset
|
9 import imp |
|
27a36b05caed
Fix distutils byte-compilation to comply with PEP 3147 (#11254).
Éric Araujo <merwok@netwok.org>
parents:
71540
diff
changeset
|
10 import sys |
|
27a36b05caed
Fix distutils byte-compilation to comply with PEP 3147 (#11254).
Éric Araujo <merwok@netwok.org>
parents:
71540
diff
changeset
|
11 import string |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
12 from distutils.errors import DistutilsPlatformError |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
13 from distutils.dep_util import newer |
|
12102
e81b139ab8a4
Added 'make_tarball()' and 'make_zipfile()' functions in preparation
Greg Ward <gward@python.net>
parents:
12044
diff
changeset
|
14 from distutils.spawn import spawn |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
15 from distutils import log |
|
56741
a3cb812d80f9
Merged revisions 75704 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55975
diff
changeset
|
16 from distutils.errors import DistutilsByteCompileError |
|
12453
d0f290b3c0b2
Merged in Python 1.5.1 compatibility changes from the 0.1.3 branch:
Greg Ward <gward@python.net>
parents:
12407
diff
changeset
|
17 |
|
11887
81f1069e1558
Added 'get_platform()' to construct a string that identifies the current
Greg Ward <gward@python.net>
parents:
11684
diff
changeset
|
18 def get_platform (): |
|
14573
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
19 """Return a string that identifies the current platform. This is used |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
20 mainly to distinguish platform-specific build directories and |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
21 platform-specific built distributions. Typically includes the OS name |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
22 and version and the architecture (as supplied by 'os.uname()'), |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
23 although the exact information included depends on the OS; eg. for IRIX |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
24 the architecture isn't particularly important (IRIX only runs on SGI |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
25 hardware), but for Linux the kernel version isn't particularly |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
26 important. |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
27 |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
28 Examples of returned values: |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
29 linux-i586 |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
30 linux-alpha (?) |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
31 solaris-2.6-sun4u |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
32 irix-5.3 |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
33 irix64-6.2 |
| 21267 | 34 |
|
42775
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
35 Windows will return one of: |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44544
diff
changeset
|
36 win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc) |
|
42775
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
37 win-ia64 (64bit Windows on Itanium) |
|
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
38 win32 (all others - specifically, sys.platform is returned) |
|
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
39 |
|
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
40 For other non-POSIX platforms, currently just returns 'sys.platform'. |
|
12951
7f022e260a4d
'get_platform()' now just returns 'sys.platform' on all platforms.
Greg Ward <gward@python.net>
parents:
12935
diff
changeset
|
41 """ |
|
42775
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
42 if os.name == 'nt': |
|
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
43 # sniff sys.version for architecture. |
|
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
44 prefix = " bit (" |
|
43029
708033ed9515
Stop using the find function on the string module, use the string method.
Neal Norwitz <nnorwitz@gmail.com>
parents:
43026
diff
changeset
|
45 i = sys.version.find(prefix) |
|
42775
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
46 if i == -1: |
|
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
47 return sys.platform |
|
43029
708033ed9515
Stop using the find function on the string module, use the string method.
Neal Norwitz <nnorwitz@gmail.com>
parents:
43026
diff
changeset
|
48 j = sys.version.find(")", i) |
|
42775
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
49 look = sys.version[i+len(prefix):j].lower() |
|
43029
708033ed9515
Stop using the find function on the string module, use the string method.
Neal Norwitz <nnorwitz@gmail.com>
parents:
43026
diff
changeset
|
50 if look == 'amd64': |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44544
diff
changeset
|
51 return 'win-amd64' |
|
43029
708033ed9515
Stop using the find function on the string module, use the string method.
Neal Norwitz <nnorwitz@gmail.com>
parents:
43026
diff
changeset
|
52 if look == 'itanium': |
|
42775
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
53 return 'win-ia64' |
|
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
54 return sys.platform |
|
d7517c306791
Merged revisions 57221-57391 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41480
diff
changeset
|
55 |
|
14941
f9cf611096bf
In 'get_platform()', handle so-called POSIX systems that don't have
Greg Ward <gward@python.net>
parents:
14860
diff
changeset
|
56 if os.name != "posix" or not hasattr(os, 'uname'): |
|
14573
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
57 # XXX what about the architecture? NT is Intel or Alpha, |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
58 # Mac OS is M68k or PPC, etc. |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
59 return sys.platform |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
60 |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
61 # Try to distinguish various flavours of Unix |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
62 |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
63 (osname, host, release, version, machine) = os.uname() |
|
16801
2c9186e40b30
Bug #229280: remove '/' characters from the OS name (for BSD/OS :) )
Andrew M. Kuchling <amk@amk.ca>
parents:
16796
diff
changeset
|
64 |
|
27106
aee43a4f3570
Translate spaces in the machine name to underscores
Andrew M. Kuchling <amk@amk.ca>
parents:
26509
diff
changeset
|
65 # Convert the OS name to lowercase, remove '/' characters |
|
aee43a4f3570
Translate spaces in the machine name to underscores
Andrew M. Kuchling <amk@amk.ca>
parents:
26509
diff
changeset
|
66 # (to accommodate BSD/OS), and translate spaces (for "Power Macintosh") |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40587
diff
changeset
|
67 osname = osname.lower().replace('/', '') |
|
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40587
diff
changeset
|
68 machine = machine.replace(' ', '_') |
|
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40587
diff
changeset
|
69 machine = machine.replace('/', '-') |
| 21267 | 70 |
|
14573
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
71 if osname[:5] == "linux": |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
72 # At least on Linux/Intel, 'machine' is the processor -- |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
73 # i386, etc. |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
74 # XXX what about Alpha, SPARC, etc? |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
75 return "%s-%s" % (osname, machine) |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
76 elif osname[:5] == "sunos": |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
77 if release[0] >= "5": # SunOS 5 == Solaris 2 |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
78 osname = "solaris" |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
79 release = "%d.%s" % (int(release[0]) - 3, release[2:]) |
|
74483
9d62f5aa35ff
Emergency fix for #13803 bootstrap issue: Under Solaris, distutils doesn't include bitness in the directory name
Jesus Cea <jcea@jcea.es>
parents:
74480
diff
changeset
|
80 # We can't use "platform.architecture()[0]" because a |
|
9d62f5aa35ff
Emergency fix for #13803 bootstrap issue: Under Solaris, distutils doesn't include bitness in the directory name
Jesus Cea <jcea@jcea.es>
parents:
74480
diff
changeset
|
81 # bootstrap problem. We use a dict to get an error |
|
9d62f5aa35ff
Emergency fix for #13803 bootstrap issue: Under Solaris, distutils doesn't include bitness in the directory name
Jesus Cea <jcea@jcea.es>
parents:
74480
diff
changeset
|
82 # if some suspicious happens. |
|
9d62f5aa35ff
Emergency fix for #13803 bootstrap issue: Under Solaris, distutils doesn't include bitness in the directory name
Jesus Cea <jcea@jcea.es>
parents:
74480
diff
changeset
|
83 bitness = {2147483647:"32bit", 9223372036854775807:"64bit"} |
|
74491
147ad02875fa
And yet another emergency fix for #13803 bootstrap issue: Under Solaris, distutils doesn't include bitness in the directory name
Jesus Cea <jcea@jcea.es>
parents:
74483
diff
changeset
|
84 machine += ".%s" % bitness[sys.maxsize] |
|
14573
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
85 # fall through to standard osname-release-machine representation |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
86 elif osname[:4] == "irix": # could be "irix64"! |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
87 return "%s-%s" % (osname, release) |
| 21267 | 88 elif osname[:3] == "aix": |
|
16796
ac180c982295
Patch #404275: generate a reasonable platform string for AIX
Andrew M. Kuchling <amk@amk.ca>
parents:
16321
diff
changeset
|
89 return "%s-%s.%s" % (osname, version, release) |
|
16035
1144afb94019
Patch #103220 from Jason Tishler:
Andrew M. Kuchling <amk@amk.ca>
parents:
15217
diff
changeset
|
90 elif osname[:6] == "cygwin": |
|
18782
98484ef225f9
Patch #429442 from Jason Tishler: Corrects sys.platform and
Andrew M. Kuchling <amk@amk.ca>
parents:
17206
diff
changeset
|
91 osname = "cygwin" |
|
48769
83b2d07b475b
#2834: Change re module semantics, so that str and bytes mixing is forbidden,
Antoine Pitrou <solipsis@pitrou.net>
parents:
48485
diff
changeset
|
92 rel_re = re.compile (r'[\d.]+', re.ASCII) |
|
16035
1144afb94019
Patch #103220 from Jason Tishler:
Andrew M. Kuchling <amk@amk.ca>
parents:
15217
diff
changeset
|
93 m = rel_re.match(release) |
|
1144afb94019
Patch #103220 from Jason Tishler:
Andrew M. Kuchling <amk@amk.ca>
parents:
15217
diff
changeset
|
94 if m: |
|
1144afb94019
Patch #103220 from Jason Tishler:
Andrew M. Kuchling <amk@amk.ca>
parents:
15217
diff
changeset
|
95 release = m.group() |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
96 elif osname[:6] == "darwin": |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
97 # |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
98 # For our purposes, we'll assume that the system version from |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
99 # distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
100 # to. This makes the compatibility story a bit more sane because the |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
101 # machine is going to compile and link as if it were |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
102 # MACOSX_DEPLOYMENT_TARGET. |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
103 from distutils.sysconfig import get_config_vars |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
104 cfgvars = get_config_vars() |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
105 |
|
70144
5b108229a978
Issue #9516: avoid errors in sysconfig when MACOSX_DEPLOYMENT_TARGET is set in shell.
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
68257
diff
changeset
|
106 macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET') |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
107 |
|
50380
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
108 if 1: |
|
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
109 # Always calculate the release of the running machine, |
|
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
110 # needed to determine if we can build fat binaries or not. |
|
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
111 |
|
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
112 macrelease = macver |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
113 # Get the system version. Reading this plist is a documented |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
114 # way to get the system version (see the documentation for |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
115 # the Gestalt Manager) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
116 try: |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
117 f = open('/System/Library/CoreServices/SystemVersion.plist') |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
118 except IOError: |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
119 # We're on a plain darwin box, fall back to the default |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
120 # behaviour. |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
121 pass |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
122 else: |
|
66007
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
62954
diff
changeset
|
123 try: |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
62954
diff
changeset
|
124 m = re.search( |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
62954
diff
changeset
|
125 r'<key>ProductUserVisibleVersion</key>\s*' + |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
62954
diff
changeset
|
126 r'<string>(.*?)</string>', f.read()) |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
62954
diff
changeset
|
127 if m is not None: |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
62954
diff
changeset
|
128 macrelease = '.'.join(m.group(1).split('.')[:2]) |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
62954
diff
changeset
|
129 # else: fall back to the default behaviour |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
62954
diff
changeset
|
130 finally: |
|
f5dd4a54d79b
Merged revisions 86223-86224,86226,86234 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents:
62954
diff
changeset
|
131 f.close() |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
132 |
|
50380
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
133 if not macver: |
|
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
134 macver = macrelease |
|
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
135 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
136 if macver: |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
137 from distutils.sysconfig import get_config_vars |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
138 release = macver |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
139 osname = "macosx" |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
140 |
|
50380
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
141 if (macrelease + '.') >= '10.4.' and \ |
|
48485
bd4841069c68
Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46370
diff
changeset
|
142 '-arch' in get_config_vars().get('CFLAGS', '').strip(): |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
143 # The universal build will build fat binaries, but not on |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
144 # systems before 10.4 |
|
48485
bd4841069c68
Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46370
diff
changeset
|
145 # |
|
bd4841069c68
Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46370
diff
changeset
|
146 # Try to detect 4-way universal builds, those have machine-type |
|
bd4841069c68
Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46370
diff
changeset
|
147 # 'universal' instead of 'fat'. |
|
bd4841069c68
Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46370
diff
changeset
|
148 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
149 machine = 'fat' |
|
50380
c338bee21173
Merged revisions 68074-68075 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49911
diff
changeset
|
150 cflags = get_config_vars().get('CFLAGS') |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
151 |
|
55975
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
152 archs = re.findall('-arch\s+(\S+)', cflags) |
|
62954
edab501f9df8
Fix for issue 9164
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57911
diff
changeset
|
153 archs = tuple(sorted(set(archs))) |
|
55975
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
154 |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
155 if len(archs) == 1: |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
156 machine = archs[0] |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
157 elif archs == ('i386', 'ppc'): |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
158 machine = 'fat' |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
159 elif archs == ('i386', 'x86_64'): |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
160 machine = 'intel' |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
161 elif archs == ('i386', 'ppc', 'x86_64'): |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
162 machine = 'fat3' |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
163 elif archs == ('ppc64', 'x86_64'): |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
164 machine = 'fat64' |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
165 elif archs == ('i386', 'ppc', 'ppc64', 'x86_64'): |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
166 machine = 'universal' |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
167 else: |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
168 raise ValueError( |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
169 "Don't know machine value for archs=%r"%(archs,)) |
|
ab4a87fef1ae
Merged revisions 74808 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
52501
diff
changeset
|
170 |
|
57911
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
171 elif machine == 'i386': |
|
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
172 # On OSX the machine type returned by uname is always the |
|
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
173 # 32-bit variant, even if the executable architecture is |
|
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
174 # the 64-bit variant |
|
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
175 if sys.maxsize >= 2**32: |
|
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
176 machine = 'x86_64' |
|
48485
bd4841069c68
Merged revisions 63955 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46370
diff
changeset
|
177 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
178 elif machine in ('PowerPC', 'Power_Macintosh'): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
179 # Pick a sane name for the PPC architecture. |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37048
diff
changeset
|
180 machine = 'ppc' |
| 21267 | 181 |
|
57911
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
182 # See 'i386' case |
|
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
183 if sys.maxsize >= 2**32: |
|
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
184 machine = 'ppc64' |
|
71e6a0dfafc8
Merged revisions 77028 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
57588
diff
changeset
|
185 |
|
14573
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
186 return "%s-%s-%s" % (osname, release, machine) |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
187 |
|
857376d699bb
Revamped 'get_platform()' to try and do something reasonably smart on
Greg Ward <gward@python.net>
parents:
13891
diff
changeset
|
188 # get_platform () |
|
11934
7bd97c3dd432
Added 'native_path()' for use on pathnames from the setup script: split on
Greg Ward <gward@python.net>
parents:
11916
diff
changeset
|
189 |
|
7bd97c3dd432
Added 'native_path()' for use on pathnames from the setup script: split on
Greg Ward <gward@python.net>
parents:
11916
diff
changeset
|
190 |
|
12804
3be92cef1917
Renamed 'native_path()' to 'convert_path()'.
Greg Ward <gward@python.net>
parents:
12802
diff
changeset
|
191 def convert_path (pathname): |
| 14949 | 192 """Return 'pathname' as a name that will work on the native filesystem, |
| 193 i.e. split it on '/' and put it back together again using the current | |
| 194 directory separator. Needed because filenames in the setup script are | |
| 195 always supplied in Unix style, and have to be converted to the local | |
| 196 convention before we can actually use them in the filesystem. Raises | |
| 14950 | 197 ValueError on non-Unix-ish systems if 'pathname' either starts or |
| 198 ends with a slash. | |
| 14949 | 199 """ |
|
14743
8db096b782f9
Fix 'convert_path()' so it returns immediately under Unix -- prevents blowing
Greg Ward <gward@python.net>
parents:
14709
diff
changeset
|
200 if os.sep == '/': |
|
8db096b782f9
Fix 'convert_path()' so it returns immediately under Unix -- prevents blowing
Greg Ward <gward@python.net>
parents:
14709
diff
changeset
|
201 return pathname |
|
24786
f0d63aa1dfc7
SF bug #574235, convert_path fails with empty pathname
Neal Norwitz <nnorwitz@gmail.com>
parents:
24710
diff
changeset
|
202 if not pathname: |
|
f0d63aa1dfc7
SF bug #574235, convert_path fails with empty pathname
Neal Norwitz <nnorwitz@gmail.com>
parents:
24710
diff
changeset
|
203 return pathname |
|
f0d63aa1dfc7
SF bug #574235, convert_path fails with empty pathname
Neal Norwitz <nnorwitz@gmail.com>
parents:
24710
diff
changeset
|
204 if pathname[0] == '/': |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42775
diff
changeset
|
205 raise ValueError("path '%s' cannot be absolute" % pathname) |
|
24786
f0d63aa1dfc7
SF bug #574235, convert_path fails with empty pathname
Neal Norwitz <nnorwitz@gmail.com>
parents:
24710
diff
changeset
|
206 if pathname[-1] == '/': |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42775
diff
changeset
|
207 raise ValueError("path '%s' cannot end with '/'" % pathname) |
|
14743
8db096b782f9
Fix 'convert_path()' so it returns immediately under Unix -- prevents blowing
Greg Ward <gward@python.net>
parents:
14709
diff
changeset
|
208 |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40587
diff
changeset
|
209 paths = pathname.split('/') |
|
16321
a58c993d9234
Remove single "." components from pathnames, and return os.curdir if
Jack Jansen <jack.jansen@cwi.nl>
parents:
16261
diff
changeset
|
210 while '.' in paths: |
|
a58c993d9234
Remove single "." components from pathnames, and return os.curdir if
Jack Jansen <jack.jansen@cwi.nl>
parents:
16261
diff
changeset
|
211 paths.remove('.') |
|
a58c993d9234
Remove single "." components from pathnames, and return os.curdir if
Jack Jansen <jack.jansen@cwi.nl>
parents:
16261
diff
changeset
|
212 if not paths: |
|
a58c993d9234
Remove single "." components from pathnames, and return os.curdir if
Jack Jansen <jack.jansen@cwi.nl>
parents:
16261
diff
changeset
|
213 return os.curdir |
| 37048 | 214 return os.path.join(*paths) |
|
11934
7bd97c3dd432
Added 'native_path()' for use on pathnames from the setup script: split on
Greg Ward <gward@python.net>
parents:
11916
diff
changeset
|
215 |
|
12804
3be92cef1917
Renamed 'native_path()' to 'convert_path()'.
Greg Ward <gward@python.net>
parents:
12802
diff
changeset
|
216 # convert_path () |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
217 |
|
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
218 |
|
12507
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
219 def change_root (new_root, pathname): |
|
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
220 """Return 'pathname' with 'new_root' prepended. If 'pathname' is |
|
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
221 relative, this is equivalent to "os.path.join(new_root,pathname)". |
|
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
222 Otherwise, it requires making 'pathname' relative and then joining the |
|
12802
33ddc12df267
Fixed 'change_root() to work at all on Windows, and to work correctly on Unix.
Greg Ward <gward@python.net>
parents:
12672
diff
changeset
|
223 two, which is tricky on DOS/Windows and Mac OS. |
|
33ddc12df267
Fixed 'change_root() to work at all on Windows, and to work correctly on Unix.
Greg Ward <gward@python.net>
parents:
12672
diff
changeset
|
224 """ |
|
33ddc12df267
Fixed 'change_root() to work at all on Windows, and to work correctly on Unix.
Greg Ward <gward@python.net>
parents:
12672
diff
changeset
|
225 if os.name == 'posix': |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
226 if not os.path.isabs(pathname): |
|
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
227 return os.path.join(new_root, pathname) |
|
12802
33ddc12df267
Fixed 'change_root() to work at all on Windows, and to work correctly on Unix.
Greg Ward <gward@python.net>
parents:
12672
diff
changeset
|
228 else: |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
229 return os.path.join(new_root, pathname[1:]) |
|
12507
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
230 |
|
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
231 elif os.name == 'nt': |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
232 (drive, path) = os.path.splitdrive(pathname) |
|
12802
33ddc12df267
Fixed 'change_root() to work at all on Windows, and to work correctly on Unix.
Greg Ward <gward@python.net>
parents:
12672
diff
changeset
|
233 if path[0] == '\\': |
|
33ddc12df267
Fixed 'change_root() to work at all on Windows, and to work correctly on Unix.
Greg Ward <gward@python.net>
parents:
12672
diff
changeset
|
234 path = path[1:] |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
235 return os.path.join(new_root, path) |
|
12507
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
236 |
|
21851
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
237 elif os.name == 'os2': |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
238 (drive, path) = os.path.splitdrive(pathname) |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
239 if path[0] == os.sep: |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
240 path = path[1:] |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
241 return os.path.join(new_root, path) |
|
e0fc286d57a4
OS/2 patches by Andrew I MacIntyre for distutils.
Marc-André Lemburg <mal@egenix.com>
parents:
21267
diff
changeset
|
242 |
|
12507
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
243 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42775
diff
changeset
|
244 raise DistutilsPlatformError("nothing known about platform '%s'" % os.name) |
|
12507
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
245 |
|
5661f4f9a47f
Added 'change_root()' to forcibly slap a new root directory onto a pathname,
Greg Ward <gward@python.net>
parents:
12482
diff
changeset
|
246 |
|
12672
47bdb636159c
Made 'check_environ()' "public" by stripping the leading underscore;
Gregory P. Smith <greg@mad-scientist.com>
parents:
12507
diff
changeset
|
247 _environ_checked = 0 |
|
47bdb636159c
Made 'check_environ()' "public" by stripping the leading underscore;
Gregory P. Smith <greg@mad-scientist.com>
parents:
12507
diff
changeset
|
248 def check_environ (): |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
249 """Ensure that 'os.environ' has all the environment variables we |
| 14949 | 250 guarantee that users can use in config files, command-line options, |
| 251 etc. Currently this includes: | |
| 252 HOME - user's home directory (Unix only) | |
| 253 PLAT - description of the current platform, including hardware | |
| 254 and OS (see 'get_platform()') | |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
255 """ |
|
12672
47bdb636159c
Made 'check_environ()' "public" by stripping the leading underscore;
Gregory P. Smith <greg@mad-scientist.com>
parents:
12507
diff
changeset
|
256 global _environ_checked |
|
47bdb636159c
Made 'check_environ()' "public" by stripping the leading underscore;
Gregory P. Smith <greg@mad-scientist.com>
parents:
12507
diff
changeset
|
257 if _environ_checked: |
|
47bdb636159c
Made 'check_environ()' "public" by stripping the leading underscore;
Gregory P. Smith <greg@mad-scientist.com>
parents:
12507
diff
changeset
|
258 return |
|
47bdb636159c
Made 'check_environ()' "public" by stripping the leading underscore;
Gregory P. Smith <greg@mad-scientist.com>
parents:
12507
diff
changeset
|
259 |
|
39575
63237fcefd99
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
260 if os.name == 'posix' and 'HOME' not in os.environ: |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
261 import pwd |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
262 os.environ['HOME'] = pwd.getpwuid(os.getuid())[5] |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
263 |
|
39575
63237fcefd99
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
264 if 'PLAT' not in os.environ: |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
265 os.environ['PLAT'] = get_platform() |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
266 |
|
12672
47bdb636159c
Made 'check_environ()' "public" by stripping the leading underscore;
Gregory P. Smith <greg@mad-scientist.com>
parents:
12507
diff
changeset
|
267 _environ_checked = 1 |
|
47bdb636159c
Made 'check_environ()' "public" by stripping the leading underscore;
Gregory P. Smith <greg@mad-scientist.com>
parents:
12507
diff
changeset
|
268 |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
269 |
|
16261
bdfc6f1fa475
In subst_vars(), change the name of the argument from str to s to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16035
diff
changeset
|
270 def subst_vars (s, local_vars): |
| 14949 | 271 """Perform shell/Perl-style variable substitution on 'string'. Every |
| 14950 | 272 occurrence of '$' followed by a name is considered a variable, and |
| 273 variable is substituted by the value found in the 'local_vars' | |
| 274 dictionary, or in 'os.environ' if it's not in 'local_vars'. | |
| 275 'os.environ' is first checked/augmented to guarantee that it contains | |
| 276 certain values: see 'check_environ()'. Raise ValueError for any | |
| 277 variables not found in either 'local_vars' or 'os.environ'. | |
| 14949 | 278 """ |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
279 check_environ() |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
280 def _subst (match, local_vars=local_vars): |
|
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
281 var_name = match.group(1) |
|
39575
63237fcefd99
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
282 if var_name in local_vars: |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
283 return str(local_vars[var_name]) |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
284 else: |
|
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
285 return os.environ[var_name] |
|
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
286 |
| 14950 | 287 try: |
|
16261
bdfc6f1fa475
In subst_vars(), change the name of the argument from str to s to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16035
diff
changeset
|
288 return re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
39575
diff
changeset
|
289 except KeyError as var: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42775
diff
changeset
|
290 raise ValueError("invalid variable '$%s'" % var) |
|
12033
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
291 |
|
856dadf56cd9
Improved an error message in 'mkpath()'.
Greg Ward <gward@python.net>
parents:
12019
diff
changeset
|
292 # subst_vars () |
|
12102
e81b139ab8a4
Added 'make_tarball()' and 'make_zipfile()' functions in preparation
Greg Ward <gward@python.net>
parents:
12044
diff
changeset
|
293 |
|
e81b139ab8a4
Added 'make_tarball()' and 'make_zipfile()' functions in preparation
Greg Ward <gward@python.net>
parents:
12044
diff
changeset
|
294 |
|
12935
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
295 def grok_environment_error (exc, prefix="error: "): |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
296 """Generate a useful error message from an EnvironmentError (IOError or |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
297 OSError) exception object. Handles Python 1.5.1 and 1.5.2 styles, and |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
298 does what it can to deal with exception objects that don't have a |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
299 filename (which happens when the error is due to a two-file operation, |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
300 such as 'rename()' or 'link()'. Returns the error message as a string |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
301 prefixed with 'prefix'. |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
302 """ |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
303 # check for Python 1.5.2-style {IO,OS}Error exception objects |
|
14860
18b3def6c4b8
Standardize whitespace in function calls.
Greg Ward <gward@python.net>
parents:
14828
diff
changeset
|
304 if hasattr(exc, 'filename') and hasattr(exc, 'strerror'): |
|
12935
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
305 if exc.filename: |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
306 error = prefix + "%s: %s" % (exc.filename, exc.strerror) |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
307 else: |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
308 # two-argument functions in posix module don't |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
309 # include the filename in the exception object! |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
310 error = prefix + "%s" % exc.strerror |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
311 else: |
|
44544
b8e34bcdba45
Missed one because of indirection.
Georg Brandl <georg@python.org>
parents:
43029
diff
changeset
|
312 error = prefix + str(exc.args[-1]) |
|
12935
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
313 |
|
a98009a4391e
Added 'grok_environment_error()' function to deal with the various
Greg Ward <gward@python.net>
parents:
12804
diff
changeset
|
314 return error |
|
13006
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
315 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
316 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
317 # Needed by 'split_quoted()' |
|
31806
078032444ecc
Defer compilation of regular expressions until first use.
Martin v. Löwis <martin@v.loewis.de>
parents:
31515
diff
changeset
|
318 _wordchars_re = _squote_re = _dquote_re = None |
|
078032444ecc
Defer compilation of regular expressions until first use.
Martin v. Löwis <martin@v.loewis.de>
parents:
31515
diff
changeset
|
319 def _init_regex(): |
|
078032444ecc
Defer compilation of regular expressions until first use.
Martin v. Löwis <martin@v.loewis.de>
parents:
31515
diff
changeset
|
320 global _wordchars_re, _squote_re, _dquote_re |
|
078032444ecc
Defer compilation of regular expressions until first use.
Martin v. Löwis <martin@v.loewis.de>
parents:
31515
diff
changeset
|
321 _wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace) |
|
078032444ecc
Defer compilation of regular expressions until first use.
Martin v. Löwis <martin@v.loewis.de>
parents:
31515
diff
changeset
|
322 _squote_re = re.compile(r"'(?:[^'\\]|\\.)*'") |
|
078032444ecc
Defer compilation of regular expressions until first use.
Martin v. Löwis <martin@v.loewis.de>
parents:
31515
diff
changeset
|
323 _dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"') |
|
13006
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
324 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
325 def split_quoted (s): |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
326 """Split a string up according to Unix shell-like rules for quotes and |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
327 backslashes. In short: words are delimited by spaces, as long as those |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
328 spaces are not escaped by a backslash, or inside a quoted string. |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
329 Single and double quotes are equivalent, and the quote characters can |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
330 be backslash-escaped. The backslash is stripped from any two-character |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
331 escape sequence, leaving only the escaped character. The quote |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
332 characters are stripped from any quoted string. Returns a list of |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
333 words. |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
334 """ |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
335 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
336 # This is a nice algorithm for splitting up a single string, since it |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
337 # doesn't require character-by-character examination. It was a little |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
338 # bit of a brain-bender to get it working right, though... |
|
31806
078032444ecc
Defer compilation of regular expressions until first use.
Martin v. Löwis <martin@v.loewis.de>
parents:
31515
diff
changeset
|
339 if _wordchars_re is None: _init_regex() |
|
13006
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
340 |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40587
diff
changeset
|
341 s = s.strip() |
|
13006
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
342 words = [] |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
343 pos = 0 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
344 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
345 while s: |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
346 m = _wordchars_re.match(s, pos) |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
347 end = m.end() |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
348 if end == len(s): |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
349 words.append(s[:end]) |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
350 break |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
351 |
|
13891
08feb538c837
Fix so 'split_quoted()' handles any whitespace delimiter (not just space).
Greg Ward <gward@python.net>
parents:
13870
diff
changeset
|
352 if s[end] in string.whitespace: # unescaped, unquoted whitespace: now |
|
13006
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
353 words.append(s[:end]) # we definitely have a word delimiter |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40587
diff
changeset
|
354 s = s[end:].lstrip() |
|
13006
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
355 pos = 0 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
356 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
357 elif s[end] == '\\': # preserve whatever is being escaped; |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
358 # will become part of the current word |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
359 s = s[:end] + s[end+1:] |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
360 pos = end+1 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
361 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
362 else: |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
363 if s[end] == "'": # slurp singly-quoted string |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
364 m = _squote_re.match(s, end) |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
365 elif s[end] == '"': # slurp doubly-quoted string |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
366 m = _dquote_re.match(s, end) |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
367 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42775
diff
changeset
|
368 raise RuntimeError("this can't happen (bad char '%c')" % s[end]) |
|
13006
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
369 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
370 if m is None: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42775
diff
changeset
|
371 raise ValueError("bad string (mismatched %s quotes?)" % s[end]) |
|
13006
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
372 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
373 (beg, end) = m.span() |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
374 s = s[:beg] + s[beg+1:end-1] + s[end:] |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
375 pos = m.end() - 2 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
376 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
377 if pos >= len(s): |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
378 words.append(s) |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
379 break |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
380 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
381 return words |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
382 |
|
87003842faec
Added 'split_quoted()' function to deal with strings that are quoted in
Greg Ward <gward@python.net>
parents:
12951
diff
changeset
|
383 # split_quoted () |
|
13807
ba8db96ea4d9
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Greg Ward <gward@python.net>
parents:
13801
diff
changeset
|
384 |
|
ba8db96ea4d9
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Greg Ward <gward@python.net>
parents:
13801
diff
changeset
|
385 |
|
ba8db96ea4d9
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Greg Ward <gward@python.net>
parents:
13801
diff
changeset
|
386 def execute (func, args, msg=None, verbose=0, dry_run=0): |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
387 """Perform some action that affects the outside world (eg. by |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
388 writing to the filesystem). Such actions are special because they |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
389 are disabled by the 'dry_run' flag. This method takes care of all |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
390 that bureaucracy for you; all you have to do is supply the |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
391 function to call and an argument tuple for it (to embody the |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
392 "external action" being performed), and an optional message to |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
393 print. |
|
13807
ba8db96ea4d9
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Greg Ward <gward@python.net>
parents:
13801
diff
changeset
|
394 """ |
|
ba8db96ea4d9
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Greg Ward <gward@python.net>
parents:
13801
diff
changeset
|
395 if msg is None: |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
27106
diff
changeset
|
396 msg = "%s%r" % (func.__name__, args) |
| 21267 | 397 if msg[-2:] == ',)': # correct for singleton tuple |
|
13807
ba8db96ea4d9
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Greg Ward <gward@python.net>
parents:
13801
diff
changeset
|
398 msg = msg[0:-2] + ')' |
|
ba8db96ea4d9
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Greg Ward <gward@python.net>
parents:
13801
diff
changeset
|
399 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
400 log.info(msg) |
|
13807
ba8db96ea4d9
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Greg Ward <gward@python.net>
parents:
13801
diff
changeset
|
401 if not dry_run: |
| 37048 | 402 func(*args) |
|
13807
ba8db96ea4d9
Added the 'execute()' function (moved here from cmd.py with minor tweakage).
Greg Ward <gward@python.net>
parents:
13801
diff
changeset
|
403 |
|
14828
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
404 |
|
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
405 def strtobool (val): |
|
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
406 """Convert a string representation of truth to true (1) or false (0). |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
31806
diff
changeset
|
407 |
|
14828
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
408 True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values |
|
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
409 are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if |
|
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
410 'val' is anything else. |
|
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
411 """ |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40587
diff
changeset
|
412 val = val.lower() |
|
14828
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
413 if val in ('y', 'yes', 't', 'true', 'on', '1'): |
|
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
414 return 1 |
|
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
415 elif val in ('n', 'no', 'f', 'false', 'off', '0'): |
|
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
416 return 0 |
|
9f96c92f03e3
Added 'strtobool()' function: convert strings like "yes", "1",
Greg Ward <gward@python.net>
parents:
14743
diff
changeset
|
417 else: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42775
diff
changeset
|
418 raise ValueError("invalid truth value %r" % (val,)) |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
419 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
420 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
421 def byte_compile (py_files, |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
422 optimize=0, force=0, |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
423 prefix=None, base_dir=None, |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
424 verbose=1, dry_run=0, |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
425 direct=None): |
|
14958
50386c73ba22
Tweaked 'byte_compile()' so it silently skips non-Python files, rather than
Greg Ward <gward@python.net>
parents:
14951
diff
changeset
|
426 """Byte-compile a collection of Python source files to either .pyc |
|
72823
651e84363001
Fix docstring of distutils.util.byte_compile (followup for #11254)
Éric Araujo <merwok@netwok.org>
parents:
72818
diff
changeset
|
427 or .pyo files in a __pycache__ subdirectory. 'py_files' is a list |
|
651e84363001
Fix docstring of distutils.util.byte_compile (followup for #11254)
Éric Araujo <merwok@netwok.org>
parents:
72818
diff
changeset
|
428 of files to compile; any files that don't end in ".py" are silently |
|
651e84363001
Fix docstring of distutils.util.byte_compile (followup for #11254)
Éric Araujo <merwok@netwok.org>
parents:
72818
diff
changeset
|
429 skipped. 'optimize' must be one of the following: |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
430 0 - don't optimize (generate .pyc) |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
431 1 - normal optimization (like "python -O") |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
432 2 - extra optimization (like "python -OO") |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
433 If 'force' is true, all files are recompiled regardless of |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
434 timestamps. |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
435 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
436 The source filename encoded in each bytecode file defaults to the |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
437 filenames listed in 'py_files'; you can modify these with 'prefix' and |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
438 'basedir'. 'prefix' is a string that will be stripped off of each |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
439 source filename, and 'base_dir' is a directory name that will be |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
440 prepended (after 'prefix' is stripped). You can supply either or both |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
441 (or neither) of 'prefix' and 'base_dir', as you wish. |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
442 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
443 If 'dry_run' is true, doesn't actually do anything that would |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
444 affect the filesystem. |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
445 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
446 Byte-compilation is either done directly in this interpreter process |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
447 with the standard py_compile module, or indirectly by writing a |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
448 temporary script and executing it. Normally, you should let |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
449 'byte_compile()' figure out to use direct compilation or not (see |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
450 the source for details). The 'direct' flag is used by the script |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
451 generated in indirect mode; unless you know what you're doing, leave |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
452 it set to None. |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
453 """ |
|
56741
a3cb812d80f9
Merged revisions 75704 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55975
diff
changeset
|
454 # nothing is done if sys.dont_write_bytecode is True |
|
a3cb812d80f9
Merged revisions 75704 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55975
diff
changeset
|
455 if sys.dont_write_bytecode: |
|
a3cb812d80f9
Merged revisions 75704 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
55975
diff
changeset
|
456 raise DistutilsByteCompileError('byte-compiling is disabled.') |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
457 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
458 # First, if the caller didn't force us into direct or indirect mode, |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
459 # figure out which mode we should be in. We take a conservative |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
460 # approach: choose direct mode *only* if the current interpreter is |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
461 # in debug mode and optimize is 0. If we're not in debug mode (-O |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
462 # or -OO), we don't know which level of optimization this |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
463 # interpreter is running with, so we can't do direct |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
464 # byte-compilation and be certain that it's the right thing. Thus, |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
465 # always compile indirectly if the current interpreter is in either |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
466 # optimize mode, or if either optimization level was requested by |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
467 # the caller. |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
468 if direct is None: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
469 direct = (__debug__ and optimize == 0) |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
470 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
471 # "Indirect" byte-compilation: write a temporary script and then |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
472 # run it with the appropriate flags. |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
473 if not direct: |
|
26509
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
474 try: |
|
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
475 from tempfile import mkstemp |
|
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
476 (script_fd, script_name) = mkstemp(".py") |
|
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
477 except ImportError: |
|
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
478 from tempfile import mktemp |
|
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
479 (script_fd, script_name) = None, mktemp(".py") |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
480 log.info("writing byte-compilation script '%s'", script_name) |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
481 if not dry_run: |
|
26509
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
482 if script_fd is not None: |
|
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
483 script = os.fdopen(script_fd, "w") |
|
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
484 else: |
|
9e4c80340fa1
Adding Python <= 2.2 support back in.
Marc-André Lemburg <mal@egenix.com>
parents:
26210
diff
changeset
|
485 script = open(script_name, "w") |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
486 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
487 script.write("""\ |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
488 from distutils.util import byte_compile |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
489 files = [ |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
490 """) |
|
14982
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
491 |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
492 # XXX would be nice to write absolute filenames, just for |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
493 # safety's sake (script should be more robust in the face of |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
494 # chdir'ing before running it). But this requires abspath'ing |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
495 # 'prefix' as well, and that breaks the hack in build_lib's |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
496 # 'byte_compile()' method that carefully tacks on a trailing |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
497 # slash (os.sep really) to make sure the prefix here is "just |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
498 # right". This whole prefix business is rather delicate -- the |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
499 # problem is that it's really a directory, but I'm treating it |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
500 # as a dumb string, so trailing slashes and so forth matter. |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
501 |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
502 #py_files = map(os.path.abspath, py_files) |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
503 #if prefix: |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
504 # prefix = os.path.abspath(prefix) |
|
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
505 |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40587
diff
changeset
|
506 script.write(",\n".join(map(repr, py_files)) + "]\n") |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
507 script.write(""" |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
27106
diff
changeset
|
508 byte_compile(files, optimize=%r, force=%r, |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
27106
diff
changeset
|
509 prefix=%r, base_dir=%r, |
|
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
27106
diff
changeset
|
510 verbose=%r, dry_run=0, |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
511 direct=1) |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
27106
diff
changeset
|
512 """ % (optimize, force, prefix, base_dir, verbose)) |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
513 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
514 script.close() |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
515 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
516 cmd = [sys.executable, script_name] |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
517 if optimize == 1: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
518 cmd.insert(1, "-O") |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
519 elif optimize == 2: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
520 cmd.insert(1, "-OO") |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
521 spawn(cmd, dry_run=dry_run) |
|
14982
0fa58fea30cf
Added a long-winded comment (and commented-out comment to go with out)
Greg Ward <gward@python.net>
parents:
14960
diff
changeset
|
522 execute(os.remove, (script_name,), "removing %s" % script_name, |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
523 dry_run=dry_run) |
| 21267 | 524 |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
525 # "Direct" byte-compilation: use the py_compile module to compile |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
526 # right here, right now. Note that the script generated in indirect |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
527 # mode simply calls 'byte_compile()' in direct mode, a weird sort of |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
528 # cross-process recursion. Hey, it works! |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
529 else: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
530 from py_compile import compile |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
531 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
532 for file in py_files: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
533 if file[-3:] != ".py": |
|
14958
50386c73ba22
Tweaked 'byte_compile()' so it silently skips non-Python files, rather than
Greg Ward <gward@python.net>
parents:
14951
diff
changeset
|
534 # This lets us be lazy and not filter filenames in |
|
50386c73ba22
Tweaked 'byte_compile()' so it silently skips non-Python files, rather than
Greg Ward <gward@python.net>
parents:
14951
diff
changeset
|
535 # the "install_lib" command. |
|
50386c73ba22
Tweaked 'byte_compile()' so it silently skips non-Python files, rather than
Greg Ward <gward@python.net>
parents:
14951
diff
changeset
|
536 continue |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
537 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
538 # Terminology from the py_compile module: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
539 # cfile - byte-compiled file |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
540 # dfile - purported source filename (same as 'file' by default) |
|
72818
27a36b05caed
Fix distutils byte-compilation to comply with PEP 3147 (#11254).
Éric Araujo <merwok@netwok.org>
parents:
71540
diff
changeset
|
541 if optimize >= 0: |
|
27a36b05caed
Fix distutils byte-compilation to comply with PEP 3147 (#11254).
Éric Araujo <merwok@netwok.org>
parents:
71540
diff
changeset
|
542 cfile = imp.cache_from_source(file, debug_override=not optimize) |
|
27a36b05caed
Fix distutils byte-compilation to comply with PEP 3147 (#11254).
Éric Araujo <merwok@netwok.org>
parents:
71540
diff
changeset
|
543 else: |
|
27a36b05caed
Fix distutils byte-compilation to comply with PEP 3147 (#11254).
Éric Araujo <merwok@netwok.org>
parents:
71540
diff
changeset
|
544 cfile = imp.cache_from_source(file) |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
545 dfile = file |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
546 if prefix: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
547 if file[:len(prefix)] != prefix: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
42775
diff
changeset
|
548 raise ValueError("invalid prefix: filename %r doesn't start with %r" |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
27106
diff
changeset
|
549 % (file, prefix)) |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
550 dfile = dfile[len(prefix):] |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
551 if base_dir: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
552 dfile = os.path.join(base_dir, dfile) |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
553 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
554 cfile_base = os.path.basename(cfile) |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
555 if direct: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
556 if force or newer(file, cfile): |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
557 log.info("byte-compiling %s to %s", file, cfile_base) |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
558 if not dry_run: |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
559 compile(file, cfile, dfile) |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
560 else: |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
561 log.debug("skipping byte-compilation of %s to %s", |
|
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23382
diff
changeset
|
562 file, cfile_base) |
|
14951
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
563 |
|
005a0b4c382d
Added 'byte_compile(): an all-singing, all-dancing wrapper around the
Greg Ward <gward@python.net>
parents:
14950
diff
changeset
|
564 # byte_compile () |
|
17126
1b8745faa2ed
Patch #407434: add rfc822_escape utility function
Andrew M. Kuchling <amk@amk.ca>
parents:
16801
diff
changeset
|
565 |
|
1b8745faa2ed
Patch #407434: add rfc822_escape utility function
Andrew M. Kuchling <amk@amk.ca>
parents:
16801
diff
changeset
|
566 def rfc822_escape (header): |
|
1b8745faa2ed
Patch #407434: add rfc822_escape utility function
Andrew M. Kuchling <amk@amk.ca>
parents:
16801
diff
changeset
|
567 """Return a version of the string escaped for inclusion in an |
|
17206
782239488058
Change rfc822_escape() to ensure there's a consistent amount of whitespace
Andrew M. Kuchling <amk@amk.ca>
parents:
17126
diff
changeset
|
568 RFC-822 header, by ensuring there are 8 spaces space after each newline. |
|
17126
1b8745faa2ed
Patch #407434: add rfc822_escape utility function
Andrew M. Kuchling <amk@amk.ca>
parents:
16801
diff
changeset
|
569 """ |
|
57588
568618b5f6fd
Merged revisions 76686 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
56741
diff
changeset
|
570 lines = header.split('\n') |
|
568618b5f6fd
Merged revisions 76686 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
56741
diff
changeset
|
571 sep = '\n' + 8 * ' ' |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40587
diff
changeset
|
572 return sep.join(lines) |
|
49911
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
573 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
574 # 2to3 support |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
575 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
576 def run_2to3(files, fixer_names=None, options=None, explicit=None): |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
577 """Invoke 2to3 on a list of Python files. |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
578 The files should all come from the build area, as the |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
579 modification is done in-place. To reduce the build time, |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
580 only files modified since the last invocation of this |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
581 function should be passed in the files argument.""" |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
582 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
583 if not files: |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
584 return |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
585 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
586 # Make this class local, to delay import of 2to3 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
587 from lib2to3.refactor import RefactoringTool, get_fixers_from_package |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
588 class DistutilsRefactoringTool(RefactoringTool): |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
589 def log_error(self, msg, *args, **kw): |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
590 log.error(msg, *args) |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
591 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
592 def log_message(self, msg, *args): |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
593 log.info(msg, *args) |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
594 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
595 def log_debug(self, msg, *args): |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
596 log.debug(msg, *args) |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
597 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
598 if fixer_names is None: |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
599 fixer_names = get_fixers_from_package('lib2to3.fixes') |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
600 r = DistutilsRefactoringTool(fixer_names, options=options) |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
601 r.refactor(files, write=True) |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
602 |
|
52501
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
603 def copydir_run_2to3(src, dest, template=None, fixer_names=None, |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
604 options=None, explicit=None): |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
605 """Recursively copy a directory, only copying new and changed files, |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
606 running run_2to3 over all newly copied Python modules afterward. |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
607 |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
608 If you give a template string, it's parsed like a MANIFEST.in. |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
609 """ |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
610 from distutils.dir_util import mkpath |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
611 from distutils.file_util import copy_file |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
612 from distutils.filelist import FileList |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
613 filelist = FileList() |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
614 curdir = os.getcwd() |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
615 os.chdir(src) |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
616 try: |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
617 filelist.findall() |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
618 finally: |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
619 os.chdir(curdir) |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
620 filelist.files[:] = filelist.allfiles |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
621 if template: |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
622 for line in template.splitlines(): |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
623 line = line.strip() |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
624 if not line: continue |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
625 filelist.process_template_line(line) |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
626 copied = [] |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
627 for filename in filelist.files: |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
628 outname = os.path.join(dest, filename) |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
629 mkpath(os.path.dirname(outname)) |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
630 res = copy_file(os.path.join(src, filename), outname, update=1) |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
631 if res[1]: copied.append(outname) |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
632 run_2to3([fn for fn in copied if fn.lower().endswith('.py')], |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
633 fixer_names=fixer_names, options=options, explicit=explicit) |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
634 return copied |
|
89dea3df4cb5
Add new copydir_run_2to3() function, for use e.g. in test runners to transparently convert and run tests written for Python 2.
Georg Brandl <georg@python.org>
parents:
50380
diff
changeset
|
635 |
|
49911
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
636 class Mixin2to3: |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
637 '''Mixin class for commands that run 2to3. |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
638 To configure 2to3, setup scripts may either change |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
639 the class variables, or inherit from individual commands |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
640 to override how 2to3 is invoked.''' |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
641 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
642 # provide list of fixers to run; |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
643 # defaults to all from lib2to3.fixers |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
644 fixer_names = None |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
645 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
646 # options dictionary |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
647 options = None |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
648 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
649 # list of fixers to invoke even though they are marked as explicit |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
650 explicit = None |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
651 |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
652 def run_2to3(self, files): |
|
60e775eaaaee
Issue #4073: Add 2to3 support to build_scripts, refactor that support
Martin v. Löwis <martin@v.loewis.de>
parents:
48769
diff
changeset
|
653 return run_2to3(files, self.fixer_names, self.options, self.explicit) |
