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

Allow running codemods without configuring in YAML #879

Merged
merged 2 commits into from
Mar 27, 2023

Conversation

akx
Copy link
Contributor

@akx akx commented Feb 28, 2023

Summary

This enables codemodding things by just plonking a CodemodCommand class into any old importable module and running python -m libcst.tool codemod -x some_module.SomeClass ...

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 28, 2023
@povilasb
Copy link

👍

@zsol
Copy link
Member

zsol commented Mar 16, 2023

I'm in favor of this functionality, but

  1. let's make it explicit behind a command line flag instead of an implicit fallthrough behavior:
python -m libcst.tool codemod --external-command some_module.SomeClass

(feel free to come up with a better name 😄 )
2. let's add tests for it

@akx
Copy link
Contributor Author

akx commented Mar 23, 2023

@zsol How about a flag to allow the fallback behavior?

python -m libcst.tool codemod -x some_module.SomeClass

(-x for eXternal)

@zsol
Copy link
Member

zsol commented Mar 23, 2023

What's the benefit of that over the explicit behavior I mentioned above?

@akx
Copy link
Contributor Author

akx commented Mar 23, 2023

@zsol Yeah, good point – I was about to edit my comment to a "never mind" because I realized that was silly after all, but you got there first 😁

Anyway, um... are there tests for the CLI at all? test_tool.py seems to have unrelated things in it... (EDIT: no, there don't seem to be thoroguh tests for the code paths in the CLI that do things.)

@akx akx force-pushed the adhoc-codemod branch 2 times, most recently from 51e1488 to 23d78e0 Compare March 23, 2023 13:46
Copy link
Member

@zsol zsol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

)
return 1
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this else block is not needed, we can just dedent the entire block since we always return in the if branch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um... no, we don't return from the if args.external branch?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're absolutely right 😂

akx added 2 commits March 24, 2023 15:50
This enables codemodding things by just plonking a CodemodCommand class
into any old importable module and running
`python -m libcst.tool codemod -x some_module.SomeClass ...`
@zsol
Copy link
Member

zsol commented Mar 27, 2023

Thanks!

@zsol zsol merged commit 4f810db into Instagram:main Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants