PyCQA / autoflake

Removes unused imports and unused variables as reported by pyflakes
https://pypi.org/project/autoflake/
MIT License
880 stars 80 forks source link

Add stdin and stdout options #12

Closed w0rp closed 2 years ago

w0rp commented 8 years ago

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.

alok commented 6 years ago

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

myint commented 6 years ago

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

alok commented 6 years ago

Implemented it. See the PR.

brupelo commented 6 years ago

@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 commented 6 years ago

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

myint commented 6 years ago

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

brupelo commented 6 years ago

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.

myint commented 6 years ago

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.

Yevgnen commented 5 years ago

Any news?

w0rp commented 5 years ago

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

fsouza commented 3 years ago

@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).

metopa commented 2 years ago

@fsouza Hi, why you PR was declined?

fsouza commented 2 years ago

@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.

metopa commented 2 years ago

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

fsouza commented 2 years ago

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.

myint commented 2 years ago

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

fsouza commented 2 years ago

@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? šŸ™ˆ

myint commented 2 years ago

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.

fsouza commented 2 years ago

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.

myint commented 2 years ago

I see. That sounds reasonable then. Welcome aboard!

fsouza commented 2 years ago

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.