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

Disable import sorting when using Python 2.7 #14101

Closed
Spitfire1900 opened this issue Sep 25, 2020 · 8 comments
Closed

Disable import sorting when using Python 2.7 #14101

Spitfire1900 opened this issue Sep 25, 2020 · 8 comments
Labels
area-formatting feature-request Request for new features or functionality needs spike Label for issues that need investigation before they can be worked on.

Comments

@Spitfire1900
Copy link

Error 2020-09-25 10:55:48:     runpy.run_path(module, run_name="__main__")
  File "C:\Python27\lib\runpy.py", line 252, in run_path
    return _run_module_code(code, init_globals, run_name, path_name)
  File "C:\Python27\lib\runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "c:\Users\<USER>\.vscode\extensions\ms-python.python-2020.9.111407\pythonFiles\sortImports.py", line 12, in <module>
    import isort.main
  File "c:\Users\<USER>\.vscode\extensions\ms-python.python-2020.9.111407\pythonFiles\lib\python\isort\__init__.py", line 2, in <module>
    from . import settings
  File "c:\Users\<USER>\.vscode\extensions\ms-python.python-2020.9.111407\pythonFiles\lib\python\isort\settings.py", line 31
    FILE_SKIP_COMMENTS: Tuple[str, ...] = (
                      ^
SyntaxError: invalid syntax

image

@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Sep 25, 2020
@brettcannon brettcannon changed the title isort in extensions version 2020.9.111407 is incompatible with Python 2.7 isort 5 in extension version 2020.9.111407 is incompatible with Python 2.7 Sep 28, 2020
@brettcannon brettcannon added area-formatting needs spike Label for issues that need investigation before they can be worked on. feature-request Request for new features or functionality important Issue identified as high-priority and removed triage-needed Needs assignment to the proper sub-team labels Sep 28, 2020
@brettcannon
Copy link
Member

I've classified this as an enhancement as due to isort 5 changes and bugfixes that mean we can't stay on isort 4 with its Python 2.7 support. But we can at least help prevent you from accidentally running the sort action.

@brettcannon brettcannon changed the title isort 5 in extension version 2020.9.111407 is incompatible with Python 2.7 Disable import sorting when using Python 2.7 Sep 28, 2020
@Spitfire1900
Copy link
Author

Spitfire1900 commented Sep 29, 2020

We have the following entry in settings.json in a number of our projects,

"editor.codeActionsOnSave": {
    "source.organizeImports": true
},

is there a way to trigger native isort py -2 -m isort ${relativeFile} instead of the integrated source action on save?

@brettcannon
Copy link
Member

We do let you specify the path to isort in your settings, so if you faked it to point to something that worked for your situation then that would let you use the old version (you can a straight use of isort 4, but it's been triggering warnings for setuptools users). Otherwise you could add a task to your project to run isort the way you want.

/cc @karrtikr in case I'm missing an idea.

@Spitfire1900
Copy link
Author

I think you're talking about #12949? Luckily for us the projects that are using Python 2.7 aren't using setuptools.

@brettcannon
Copy link
Member

@Spitfire1900 yep, that's the issue

@luabud luabud removed the important Issue identified as high-priority label Oct 7, 2020
@CHBrianLiu
Copy link

Hi, I encountered this issue as well while using Python 2.7.17. For me, the workaround is to set python.sortImports.path explicitly in settings.json.

$ # Check isort version is 4.
$ isort --version

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

                            VERSION 4.3.21

$ # Get isort path.
$ which isort
/home/brian_ch_liu/.local/bin/isort

In project directory, edit the VS code configuration file (.vscode/settings.json).

{
    "python.sortImports.path": "/home/brian_ch_liu/.local/bin/isort"
}

@lamborghini1993
Copy link

image

python2.7 use isort. so How should i solve?

@karrtikr
Copy link

karrtikr commented Dec 20, 2022

We no longer support Python 2.7 as its reached its EOL, hence closing this.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-formatting feature-request Request for new features or functionality needs spike Label for issues that need investigation before they can be worked on.
Projects
None yet
Development

No branches or pull requests

6 participants