Isort: Question about sorting behavior

Created on 12 May 2019  路  4Comments  路  Source: PyCQA/isort

Big fan of isort, but I ran into an issue today that I am unsure how to fix and don't know if it is intended functionality.

I have the following imports in my Python script:

from collections import namedtuple
from datetime import date
from pathlib import Path

import bs4
import requests

Whenever I run isort (through both VSCode and through the command line), it sorts into this:

from collections import namedtuple
from datetime import date
from pathlib import Path

import requests

import bs4

I thought this was odd because requests and BeautifulSoup are both third party libraries and isort does not seem to realize that (and thus sort them alphabetically). I tried passing in my virtual env, but the same thing still occurred. Any ideas? Am I doing something wrong? Thanks!

The reason I am asking is because I am trying to integrate this flake8 plugin into my project while still using isort.

enhancement repo_needed

Most helpful comment

It would be nice if --verbose output explained _why_ a certain import was assigned FIRSTPARTY/THIRDPARTY status. (If that's too verbose, then maybe --verbose=2 or --verbose --verbose could do it.)

All 4 comments

Hi @jadchaar,

Thanks for reporting this issue! And I'm glad you've found isort useful!

Can you provide some additional information, to assist me in determining the root cause of your issue:

  • What does a pip freeze look like within your virtual environment?
  • What OperatingSystem are you using?
  • What version of isort?
  • Are you utilizing conda or any other alternative Python package managers?

Thanks!

~Timothy

Hi @timothycrosley, thanks for the swift response.

  1. My pip freeze:
atomicwrites==1.3.0
attrs==19.1.0
beautifulsoup4==4.7.1
certifi==2019.3.9
chardet==3.0.4
coverage==4.5.3
entrypoints==0.3
flake8==3.7.7
idna==2.8
lxml==4.3.3
mccabe==0.6.1
more-itertools==7.0.0
pluggy==0.11.0
py==1.8.0
pycodestyle==2.5.0
pyflakes==2.1.1
pytest==4.4.1
pytest-cov==2.7.1
requests==2.21.0
six==1.12.0
soupsieve==1.9.1
urllib3==1.24.3
  1. OS: macOS 10.14.4
  2. iSort version 4.3.19
  3. Nope, old fashioned pip :).

My hypothesis is that isort is getting confused by bs4 being installed as beautifulsoup4 in the requirements.txt file.

I'm having a simillar problem: isort thinks 'requests' and 'mako' are THIRDPARTY, but that 'arrow' and 'request_cache' are FIRSTPARTY.

To reproduce:

python3 -m pip list shows that requests and mako are present in my system Python site packages, but arrow/requests_cache are not, which probably explains everything.

It would be nice if --verbose output explained _why_ a certain import was assigned FIRSTPARTY/THIRDPARTY status. (If that's too verbose, then maybe --verbose=2 or --verbose --verbose could do it.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

darkclouder picture darkclouder  路  3Comments

akaihola picture akaihola  路  3Comments

ionelmc picture ionelmc  路  3Comments

pawamoy picture pawamoy  路  3Comments

and-semakin picture and-semakin  路  3Comments