Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/suff.py @ 73323:dad02a080bbc
Improve byte-compilation in packaging to be independent of -O or -B.
The code I fixed to comply with PEP 3147 still had one bug: When run
under python -O, some paths for pyc files would be pyo, because I called
imp.cache_from_source without explicit debug_override argument in some
places, and under -O that would return .pyo (this is well explained in
the imp docs). Now all code (util.byte_compile, build_py, install_lib)
can create .pyo files according to options given by users,
without interference from the calling Python’s own optimize mode.
On a related topic, I also removed the code that prevented byte
compilation under python -B. The rationale is that packaging gives
control over the creation of pyc files to the user with its own explicit
option, and the behavior should not be changed if the calling Python
happens to run with -B for whatever reason. I will argue that this is a
bug fix and ask to be allowed to backport this change to distutils.
Finally, I moved one nugget of information about the --compile and
--optimize options from the source into the doc. It clears up a
misunderstanding that I (and maybe other people) had.
| author | Éric Araujo <merwok@netwok.org> |
|---|---|
| date | Thu, 03 Nov 2011 05:08:28 +0100 |
| parents | 5ae390ac6c61 |
| children |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
47100
diff
changeset
|
1 #! /usr/bin/env python3 |
| 274 | 2 |
| 3 # suff | |
| 4 # | |
| 5 # show different suffixes amongst arguments | |
| 6 | |
| 7 import sys | |
| 8 | |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
9 |
| 274 | 10 def main(): |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
4573
diff
changeset
|
11 files = sys.argv[1:] |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
4573
diff
changeset
|
12 suffixes = {} |
|
29107
93c92f20b6bf
Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents:
15930
diff
changeset
|
13 for filename in files: |
|
93c92f20b6bf
Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents:
15930
diff
changeset
|
14 suff = getsuffix(filename) |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
15 suffixes.setdefault(suff, []).append(filename) |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
16 for suff, filenames in sorted(suffixes.items()): |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
17 print(repr(suff), len(filenames)) |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
18 |
| 274 | 19 |
|
29107
93c92f20b6bf
Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents:
15930
diff
changeset
|
20 def getsuffix(filename): |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
21 name, sep, suff = filename.rpartition('.') |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
22 return sep + suff if sep else '' |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
23 |
| 274 | 24 |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
25 if __name__ == '__main__': |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
31515
diff
changeset
|
26 main() |
