Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9255464

Browse files
committed
Branch merge
2 parents eaf139b + a29e4f6 commit 9255464

15 files changed

Lines changed: 79 additions & 33 deletions

Doc/distutils/apiref.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,9 +1204,9 @@ other utility module.
12041204
.. function:: byte_compile(py_files[, optimize=0, force=0, prefix=None, base_dir=None, verbose=1, dry_run=0, direct=None])
12051205

12061206
Byte-compile a collection of Python source files to either :file:`.pyc` or
1207-
:file:`.pyo` files in the same directory. *py_files* is a list of files to
1208-
compile; any files that don't end in :file:`.py` are silently skipped.
1209-
*optimize* must be one of the following:
1207+
:file:`.pyo` files in a :file:`__pycache__` subdirectory (see :pep:`3147`).
1208+
*py_files* is a list of files to compile; any files that don't end in
1209+
:file:`.py` are silently skipped. *optimize* must be one of the following:
12101210

12111211
* ``0`` - don't optimize (generate :file:`.pyc`)
12121212
* ``1`` - normal optimization (like ``python -O``)
@@ -1231,6 +1231,11 @@ other utility module.
12311231
is used by the script generated in indirect mode; unless you know what you're
12321232
doing, leave it set to ``None``.
12331233

1234+
.. versionchanged:: 3.2.3
1235+
Create ``.pyc`` or ``.pyo`` files with an :func:`import magic tag
1236+
<imp.get_tag>` in their name, in a :file:`__pycache__` subdirectory
1237+
instead of files without tag in the current directory.
1238+
12341239

12351240
.. function:: rfc822_escape(header)
12361241

Doc/library/gettext.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ are the methods of :class:`NullTranslations`:
263263

264264
.. method:: lngettext(singular, plural, n)
265265

266-
If a fallback has been set, forward :meth:`ngettext` to the fallback.
266+
If a fallback has been set, forward :meth:`lngettext` to the fallback.
267267
Otherwise, return the translated message. Overridden in derived classes.
268268

269269

