dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.49k stars 1.43k forks source link

Python isort fixer does not respect pyproject.toml #2885

Open jaapz opened 4 years ago

jaapz commented 4 years ago

Information

VIM version

:version
NVIM v0.5.0-95-g2e14dffbb
Build type: RelWithDebInfo

Operating System: arch linux

What went wrong

When enabling the isort fixer, it does not respect settings defined in pyproject.toml in the project directory. I think this is the same problem the black fixer had which was fixed like this: https://github.com/dense-analysis/ale/pull/2262

Reproducing the bug

  1. Put some isort config in pyproject.toml, for example:

    [tool.isort]
    skip = ["*"]
  2. Watch isort not care about your config

:ALEInfo

 Current Filetype: python
Available Linters: ['bandit', 'flake8', 'mypy', 'prospector', 'pycodestyle', 'pydocstyle', 'pyflakes', 'pylama', 'pylint', 'pyls', 'pyre', 'vulture']
  Enabled Linters: ['flake8', 'mypy']
 Suggested Fixers: 
  'add_blank_lines_for_python_control_statements' - Add blank lines before control statements.
  'autopep8' - Fix PEP8 issues with autopep8.
  'black' - Fix PEP8 issues with black.
  'isort' - Sort Python imports with isort.
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'reorder-python-imports' - Sort Python imports with reorder-python-imports.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
  'yapf' - Fix Python files with yapf.
 Linter Variables:

let g:ale_python_auto_pipenv = 0
let g:ale_python_flake8_auto_pipenv = 0
let g:ale_python_flake8_change_directory = 1
let g:ale_python_flake8_executable = 'flake8'
let g:ale_python_flake8_options = ''
let g:ale_python_flake8_use_global = 0
let g:ale_python_mypy_auto_pipenv = 0
let g:ale_python_mypy_executable = 'mypy'
let g:ale_python_mypy_ignore_invalid_syntax = 0
let g:ale_python_mypy_options = ''
let g:ale_python_mypy_use_global = 0
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {'go': ['goimports'], 'typescript': ['prettier'], 'javascript': ['prettier'], 'python': ['isort', 'black']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'go': ['gometalinter', 'golint', 'govet'], 'typescript': ['eslint', 'tsserver'], 'javascript': ['eslint'], 'python': ['flake8', 'mypy']}
let g:ale_linters_explicit = 1
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 1
let g:ale_sign_error = '⤫'
let g:ale_sign_info = '⚠️'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '⤫'
let g:ale_sign_style_warning = '⚠️'
let g:ale_sign_warning = '⚠️'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - success) /home/jaapz/programming/core/.env/bin/flake8
(finished - exit code 0) ['/bin/zsh', '-c', '''/home/jaapz/programming/core/.env/bin/flake8'' --version']

<<<OUTPUT STARTS>>>
3.7.8 (flake8-todo: 0.7, mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.4 on Linux
<<<OUTPUT ENDS>>>

(executable check - success) /home/jaapz/programming/core/.env/bin/mypy
(finished - exit code 0) ['/bin/zsh', '-c', 'cd ''/home/jaapz/programming/core'' && ''/home/jaapz/programming/core/.env/bin/mypy'' --show-column-numbers  --shadow-file ''/home/jaapz/programming/core/mijnbaopt/button.py'' ''/tmp/nvimEVdIb2/4/button.py'' ''/home/jaapz/programming/core/mijnbaopt/button.py''']

<<<NO OUTPUT RETURNED>>>

(finished - exit code 0) ['/bin/zsh', '-c', 'cd ''/home/jaapz/programming/core/mijnbaopt'' && ''/home/jaapz/programming/core/.env/bin/flake8'' --format=default --stdin-display-name ''/home/jaapz/programming/core/mijnbaopt/button.py'' - < ''/tmp/nvimEVdIb2/5/button.py''']

<<<NO OUTPUT RETURNED>>>
mfogel commented 4 years ago

It appears what's going on is that isort doesn't do the same 'search for settings' when consuming input via stdin vs. when it is passed path to a file. It doesn't use the current working directory to search for settings files when consuming from stdiin.

However, as a workaround, setting

let g:ale_python_isort_options = '--settings-path .'

will get isort to find the right settings file (including a pyproject.toml, that's what I'm using).

mfogel commented 3 years ago

This appears to be fixed now. I've tested this using isort 5.2.2 on vim8 with ale 2.6.0 and on neovim using the latest on master for ale, and isort now finds my settings in pyproject.toml as expected. So no more need for the workaround I posted above.

@w0rp I think this is safe to close

nospam2998 commented 1 week ago

Could you @jaapz please confirm what @mfogel wrote above, and close this stale issue if it is resolved?