autoflake icon indicating copy to clipboard operation
autoflake copied to clipboard

Add stdin and stdout options

Open w0rp opened this issue 9 years ago • 21 comments

Currently autoflake reads from a file by taking a filename, and outputs a diff with a patch to make. This works well for some command line usage, but doesn't integrate so well with replacing a buffer in Vim. This could be improved by offering an option to read the file from stdin, and an option for outputting the entire file contents, with the patch applied, to stdout. stdin support could either by via flag, or by reading a special filename -. Supposing there was a flag for stdout support, then autoflake could automatically remove unused imports in Vim with both flags like so.

silent 0,$!autoflake --stdin --output-file

That command would take the contents of the current buffer, pass it to autoflake via stdin, get the new file after applying the patch back out again, and replace the current buffer with that text.

At the moment, I shall have to save my current buffer to a file, run autoflake on that temporary file and save the diff to another temporary file, and then use the :diffpatch command to apply the patch to the current buffer, in order to integrate autoflake with Vim.

w0rp avatar Sep 09 '16 09:09 w0rp

I'd also be very happy to see this implemented.

alok avatar Mar 13 '18 09:03 alok

I think this is a reasonable request. I've done this in various other tools. For example, see:

https://github.com/myint/docformatter/blob/7a23f89a8bcfb117db2f388c6706d28e9bb30e9c/docformatter.py#L593-L626

myint avatar Mar 13 '18 13:03 myint

Implemented it. See the PR.

alok avatar Apr 27 '18 08:04 alok

@myint Steven, hi. What happened finally to this feature? I'd be very happy to use it on a SublimeText plugin but i don't see it living on the latest autoflake 1.2 after doing pip install --upgrade autoflake.

Autoflake is an awesome tool and reading from stdin is supported by many python linters out there, so it'd be great to have it as well here.

For example, autopep8... test it on windows is as easy as just doing echo a=1+2 | autopep8 --ignore=IGNORE -.

Please let me know. Tyvm

brupelo avatar Jul 06 '18 02:07 brupelo

Is this repo still alive? Here's a little example how to achieve the task:

  • Make sure this option doesn't conflict with existing one: https://github.com/hhatto/autopep8/blob/master/autopep8.py#L3446-L3457
  • Read from standard input: https://github.com/hhatto/autopep8/blob/master/autopep8.py#L3955-L3963

brupelo avatar Jul 26 '18 21:07 brupelo

@brupelo Please see https://github.com/myint/autoflake/pull/37#discussion_r184868642.

myint avatar Aug 05 '18 18:08 myint

Almost all python linters out there support this and if - conflicts with another option the right call is just warning about it (see for instance how isort does it as an example), not having this standard common operation on autoflake doesn't make sense. A linter tool should be a tool to be used not only on the command line but also should allow to interact with the IDE itself.

brupelo avatar Aug 05 '18 21:08 brupelo

I'm not arguing against the - feature. 😄

Merely doing it in the right way, which I specified in the pull request. I would do it myself if I wasn't doing 12 hour days at work.

myint avatar Aug 08 '18 01:08 myint

Any news?

Yevgnen avatar Jan 13 '19 04:01 Yevgnen

If there was news, you'd see a comment here. ;)

w0rp avatar Jan 13 '19 08:01 w0rp

@myint hi there! If I were to take on this change, would you accept a patch? I can build on #37 or start from scratch, whatever works better (haven't investigated what will be simpler yet).

fsouza avatar Aug 31 '21 15:08 fsouza

@fsouza Hi, why you PR was declined?

metopa avatar Apr 16 '22 15:04 metopa

@fsouza Hi, why you PR was declined?

Oh, this was from before the repo was moved to pycqa and I thought it was kind of abandoned. It wasn't declined, I just closed it. Happy to reopen it if the repo is active again.

fsouza avatar Apr 17 '22 12:04 fsouza

Looks like it is abandoned indeed, which is unfortunate :(

metopa avatar Apr 17 '22 18:04 metopa

With the move to PyCQA maybe it'll be picked up again? I did fork it here and have some plans for it, but if pycqa will move it forward I'm happy to abandon autoflake8 and focus on the work here.

fsouza avatar Apr 17 '22 22:04 fsouza

@fsouza Would you be interested in becoming a maintainer of this repository?

myint avatar Jul 25 '22 03:07 myint

@fsouza Would you be interested in becoming a maintainer of this repository?

Hey @myint, thank you very much for creating autoflake and apologies for the delayed response, I was on paternity leave and very slow to respond. Do you have details on what maintaining it would entail? (something along the lines of reviewing PRs, triaging issues, creating new releases? Anything else?) Are there other maintainers? Like, would there be someone to review my PRs too? 🙈

fsouza avatar Aug 14 '22 23:08 fsouza

Maintaining would entail reviewing, triaging, and creating releases as you suggest. There are currently no other maintainers, but ideally there would be.

I just took a look at https://github.com/fsouza/autoflake8, and one slightly worrying thing I notice is there is over ten dependencies in the fork whereas autoflake in this repository only depends on pyflakes. I try to keep dependencies minimal in autoflake.

myint avatar Aug 15 '22 02:08 myint

Users of autoflake8 still only have 1 dependency (pyflakes). The other dependencies are used only to develop autoflake8. It's basically pytest and aiofiles, and both are used for running tests/in tests.

That being said, I don't think we need to bring autoflake8 as is. We can keep the current approach and port the improvements without necessarily pushing it to poetry, changing how the code is organized or how tests are executed.

fsouza avatar Aug 15 '22 03:08 fsouza

I see. That sounds reasonable then. Welcome aboard!

myint avatar Aug 15 '22 16:08 myint

Sounds good! I'll reopen my PR adding stdin and stdout, and if CI is happy I'll merge it! I'll also move CI to GH Actions.

fsouza avatar Aug 16 '22 02:08 fsouza