Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] isort thinks config is a part of stdlib? #910

Closed
wisechengyi opened this issue Mar 22, 2019 · 3 comments
Closed

[bug] isort thinks config is a part of stdlib? #910

wisechengyi opened this issue Mar 22, 2019 · 3 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@wisechengyi
Copy link

Dummy.py

$ cat dummy.py 
import csv

from contextlib import contextmanager

import vertica_python
import yaml

import config
from db_config import DbConfig
import sql_generator as sql_gen
import util

Repro

$ isort --diff dummy.py 
--- /Users/me/workspace/source/dummy.py:before	2019-03-22 10:57:38.886071
+++ /Users/me/workspace/source/dummy.py:after	2019-03-22 11:01:22.796368
@@ -1,12 +1,9 @@
+import config
+from contextlib import contextmanager
 import csv
 
-from contextlib import contextmanager
-
-import vertica_python
-import yaml
-
-import config
 from db_config import DbConfig
 import sql_generator as sql_gen
 import util
-
+import vertica_python
+import yaml

.isort.cfg

$ cat .isort.cfg 
[settings]
line_length=100
indent=2
# 1/Vertical
multi_line_output=3
lines_after_imports=2
known_gen=gen
default_section=THIRDPARTY
sections=FUTURE,STDLIB,GEN,LOCALFOLDER,THIRDPARTY
force_sort_within_sections=1
force_alphabetical_sort_within_sections=1
# https://github.com/timothycrosley/isort/issues/723#issuecomment-425400842
combine_as_imports=1

contextlib and csv are correct, but config is not part of the stdlib:

$ python3 -c 'import config'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'config'
$ python2 -c 'import config'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named config
@timothycrosley timothycrosley added the repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue. label Mar 24, 2019
@timothycrosley
Copy link
Member

timothycrosley commented Mar 24, 2019

Hi @wisechengyi,

You are correct that config should not be identified as a standard lib import! I haven't been able to reproduce this issue on my testing machines using the exact config, and file given - is there any chance you can provide some additional information:

What version of isort is being used? isort -v
What Operating System is isort being used on?
What is the verbose output given? isort --check-only dummy.py --verbose

Thanks!

~Timothy

@wisechengyi
Copy link
Author

I can actually repro this without any additional config:
OS: osx 10.14.3

$ isort --check-only dummy.py --verbose

/#######################################################################\

     `sMMy`
     .yyyy-                                                      `
    ##soos##                                                    ./o.
          `     ``..-..`         ``...`.``         `   ```` ``-ssso```
     .s:-y-   .+osssssso/.     ./ossss+:so+:`    :+o-`/osso:+sssssssso/
     .s::y-   osss+.``.``     -ssss+-.`-ossso`   ssssso/::..::+ssss:::.
     .s::y-   /ssss+//:-.`   `ssss+     `ssss+   sssso`       :ssss`
     .s::y-   `-/+oossssso/  `ssss/      sssso   ssss/        :ssss`
     .y-/y-       ````:ssss`  ossso.    :ssss:   ssss/        :ssss.
     `/so:`    `-//::/osss+   `+ssss+-/ossso:    /sso-        `osssso/.
       \/      `-/oooo++/-      .:/++:/++/-`      ..           `://++/.


         isort your Python imports for you so you don't have to

                            VERSION 4.3.15

\########################################################################/

else-type place_module for csv returned STDLIB
from-type place_module for contextlib returned STDLIB
else-type place_module for vertica_python returned FIRSTPARTY
else-type place_module for yaml returned FIRSTPARTY
else-type place_module for config returned STDLIB
from-type place_module for db_config returned FIRSTPARTY
else-type place_module for sql_generator returned FIRSTPARTY
else-type place_module for util returned FIRSTPARTY
ERROR: /Users/yic/workspace/fiddle/isort-910/dummy.py Imports are incorrectly sorted.

isort is using this python2 at /usr/local/opt/python@2/bin/python2.7

$ which isort
/usr/local/bin/isort
$ cat /usr/local/bin/isort
#!/usr/local/opt/python@2/bin/python2.7
# -*- coding: utf-8 -*-
import re
import sys

from isort.main import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Sanity check on the interpreter:

$ /usr/local/opt/python@2/bin/python2.7 -c 'import config'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named config

@timothycrosley
Copy link
Member

This should be fixed for the 5.0.0 release in spirit via this ticket: #1147

@timothycrosley timothycrosley added duplicate This issue or pull request already exists enhancement New feature or request and removed repo_needed Can't currently reproduce, if reproduction steps are added we will resivit this issue. labels Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants