Skip to content

isort behavior different for venv vs conda env #1058

@calebho

Description

@calebho

This is similar to #789 but not quite the same. To reproduce, let's setup three different Python 3.6 environments

  1. Conda environment test_numpy_requests with isort, requests, numpy
  2. Conda environment test_numpy with isort, numpy
  3. Venv created using the Python in 1 with only isort (e.g. created with 1 activated using python -m venv /tmp/venv_from_conda)

Now let's use the following file (henceforth called isort_bug.py):

import numpy
import requests

As expected, isort -c -rc isort_bug.py exits successfully:

(test_numpy_requests) calebh@devfair020:~/scratch$ cat isort_bug.py
import numpy
import requests
(test_numpy_requests) calebh@devfair020:~/scratch$ isort -c -rc isort_bug.py
(test_numpy_requests) calebh@devfair020:~/scratch$

Also as expected (based on #789), isort -c -rc isort_bug.py does not exit successfully because requests isn't installed:

(test_numpy) calebh@devfair020:~/scratch$ isort -c -rc isort_bug.py
ERROR: /private/home/calebh/scratch/isort_bug.py Imports are incorrectly sorted.
(test_numpy) calebh@devfair020:~/scratch$

The interesting bit happens with the last env

(test_numpy_requests) calebh@devfair020:~/scratch$ /tmp/venv_from_conda/bin/python -m isort -c -rc isort_bug.py
(test_numpy_requests) calebh@devfair020:~/scratch$ /tmp/venv_from_conda/bin/python -m pip list
Package    Version
---------- -------
isort      4.3.21
pip        18.1
setuptools 40.6.2
You are using pip version 18.1, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(test_numpy_requests) calebh@devfair020:~/scratch$

Neither numpy nor requests are installed!

But what happens if you invoke it from base? (If you want to be really sure, try it in a fresh conda env with absolutely nothing installed)

(base) calebh@devfair020:~/scratch$ /tmp/venv_from_conda/bin/python -m isort -c -rc isort_bug.py
ERROR: /private/home/calebh/scratch/isort_bug.py Imports are incorrectly sorted.
(base) calebh@devfair020:~/scratch$

Why does this matter? Well nox creates virtualenvs for each session, so when I run things locally everything is fine because I have everything installed. But when I run in CI, isort complains.

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existsenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions