From 51e2120886a9a652bc4e47becad232d9e7f85c00 Mon Sep 17 00:00:00 2001 From: James Laska Date: Wed, 26 Aug 2015 11:31:37 -0400 Subject: [PATCH] Properly handle namespace packages (oslo, dogpile) Using `site.addsitedir()` handles namespace packages, where the traditional `sys.path.insert` does not. Kudos to Chris Meyers for this discovery. --- awx/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/awx/__init__.py b/awx/__init__.py index 4b3a8072fa..2c4a64f58e 100644 --- a/awx/__init__.py +++ b/awx/__init__.py @@ -4,6 +4,7 @@ import os import sys import warnings +import site __version__ = '2.3.0' @@ -39,7 +40,10 @@ def prepare_env(): # Add local site-packages directory to path. local_site_packages = os.path.join(os.path.dirname(__file__), 'lib', 'site-packages') - sys.path.insert(0, local_site_packages) + site.addsitedir(local_site_packages) + # Work around https://bugs.python.org/issue7744 + # by moving local_site_packages to the front of sys.path + sys.path.insert(0, sys.path.pop()) # Hide DeprecationWarnings when running in production. Need to first load # settings to apply our filter after Django's own warnings filter. from django.conf import settings