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

Run on a file or directory #40

Closed
hugovk opened this issue Jun 10, 2018 · 7 comments
Closed

Run on a file or directory #40

hugovk opened this issue Jun 10, 2018 · 7 comments

Comments

@hugovk
Copy link
Contributor

hugovk commented Jun 10, 2018

Thanks for this handy tool!

It would be nice to be able to run pyupgrade on a directory, and have it process all .py files in that directory and subdirectories.

For example:

pyupgrade .

This would be similar to other tools like Flake8 and Black.

In the meantime, this works:

pyupgrade `find . -name "*.py"`
@asottile
Copy link
Owner

I'd suggest using pre-commit to run pyupgrade (or, well, any linter) -- pre-commit is better at running your linters than your linters could be because it knows about what is checked in and can identify extensionless executables.

Your "workaround" would be my other suggestion -- no need to make a tool more complicated than it needs to be if there's another tool which does exactly what you need.

Adding directory recursion is a surprising amount of complexity, you then need to handle exclusion, inclusion, globs, walking, ordering, and a bunch of other problems I'm not interested in solving (again) (because pre-commit does this better!).

@cdeil
Copy link

cdeil commented Feb 6, 2019

@asottile - thank you for this wonderful tool!

I would also find this option useful to pass a folder. Yes, it's a bit of code to walk the directories, but black has a very good implementation that could be copied.

It's not obvious to me why one would use pre-commit to upgrade a given codebase. Upgrading is a one-time action, at least that's how I want to use it. So why make this a pre-commit hook? -- @asottile maybe you could clarify a bit at the start of the readme.

@hugovk
Copy link
Contributor Author

hugovk commented Feb 6, 2019

My workaround now also checks the found thing is a file (once *.py found a directory):

pyupgrade `find . -name "*.py" -type f`

@asottile
Copy link
Owner

asottile commented Feb 6, 2019

It's not just a one time tool, it will continue to enforce the rewrites into the future (and gain features over time). You don't want to have to manually point out "this code base is python 3+ don't do X" in code reviews ad infinitum.

Even if you don't want to have hooks indefinitely, pre-commit try-repo ... is good for one time runs

@bagerard
Copy link

Hi @asottile I understand that you are advocating for pre-commit but I believe it would be good to mention the trick with pyupgrade find . -name "*.py" -type f`` in a "Usage" section of the readme as well. What do you think?

@asottile
Copy link
Owner

asottile commented Mar 11, 2020

that has some correctness and portability issues, slightly better is find . -name '*.py' -exec pyupgrade {} + or find -name '*.py' -print0 | xargs pyupgrade or shopt -s globstar; pyupgrade **/*.py or ...

I don't really think it's the readme's place to teach how to use unix commands

@bagerard
Copy link

Alright that's your call :) Thanks for the quick feedback and for the library

Repository owner locked as resolved and limited conversation to collaborators Oct 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants