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

Skip to content

Commit 6ebea15

Browse files
committed
Merge fixes for #10526, #10359, #11254, #9100 and the bug without number
2 parents dd07732 + fea2d04 commit 6ebea15

10 files changed

Lines changed: 52 additions & 20 deletions

File tree

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

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/test/test_sysconfig.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import os
44
import subprocess
55
import shutil
6-
from copy import copy, deepcopy
6+
from copy import copy
77

8-
from test.support import (run_unittest, TESTFN, unlink, get_attribute,
8+
from test.support import (run_unittest, TESTFN, unlink,
99
captured_stdout, skip_unless_symlink)
1010

1111
import sysconfig
@@ -256,8 +256,15 @@ def test_user_similar(self):
256256
# is similar to the global posix_prefix one
257257
base = get_config_var('base')
258258
user = get_config_var('userbase')
259+
# the global scheme mirrors the distinction between prefix and
260+
# exec-prefix but not the user scheme, so we have to adapt the paths
261+
# before comparing (issue #9100)
262+
adapt = sys.prefix != sys.exec_prefix
259263
for name in ('stdlib', 'platstdlib', 'purelib', 'platlib'):
260264
global_path = get_path(name, 'posix_prefix')
265+
if adapt:
266+
global_path = global_path.replace(sys.exec_prefix, sys.prefix)
267+
base = base.replace(sys.exec_prefix, sys.prefix)
261268
user_path = get_path(name, 'posix_user')
262269
self.assertEqual(user_path, global_path.replace(base, user, 1))
263270

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ Brian Quinlan
772772
Anders Qvist
773773
Jérôme Radix
774774
Burton Radons
775+
Jeff Ramnani
775776
Brodie Rao
776777
Antti Rasinen
777778
Sridhar Ratnakumar

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ Core and Builtins
301301
Library
302302
-------
303303

304+
- Fix distutils.sysconfig.get_makefile_filename when Python was configured with
305+
different prefix and exec-prefix.
306+
307+
- Issue #11254: Teach distutils to compile .pyc and .pyo files in
308+
PEP 3147-compliant __pycache__ directories.
309+
304310
- Issue #7367: Fix pkgutil.walk_paths to skip directories whose
305311
contents cannot be read.
306312

0 commit comments

Comments
 (0)