summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2015-02-05 16:44:44 -0500
committerTimothy Crosley <timothy.crosley@gmail.com>2015-02-05 16:44:44 -0500
commit94d9d851cd990c918c2a4b3da0d8c02ca95c2dba (patch)
tree0bf86bdea5d3b9a19b132276bf1e3edca46d547b
parentd8cea240730dae6f571e41ddad22e61217d40943 (diff)
downloadisort-94d9d851cd990c918c2a4b3da0d8c02ca95c2dba.tar.gz
Smarter virtualenv behaviour inspired by feedback from @spookylukey
-rw-r--r--isort/isort.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/isort/isort.py b/isort/isort.py
index 8b6ae933..12d1156d 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -209,7 +209,14 @@ class SortImports(object):
if module_name_to_check in self.config[config_key]:
return placement
- for prefix in PYTHONPATH:
+ paths = PYTHONPATH
+ virtual_env = os.environ.get('VIRTUAL_ENV', None)
+ if virtual_env:
+ paths = list(paths)
+ for version in ((2, 6), (2, 7), (3, 0), (3, 1), (3, 2), (3, 3), (3, 4)):
+ paths.append("{0}/lib/python{1}.{2}/site-packages".format(virtual_env, version[0], version[1]))
+
+ for prefix in paths:
module_path = "/".join((prefix, moduleName.replace(".", "/")))
package_path = "/".join((prefix, moduleName.split(".")[0]))
if (os.path.exists(module_path + ".py") or os.path.exists(module_path + ".so") or