summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Edmund Crosley <timothy.crosley@gmail.com>2019-03-06 20:44:37 -0800
committerGitHub <noreply@github.com>2019-03-06 20:44:37 -0800
commitd6f200ba77c18dfe9eb65c6de1175acf360a27b0 (patch)
treef3699b5586ea1fa2457388d0f595ad551dfe5bda
parentbe50253e0beaadc4412ddb63091c1574a8507680 (diff)
parent35765c51ecb2a9e38bf2aa512caf42fe42170dd5 (diff)
downloadisort-d6f200ba77c18dfe9eb65c6de1175acf360a27b0.tar.gz
Merge pull request #886 from timothycrosley/feature/anaconda-support
Feature/anaconda support
-rw-r--r--CHANGELOG.md4
-rw-r--r--isort/finders.py28
-rw-r--r--isort/main.py2
3 files changed, 27 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3682f6cc..f7ebed58 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
Changelog
=========
+### 4.3.13 - March 6, 2019 - hot fix release
+- Fixed the inability to accurately determine import section when a mix of conda and virtual environments are used.
+- Fixed some output being printed even when --quiet mode is enabled.
+
### 4.3.12 - March 6, 2019 - hot fix release
- Fix error caused when virtual environment not detected
diff --git a/isort/finders.py b/isort/finders.py
index fc9e8cf7..c0b1341a 100644
--- a/isort/finders.py
+++ b/isort/finders.py
@@ -130,13 +130,8 @@ class PathFinder(BaseFinder):
def __init__(self, config, sections):
super(PathFinder, self).__init__(config, sections)
- # Use a copy of sys.path to avoid any unintended modifications
- # to it - e.g. `+=` used below will change paths in place and
- # if not copied, consequently sys.path, which will grow unbounded
- # with duplicates on every call to this method.
- self.paths = list(sys.path)
# restore the original import path (i.e. not the path to bin/isort)
- self.paths[0] = os.getcwd()
+ self.paths = [os.getcwd()]
# virtual env
self.virtual_env = self.config.get('virtual_env') or os.environ.get('VIRTUAL_ENV')
@@ -155,6 +150,17 @@ class PathFinder(BaseFinder):
if os.path.isdir(path):
self.paths.append(path)
+ # conda
+ self.conda_env = self.config.get('conda_env') or os.environ.get('CONDA_PREFIX')
+ if self.conda_env:
+ self.conda_env = os.path.realpath(self.conda_env)
+ for path in glob('{0}/lib/python*/site-packages'.format(self.conda_env)):
+ if path not in self.paths:
+ self.paths.append(path)
+ for path in glob('{0}/lib/python*/*/site-packages'.format(self.conda_env)):
+ if path not in self.paths:
+ self.paths.append(path)
+
# handle case-insensitive paths on windows
self.stdlib_lib_prefix = os.path.normcase(sysconfig.get_paths()['stdlib'])
if self.stdlib_lib_prefix not in self.paths:
@@ -163,12 +169,18 @@ class PathFinder(BaseFinder):
# handle compiled libraries
self.ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") or ".so"
+ # add system paths
+ for path in sys.path[1:]:
+ if path not in self.paths:
+ self.paths.append(path)
+
def find(self, module_name):
for prefix in self.paths:
package_path = "/".join((prefix, module_name.split(".")[0]))
is_module = (exists_case_sensitive(package_path + ".py") or
exists_case_sensitive(package_path + ".so") or
- exists_case_sensitive(package_path + self.ext_suffix))
+ exists_case_sensitive(package_path + self.ext_suffix) or
+ exists_case_sensitive(package_path + "/__init__.py"))
is_package = exists_case_sensitive(package_path) and os.path.isdir(package_path)
if is_module or is_package:
if 'site-packages' in prefix:
@@ -177,6 +189,8 @@ class PathFinder(BaseFinder):
return self.sections.THIRDPARTY
if self.virtual_env and self.virtual_env_src in prefix:
return self.sections.THIRDPARTY
+ if self.conda_env and self.conda_env in prefix:
+ return self.sections.THIRDPARTY
if os.path.normcase(prefix).startswith(self.stdlib_lib_prefix):
return self.sections.STDLIB
return self.config['default_section']
diff --git a/isort/main.py b/isort/main.py
index bf6d93c9..29049ac6 100644
--- a/isort/main.py
+++ b/isort/main.py
@@ -278,6 +278,8 @@ def parse_args(argv=None):
help='Shows verbose output, such as when files are skipped or when a check is successful.')
parser.add_argument('--virtual-env', dest='virtual_env',
help='Virtual environment to use for determining whether a package is third-party')
+ parser.add_argument('--conda-env', dest='conda_env',
+ help='Conda environment to use for determining whether a package is third-party')
parser.add_argument('-vn', '--version-number', action='version', version=__version__,
help='Returns just the current version number without the logo')
parser.add_argument('-w', '--line-width', help='The max length of an import line (used for wrapping long imports).',