From 8c582d87912270afa37371bbb202ae98dc1d375c Mon Sep 17 00:00:00 2001 From: haixin Date: Thu, 26 Mar 2020 16:45:29 +0800 Subject: [PATCH] If only .pyc exist, the extension API will be disabled In some commercial production environments, generally will not expose the source code, this means that only .pyc files exist in the environment.In this case, the extension API cannot be loaded. Closes-Bug:#1869148 Change-Id: Id5238e7efe5ff0b80197ac0afa9f5f7a73239f20 --- manila/api/extensions.py | 10 +++++++--- ...xtension-API-cannot-be-loaded-172cb9153ebd4b56.yaml | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/bug-1869148-if-only-pyc-exist-the-extension-API-cannot-be-loaded-172cb9153ebd4b56.yaml diff --git a/manila/api/extensions.py b/manila/api/extensions.py index cbb3f79cc9..bea35bec94 100644 --- a/manila/api/extensions.py +++ b/manila/api/extensions.py @@ -273,12 +273,16 @@ def load_standard_extensions(ext_mgr, logger, path, package, ext_list=None): else: relpkg = '.%s' % '.'.join(relpath.split(os.sep)) - # Now, consider each file in turn, only considering .py files + # Now, consider each file in turn, only considering .py and .pyc files for fname in filenames: root, ext = os.path.splitext(fname) - # Skip __init__ and anything that's not .py - if ext != '.py' or root == '__init__': + # Skip __init__ and anything that's not .py and .pyc + if (ext not in ('.py', '.pyc')) or root == '__init__': + continue + + # If .pyc and .py both exist, skip .pyc + if ext == '.pyc' and ((root + '.py') in filenames): continue # Try loading it diff --git a/releasenotes/notes/bug-1869148-if-only-pyc-exist-the-extension-API-cannot-be-loaded-172cb9153ebd4b56.yaml b/releasenotes/notes/bug-1869148-if-only-pyc-exist-the-extension-API-cannot-be-loaded-172cb9153ebd4b56.yaml new file mode 100644 index 0000000000..352a4fac00 --- /dev/null +++ b/releasenotes/notes/bug-1869148-if-only-pyc-exist-the-extension-API-cannot-be-loaded-172cb9153ebd4b56.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + `Launchpad bug 1869148 `_ has been + fixed. This bug could have affected environments where extension APIs were + provided in compiled files rather than source code. +