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

isort needs to have the filename passed in as an arg #3806

Closed
jeffwillette opened this issue Jul 8, 2021 · 3 comments
Closed

isort needs to have the filename passed in as an arg #3806

jeffwillette opened this issue Jul 8, 2021 · 3 comments

Comments

@jeffwillette
Copy link
Contributor

jeffwillette commented Jul 8, 2021

Using the isort fixer is convenient in python except for when editing __init__.py files which often need their imports in a specifici order which gets undone when I save the file and the fixers run.

  • ALE used to never give a problem (because I had added custom CLI args let g:ale_python_isort_options = '--skip __init__.py --filter-files)
  • It seems like something changed along the way and now the file cannot be ignored via the above CLI args because the command which gets passed to isort reads from stdin isort --skip __init__.py --filter-files - < /tmp/nvim0aAePZ/10745/__init__.py
  • isort issue reference skip files no longer ignores from stdin PyCQA/isort#1771 (comment)
  • The solution is to make the command passed to isort have the filename passed in manually, the correct command should be...
isort --skip __init__.py --filter-files --filename /tmp/nvim0aAePZ/10745/__init__.py - < /tmp/nvim0aAePZ/10745/__init__.py

so the command called by ALE directly should have the --filename option added so that users custom args given to isort can work off the filename since the stdin stream doesn't give any file information. I don't have time to do this now, but I will leave this issue here and get to it when I have some free time if no one else takes it up.

@jeffwillette
Copy link
Contributor Author

jeffwillette commented Jul 8, 2021

Actually, I just had a look at the fixer itself and I am not sure how to go about fixing this since the stdin stream filename isn't anywhere I can see. Does anyone have an idea of how to accomplish this?

return {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(l:executable) . l:exec_args
\ . (!empty(l:options) ? ' ' . l:options : '') . ' -',
\}

@hsanson
Copy link
Contributor

hsanson commented Jul 9, 2021

@jeffwillette you can use %s placeholder and it will be replaced with the absolute filename by ALE. Something like below should do what you need:

    return {
    \   'cwd': '%s:h',
    \   'command': ale#Escape(l:executable) . l:exec_args
    \   . ale#Pad('--filename %s')
    \   . (!empty(l:options) ? ' ' . l:options : '') . ' -',
    \}

Feel free to make a PR if the change fixes this issue and does not break anything else.

@hsanson
Copy link
Contributor

hsanson commented Jul 14, 2021

Should be fixed with #3815

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants