From c531faa4459f34ea989b2fec7f86e8c5537cb984 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 18 Jun 2017 19:35:58 +0300 Subject: [PATCH 1/3] bpo-30645: use an internal variable while iterating in imp.load_package() The imp.load_package() function is marked as deprecated, however, some packages (like virtualenv) seem to use it. The problem with that loop, is that if the .py file does not exist, you'll get a `__init__.py/__init__.pyc` file. When shipping only Python bytecodes, we don't want that. Signed-off-by: Alexandru Ardelean --- Lib/imp.py | 5 +++-- Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/imp.py b/Lib/imp.py index 781ff23d2521611..beeac70e4b466ef 100644 --- a/Lib/imp.py +++ b/Lib/imp.py @@ -203,8 +203,9 @@ def load_package(name, path): extensions = (machinery.SOURCE_SUFFIXES[:] + machinery.BYTECODE_SUFFIXES[:]) for extension in extensions: - path = os.path.join(path, '__init__'+extension) - if os.path.exists(path): + init_path = os.path.join(path, '__init__'+extension) + if os.path.exists(init_path): + path = init_path break else: raise ValueError('{!r} is not a package'.format(path)) diff --git a/Misc/ACKS b/Misc/ACKS index 4f98e980bd971fb..eaff17232c9a12d 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -57,6 +57,7 @@ Ankur Ankan Heidi Annexstad Ramchandra Apte Éric Araujo +Alexandru Ardelean Alicia Arlen Jeffrey Armstrong Jason Asbahr diff --git a/Misc/NEWS b/Misc/NEWS index 88b1e3e22f71187..859f9b1dac235b9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -400,6 +400,10 @@ Library - bpo-30508: Don't log exceptions if Task/Future "cancel()" method was called. +- bpo-30645: Fix path creation of __init__.pyc in imp.load_package(), + for cases when a package is only shipped with bytecodes. This bug + was not noticeable if the source-code of __init__.py was available. + - bpo-11822: The dis.dis() function now is able to disassemble nested code objects. From fd64610ec418f10c0091b6fce0de2fa3112ce3a6 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 23 Jun 2017 10:00:21 -0700 Subject: [PATCH 2/3] Tweak formatting --- Lib/imp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/imp.py b/Lib/imp.py index beeac70e4b466ef..866464b245b24c5 100644 --- a/Lib/imp.py +++ b/Lib/imp.py @@ -203,7 +203,7 @@ def load_package(name, path): extensions = (machinery.SOURCE_SUFFIXES[:] + machinery.BYTECODE_SUFFIXES[:]) for extension in extensions: - init_path = os.path.join(path, '__init__'+extension) + init_path = os.path.join(path, '__init__' + extension) if os.path.exists(init_path): path = init_path break From c74e28aacc21610c30ea4de0de87395590295d74 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 23 Jun 2017 10:02:34 -0700 Subject: [PATCH 3/3] Tweak news entry --- Misc/NEWS | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 859f9b1dac235b9..606905b00173563 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -400,9 +400,9 @@ Library - bpo-30508: Don't log exceptions if Task/Future "cancel()" method was called. -- bpo-30645: Fix path creation of __init__.pyc in imp.load_package(), - for cases when a package is only shipped with bytecodes. This bug - was not noticeable if the source-code of __init__.py was available. +- bpo-30645: Fix path calculation in `imp.load_package()`, fixing it for + cases when a package is only shipped with bytecodes. Patch by + Alexandru Ardelean. - bpo-11822: The dis.dis() function now is able to disassemble nested code objects.