diff --git a/ext/backports/__init__.py b/ext/backports/__init__.py deleted file mode 100644 index 3ad9513f40e..00000000000 --- a/ext/backports/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from pkgutil import extend_path -__path__ = extend_path(__path__, __name__) diff --git a/ext/configparser.pth b/ext/configparser.pth new file mode 100644 index 00000000000..781f5d2a637 --- /dev/null +++ b/ext/configparser.pth @@ -0,0 +1 @@ +import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('backports',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('backports', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('backports', [os.path.dirname(p)])));m = m or sys.modules.setdefault('backports', types.ModuleType('backports'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p) diff --git a/medusa/init/__init__.py b/medusa/init/__init__.py index 36f6dd50aa1..82773f16cd6 100644 --- a/medusa/init/__init__.py +++ b/medusa/init/__init__.py @@ -8,6 +8,7 @@ import mimetypes import os import shutil +import site import sys @@ -46,8 +47,20 @@ def _ext_lib_location(): def _configure_syspath(): - sys.path.insert(1, _lib_location()) - sys.path.insert(1, _ext_lib_location()) + # Note: Paths are inserted in reverse order (LIFO) + paths_to_insert = [ + _lib_location(), + _ext_lib_location() + ] + + # Handle `.pth` files: https://bugs.python.org/issue7744 + for dirpath in paths_to_insert: + # Clear `sys.path` + sys.path, remainder = sys.path[:1], sys.path[1:] + # Add directory as a site-packages directory and handle `.pth` files + site.addsitedir(dirpath) + # Restore rest of `sys.path` + sys.path.extend(remainder) def _register_utf8_codec():