@@ -644,8 +644,8 @@ implementations, and valuable experience to the creation of this module:
644644
.. [#] See the footnote for :func:`bindtextdomain` above.
645645
646646
.. [#] François Pinard has written a program called :program:`xpot` which does a
647-
similar job. It is available as part of his :program:`po-utils` package at http
648-
://po-utils.progiciels-bpi.ca/.
647+
similar job. It is available as part of his `po-utils package
648+
<http://po-utils.progiciels-bpi.ca/>`_.
649649
650650
.. [#] :program:`msgfmt.py` is binary compatible with GNU :program:`msgfmt` except that
651651
it provides a simpler, all-Python implementation. With this and

Doc/library/packaging.util.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ This module contains various helpers for the other modules.
121121
.. function:: byte_compile(py_files[, optimize=0, force=0, prefix=None, base_dir=None, verbose=1, dry_run=0, direct=None])
122122

123123
Byte-compile a collection of Python source files to either :file:`.pyc` or
124-
:file:`.pyo` files in the same directory. *py_files* is a list of files to
125-
compile; any files that don't end in :file:`.py` are silently skipped.
126-
*optimize* must be one of the following:
124+
:file:`.pyo` files in a :file:`__pycache__` subdirectory (see :pep:`3147`),
125+
or to the same directory when using the distutils2 backport on Python
126+
versions older than 3.2.
127+
128+
*py_files* is a list of files to compile; any files that don't end in
129+
:file:`.py` are silently skipped. *optimize* must be one of the following:
127130

128131
* ``0`` - don't optimize (generate :file:`.pyc`)
129132
* ``1`` - normal optimization (like ``python -O``)

Lib/distutils/sysconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def get_makefile_filename():
218218
"""Return full pathname of installed Makefile from the Python build."""
219219
if python_build:
220220
return os.path.join(os.path.dirname(sys.executable), "Makefile")
221-
lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
221+
lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
222222
config_file = 'config-{}{}'.format(get_python_version(), build_flags)
223223
return os.path.join(lib_dir, config_file, 'Makefile')
224224

Lib/distutils/tests/test_build_py.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import sys
55
import io
6+
import imp
67
import unittest
78

89
from distutils.command.build_py import build_py
@@ -57,13 +58,15 @@ def test_package_data(self):
5758
self.assertEqual(len(cmd.get_outputs()), 3)
5859
pkgdest = os.path.join(destination, "pkg")
5960
files = os.listdir(pkgdest)
61+
pycache_dir = os.path.join(pkgdest, "__pycache__")
6062
self.assertIn("__init__.py", files)
6163
self.assertIn("README.txt", files)
62-
# XXX even with -O, distutils writes pyc, not pyo; bug?
6364
if sys.dont_write_bytecode:
64-
self.assertNotIn("__init__.pyc", files)
65+
self.assertFalse(os.path.exists(pycache_dir))
6566
else:
66-
self.assertIn("__init__.pyc", files)
67+
# XXX even with -O, distutils writes pyc, not pyo; bug?
68+
pyc_files = os.listdir(pycache_dir)
69+
self.assertIn("__init__.%s.pyc" % imp.get_tag(), pyc_files)
6770

6871
def test_empty_package_dir(self):
6972
# See SF 1668596/1720897.

Lib/distutils/tests/test_config_cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def test_search_cpp(self):
4444
cmd = config(dist)
4545

4646
# simple pattern searches
47-
match = cmd.search_cpp(pattern='xxx', body='// xxx')
47+
match = cmd.search_cpp(pattern='xxx', body='/* xxx */')
4848
self.assertEqual(match, 0)
4949

50-
match = cmd.search_cpp(pattern='_configtest', body='// xxx')
50+
match = cmd.search_cpp(pattern='_configtest', body='/* xxx */')
5151
self.assertEqual(match, 1)
5252

5353
def test_finalize_options(self):

Lib/distutils/tests/test_install_lib.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for distutils.command.install_data."""
22
import sys
33
import os
4+
import imp
45
import unittest
56

67
from distutils.command.install_lib import install_lib
@@ -32,18 +33,20 @@ def test_finalize_options(self):
3233
cmd.finalize_options()
3334
self.assertEqual(cmd.optimize, 2)
3435

35-
@unittest.skipUnless(not sys.dont_write_bytecode,
36-
'byte-compile not supported')
36+
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
3737
def test_byte_compile(self):
3838
pkg_dir, dist = self.create_dist()
39+
os.chdir(pkg_dir)
3940
cmd = install_lib(dist)
4041
cmd.compile = cmd.optimize = 1
4142

4243
f = os.path.join(pkg_dir, 'foo.py')
4344
self.write_file(f, '# python file')
4445
cmd.byte_compile([f])
45-
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
46-
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
46+
pyc_file = imp.cache_from_source('foo.py')
47+
pyo_file = imp.cache_from_source('foo.py', debug_override=False)
48+
self.assertTrue(os.path.exists(pyc_file))
49+
self.assertTrue(os.path.exists(pyo_file))
4750

4851
def test_get_outputs(self):
4952
pkg_dir, dist = self.create_dist()

Lib/distutils/util.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
one of the other *util.py modules.
55
"""
66

7-
import sys, os, string, re
7+
import os
8+
import re
9+
import imp
10+
import sys
11+
import string
812
from distutils.errors import DistutilsPlatformError
913
from distutils.dep_util import newer
1014
from distutils.spawn import spawn
@@ -529,7 +533,10 @@ def byte_compile (py_files,
529533
# Terminology from the py_compile module:
530534
# cfile - byte-compiled file
531535
# dfile - purported source filename (same as 'file' by default)
532-
cfile = file + (__debug__ and "c" or "o")
536+
if optimize >= 0:
537+
cfile = imp.cache_from_source(file, debug_override=not optimize)
538+
else:
539+
cfile = imp.cache_from_source(file)
533540
dfile = file
534541
if prefix:
535542
if file[:len(prefix)] != prefix:

Lib/packaging/tests/test_command_build_py.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import sys
5+
import imp
56

67
from packaging.command.build_py import build_py
78
from packaging.dist import Distribution
@@ -58,13 +59,15 @@ def test_package_data(self):
5859
self.assertEqual(len(cmd.get_outputs()), 3)
5960
pkgdest = os.path.join(destination, "pkg")
6061
files = os.listdir(pkgdest)
62+
pycache_dir = os.path.join(pkgdest, "__pycache__")
6163
self.assertIn("__init__.py", files)
6264
self.assertIn("README.txt", files)
63-
# XXX even with -O, distutils writes pyc, not pyo; bug?
6465
if sys.dont_write_bytecode:
65-
self.assertNotIn("__init__.pyc", files)
66+
self.assertFalse(os.path.exists(pycache_dir))
6667
else:
67-
self.assertIn("__init__.pyc", files)
68+
# XXX even with -O, packaging writes pyc, not pyo; bug?
69+
pyc_files = os.listdir(pycache_dir)
70+
self.assertIn("__init__.%s.pyc" % imp.get_tag(), pyc_files)
6871

6972
def test_empty_package_dir(self):
7073
# See SF 1668596/1720897.

Lib/packaging/tests/test_command_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def test_search_cpp(self):
2929
cmd = config(dist)
3030

3131
# simple pattern searches
32-
match = cmd.search_cpp(pattern='xxx', body='// xxx')
32+
match = cmd.search_cpp(pattern='xxx', body='/* xxx */')
3333
self.assertEqual(match, 0)
3434

35-
match = cmd.search_cpp(pattern='_configtest', body='// xxx')
35+
match = cmd.search_cpp(pattern='_configtest', body='/* xxx */')
3636
self.assertEqual(match, 1)
3737

3838
def test_finalize_options(self):

0 commit comments

Comments
 (0)